2019-07-12 19:05:56 +00:00
|
|
|
//
|
|
|
|
// Created by tobias on 08/07/19.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include "device_dbo.h"
|
|
|
|
#include "globals.h"
|
|
|
|
|
|
|
|
bool device_dbo::save()
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
sqlite3_stmt *stmt;
|
|
|
|
|
2019-07-14 22:39:37 +00:00
|
|
|
sqlite3_prepare_v2(globals::db, "INSERT INTO devices(id, name, ip, active) values (?1, ?2, ?3, ?4);", -1, &stmt, nullptr);
|
|
|
|
//sqlite3_prepare_v2(globals::db, "UPDATE devices set name = ?2, ip = ?3, active = ?4 WHERE id = ?1;", -1, &stmt, nullptr);
|
2019-07-12 19:05:56 +00:00
|
|
|
|
|
|
|
sqlite3_bind_text(stmt, 1, this->id, -1, SQLITE_STATIC);
|
|
|
|
sqlite3_bind_text(stmt, 2, this->name, -1, SQLITE_STATIC);
|
|
|
|
sqlite3_bind_text(stmt, 3, this->ip, -1, SQLITE_STATIC);
|
|
|
|
sqlite3_bind_int(stmt, 4, this->active);
|
|
|
|
//sqlite3_bind_int(stmt, 2, 21);
|
|
|
|
|
|
|
|
rc = sqlite3_step(stmt);
|
|
|
|
if (rc != SQLITE_DONE) {
|
|
|
|
printf("ERROR inserting data: %s\n", sqlite3_errmsg(globals::db));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sqlite3_finalize(stmt);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|