From 4672159f50a584cef58f688efb5e09a02dde86c4 Mon Sep 17 00:00:00 2001 From: Quentin Perret Date: Fri, 2 Jun 2023 00:03:16 +0200 Subject: [PATCH] create script ok --- Db-Script/database.c | 79 ++++++++++++++++++++------------------- Db-Script/db | Bin 17376 -> 17240 bytes Db-Script/robotgowest.db | Bin 16384 -> 24576 bytes 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/Db-Script/database.c b/Db-Script/database.c index d27e2b7..25f1854 100644 --- a/Db-Script/database.c +++ b/Db-Script/database.c @@ -1,6 +1,6 @@ #include "./database.h" -int initializeTrailsAndCaptorMetadataTables() +int initializeTrailsTable() { sqlite3 *db; char *err_msg; @@ -8,38 +8,44 @@ int initializeTrailsAndCaptorMetadataTables() 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));"; + char *sql = + "CREATE TABLE Trials(Id INTEGER PRIMARY KEY AUTOINCREMENT, Position TEXT, Start INT, Frequency NUMBER, Duration INT);"; rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL); - printf("%i\n", rc); - if (rc != SQLITE_OK) - { - return 1; - } rc = sqlite3_step(stmt); - printf("%i\n", rc); - if (rc != SQLITE_DONE) - { - return 1; - } rc = sqlite3_finalize(stmt); + sqlite3_close(db); +} - printf("%i\n", rc); +int initializeCaptorMetadataTable() +{ + sqlite3 *db; + char *err_msg; + int rc; + sqlite3_stmt *stmt; + + rc = sqlite3_open("robotgowest.db", &db); + + // char *sql = "CREATE TABLE Test(Id INT)"; + + char *sql = + "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); + rc = sqlite3_step(stmt); + rc = sqlite3_finalize(stmt); sqlite3_close(db); } int createCaptorDataTable(int trialId, int captorNumber) { sqlite3 *db; - char *err_msg = 0; + char *err_msg; int rc; + sqlite3_stmt *stmt; // Create Table Name char tableName[8]; @@ -49,26 +55,22 @@ int createCaptorDataTable(int trialId, int captorNumber) strcat(tableName, convertIntegerToChar(captorNumber)); strcat(tableName, "Data"); - if (sqlite3_open("robotgowest.db", &db) == SQLITE_OK) + rc = sqlite3_open("robotgowest.db", &db); + if (rc != SQLITE_OK) { - char sql[101] = "CREATE TABLE "; - strcat(sql, tableName); - strcat(sql, " (Id INTEGER PRIMARY KEY AUTOINCREMENT, Lux NUMBER, Mean NUMBER , Power NUMBER);"); - - if (rc != SQLITE_OK) - { - printf("Error code : %i", rc); - fprintf(stderr, "SQL error: %s\n", err_msg); - - sqlite3_free(err_msg); - sqlite3_close(db); - - return 1; - } - sqlite3_close(db); - - return 0; + return 1; } + + char sql[101] = "CREATE TABLE "; + strcat(sql, tableName); + strcat(sql, " (Id INTEGER PRIMARY KEY AUTOINCREMENT, Lux NUMBER, Mean NUMBER , Power NUMBER);"); + + rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL); + rc = sqlite3_step(stmt); + rc = sqlite3_finalize(stmt); + sqlite3_close(db); + + return 0; } /** @@ -109,7 +111,8 @@ int main(void) { sqlite3_initialize(); - initializeTrailsAndCaptorMetadataTables(); - // createCaptorDataTable(1, 1); + initializeTrailsTable(); + initializeCaptorMetadataTable(); + createCaptorDataTable(12, 8); sqlite3_shutdown(); } \ No newline at end of file diff --git a/Db-Script/db b/Db-Script/db index e4aa2f9117689f6d4e5955547cbd1188f37e0133..c116f7d54c52becf6d6fcf05b1128d4caaa59f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ra2|rzJmS*Sm7rpKpF)J?pn1Ru;WsC2t z7VoQf3VFMt#W`-F`!!$P_Xk|DeypwIuZY`NKj7}SbbLdgWv8B zMd26qkHWnT(cI`jcQ_WR40N)qU9zEBuUze>-f5`O(5-NLhYK&1^^FdJ?{Ch_;4q?m zr*Xa&E;KrF`2OtD!}Z1*fp22Y=b^sIQNXu4=XDeYn~oS$tiwofrpW>pmyol(%LJ%! z)d>9ca_)q~E=P8&dVsXTPh30cF}Uq=2w%8-L%rJ}%-fatocB*1cDpFp7He2Z!3^cp4r^~tJh349vx;jNF)xw?Tnw%%LE24oy!;Y`~ E4~BsbK>z>% diff --git a/Db-Script/robotgowest.db b/Db-Script/robotgowest.db index 01bd2203494400e94527396b4c448e9d9da176fe..1e6be5e463f1441094245cd6591703de2536035d 100644 GIT binary patch literal 24576 zcmeI#!EV|x7{KwQ4R9IjZcz^vzKy8Sq;Ar*<7jHCsF1P{w4og)cTFWEAR`IdcFf*j zuec|fAy6qCrXF^R{+3Ma*bbk6_T?LY7|ilmJS6Et<>HO;!Z1zay%2_BSh_ZK-Iq;& zQ}@N(H~#Uoj8`|m+j>Hy{n#z*C|Y^WuKjy#bg(TcTq-BJ{t!?lyCoc z3~!HHw&R$;UT$OX)VDlIhjFg%wMVsQRpP0RJrSl{6s#9_T0uj)B1&g!UaGpHe;Z2w zI@pqScO#AnWnYFe@Z`9ho#{VwoY7I!K0i07+px3MT<6MPvUs(QmtW(9?r|mXgTd}n zEn-)%bc$zY%RW6di>y43O=Q_NitMQJh4S4Kw>(O+Sw2gaB9fo z<6XI0r)oP_(>R;lTqpe$1Q0*~0R#|0009ILKmY**5U8;L`G1WMm#ray00IagfB*sr zAb=Lo3e@p2 z1u#!m