diff options
Diffstat (limited to 'src/sqliteinterface.cpp')
-rw-r--r-- | src/sqliteinterface.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/sqliteinterface.cpp b/src/sqliteinterface.cpp index 39bdb3b..c34576b 100644 --- a/src/sqliteinterface.cpp +++ b/src/sqliteinterface.cpp @@ -29,7 +29,6 @@ void SqliteInterface::openDB() } fs::path filename = appdata / "ytcpp.db"; - cout << filename.c_str() << endl; int rc = sqlite3_open(filename.c_str(), &db); if (rc) @@ -60,14 +59,21 @@ static int callback(void *NotUsed, int argc, char **argv, char **azColName) { void SqliteInterface::createTables() { char *errmsg = 0; - int rc = sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS INSTANCES (url TEXT PRIMARY KEY, health, location);", callback, 0, &errmsg); + int rc = sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS INSTANCES (url TEXT PRIMARY KEY, health FLOAT, location TEXT);", callback, 0, &errmsg); if( rc != SQLITE_OK ){ fprintf(stderr, "SQL error: %s\n", errmsg); sqlite3_free(errmsg); - } else { - fprintf(stdout, "Table created successfully\n"); } +} + +void SqliteInterface::saveInstance(const string& uri, float health, const string& location) { + char *errmsg = 0; + int rc = sqlite3_exec(db, sqlite3_mprintf("INSERT INTO INSTANCES (%Q, %F.2, %Q)", uri, health, location), callback, 0, &errmsg); + if( rc != SQLITE_OK ){ + fprintf(stderr, "SQL error: %s\n", errmsg); + sqlite3_free(errmsg); + } } void SqliteInterface::saveVideo(const Video::video& vid) { |