33 lines
893 B
C++
33 lines
893 B
C++
|
//
|
||
|
// 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;
|
||
|
|
||
|
//sqlite3_prepare_v2(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);
|
||
|
|
||
|
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;
|
||
|
}
|