diff --git a/Db-Script/database.c b/Db-Script/database.c index 97cd524..d27e2b7 100644 --- a/Db-Script/database.c +++ b/Db-Script/database.c @@ -1,49 +1,38 @@ #include "./database.h" -int openDb(sqlite3 *db) -{ - - int rc = sqlite3_open("robotgowest.db", &db); - - if (rc != SQLITE_OK) - { - - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); - sqlite3_close(db); - - return 1; - } - return 0; -} - int initializeTrailsAndCaptorMetadataTables() { sqlite3 *db; - char *err_msg = 0; + char *err_msg; int rc; - if (!openDb(db)) + sqlite3_stmt *stmt; + + rc = sqlite3_open("robotgowest.db", &db); + printf("%i\n", rc); + + // char *sql = "CREATE TABLE Test(Id INT)"; + + char *sql = "DROP TABLE IF EXISTS Trials;" + "DROP TABLE IF EXISTS CaptorMetadata;" + "CREATE TABLE Trials(Id INTEGER PRIMARY KEY AUTOINCREMENT, Position TEXT, Start INT, Frequency NUMBER, Duration INT);" + "CREATE TABLE CaptorMetadata(Id INTEGER PRIMARY KEY AUTOINCREMENT, CaptorNumber INT, TrialId INT, FOREIGN KEY (TrialId) REFERENCES Trials(Id));"; + + rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL); + printf("%i\n", rc); + if (rc != SQLITE_OK) { - char *sql = "DROP TABLE IF EXISTS Trials;" - "DROP TABLE IF EXISTS CaptorMetadata;" - "CREATE TABLE Trials(Id INTEGER PRIMARY KEY AUTOINCREMENT, Position TEXT, Start INT, Frequency NUMBER, Duration INT);" - "CREATE TABLE CaptorMetadata(Id INTEGER PRIMARY KEY AUTOINCREMENT, CaptorNumber INT, TrialId INT, FOREIGN KEY (TrialId) REFERENCES Trials(Id));"; - - rc = sqlite3_prepare_v2(db, sql, 0, 0, &err_msg); - - if (rc != SQLITE_OK) - { - - fprintf(stderr, "SQL error: %s\n", err_msg); - - sqlite3_free(err_msg); - sqlite3_close(db); - - return 1; - } - sqlite3_close(db); - - return 0; + return 1; } + rc = sqlite3_step(stmt); + printf("%i\n", rc); + if (rc != SQLITE_DONE) + { + return 1; + } + rc = sqlite3_finalize(stmt); + + printf("%i\n", rc); + sqlite3_close(db); } int createCaptorDataTable(int trialId, int captorNumber) @@ -60,12 +49,11 @@ int createCaptorDataTable(int trialId, int captorNumber) strcat(tableName, convertIntegerToChar(captorNumber)); strcat(tableName, "Data"); - if (!openDb(db)) + if (sqlite3_open("robotgowest.db", &db) == SQLITE_OK) { char sql[101] = "CREATE TABLE "; strcat(sql, tableName); strcat(sql, " (Id INTEGER PRIMARY KEY AUTOINCREMENT, Lux NUMBER, Mean NUMBER , Power NUMBER);"); - rc = sqlite3_exec(db, sql, 0, 0, &err_msg); if (rc != SQLITE_OK) { @@ -119,6 +107,9 @@ char *convertIntegerToChar(int N) int main(void) { + sqlite3_initialize(); + initializeTrailsAndCaptorMetadataTables(); // createCaptorDataTable(1, 1); + sqlite3_shutdown(); } \ No newline at end of file diff --git a/Db-Script/db b/Db-Script/db index 5e51ebf..e4aa2f9 100755 Binary files a/Db-Script/db and b/Db-Script/db differ diff --git a/Db-Script/robotgowest.db b/Db-Script/robotgowest.db index e69de29..01bd220 100644 Binary files a/Db-Script/robotgowest.db and b/Db-Script/robotgowest.db differ diff --git a/influxdb_token.txt b/influxdb_token.txt deleted file mode 100644 index 999500b..0000000 --- a/influxdb_token.txt +++ /dev/null @@ -1 +0,0 @@ -mlxKvuIC8vZ9qQMAVxa4jD9vCLekIMFXI3tdHmx-Ho88ER1IAQfq5J1m3Rfpz_41ML6ZRSh0jZBb-aQAzoZExA== diff --git a/robotgowestdb.db b/robotgowestdb.db deleted file mode 100644 index 5e0cf70..0000000 Binary files a/robotgowestdb.db and /dev/null differ