From b1a5b8b7bf4015f699d691a57af435aa3357a3b2 Mon Sep 17 00:00:00 2001 From: QuentinPerret Date: Thu, 1 Jun 2023 23:26:13 +0200 Subject: [PATCH] create table progression --- Db-Script/database.c | 71 +++++++++++++++++---------------------- Db-Script/db | Bin 17256 -> 17376 bytes Db-Script/robotgowest.db | Bin 0 -> 16384 bytes influxdb_token.txt | 1 - robotgowestdb.db | Bin 8192 -> 0 bytes 5 files changed, 31 insertions(+), 41 deletions(-) delete mode 100644 influxdb_token.txt delete mode 100644 robotgowestdb.db 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 5e51ebf8cfa7a85dadef2ba112dcd10cf44b4a72..e4aa2f9117689f6d4e5955547cbd1188f37e0133 100755 GIT binary patch delta 3293 zcmZV=YiyI(^^N^IiR~mFpJ}L|B#TN~9rHL2lM1Ho>L^wDlLXPb{_sA8)%Q}gDS$FR5R{a63#2o+=wdn=5 z#0lU*Zbl_>3ot@oD1N?J;?~m^NlaQ`r)nzqHN$^G^WS&RXy#u3VzPeljk1y9i;z@p z-I|SN6#p7#PDdD4F`}%g*u7KyGv4F z(wGaT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rTp9+AHK-~o>0?Gv94pQ z8IvpZFq$!IG0a-q*G1MIMH{-8<}Jc3mwcaWi>y6_ZIQM6u8Oo#Ja(wfituOPTHFApX$7Fla`^O5b_n&}Sf8<5&2YFgX-cKNNS z=)#5L>*6+k3lV#;{U5374-qT=rK;x;8xaGDMT@F>1@Q-n@wiuAH&k^!;_p6D)kee( zw^X$g(Svvh@n?wdA!agoKmSXHvme2K@=J{K*H!fmC@v`EJ7HUa#pgip-RPCMQqm3> z8j@ETcCSvr`!5$&-@|_p?LYaP{ncgr5!7d4G(p@y%l+f_8;D><)m!*~3SKM7D~e)^ z;>488^n982t;F73pxkSzTWES=5KW7M^Tad^SM4cp4H;u2X@ zAa;T=l#|#zA)F~I=X3B^)TAJTFqL_rsNBYnz@GA~xOBFJ_zdp^ZnsR^*FcHAoTq`$ zZpm?KA2fZyd~6t43Vwd4>=u3yUbEZy3@q5ad_UAwJdO@eRD6}+4+|A}=B-*v^ton2 zex)S`P_(ja*6GxJN-TvFXmy}94Xr~ftc_%a(aJ=#M^CiYeH&T$QBm&_^**X|rZi70 z$9Yk3eoC>FokmVN&ZaC~IurXDn;)XyY{+K%XIvYK{af^nhnK1>IT^UOsqf+%X>HX= zg>b$qZ)DP`_mOy58!4)7J-n?%snWdsM$5A}acFU%J`JBaEA!yi_!qTN#koQL7ERwF z6$Pvx2c*)j87^s46h{*EPhgl9eu(Ov=aECxT{+l~;6}B@_$#y);9D-k^gi+E?G-6{ zu#khH0C&agl+c z?kWBTjMdqa=CoCuOM^G-s?7SL>bM8E(`M2)st0PEoB0bc=Cql=@Y;scs9nmZmBI&} zhLaKQs^fSZUG+ATzJEL6iTY~Os8cZ65S*&7<3sRieVyr8snl%+S3`BuVzrd68(?2U OmFdz3DJB4~&HEq4BROyY diff --git a/Db-Script/robotgowest.db b/Db-Script/robotgowest.db index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..01bd2203494400e94527396b4c448e9d9da176fe 100644 GIT binary patch literal 16384 zcmeI%ISK+X6oBCuN9DMS&MX{=<_2!abb<2l5mc@vLdMl94u3k8e+ zLC7Rzl9w-4$Y{`AhDI;8`?VkHs$@hdscS7FjxF(ftsdI;^A=IxyKtn^IVICgiKQ-* zKBq3WA`n0T0R#|0009ILKmY**5cs)3-$~?(MKuon>B5+*x=A8ab z+ULLdfr^J)Dgu2*yXn(MRcbQ;Z$ M|5R@`y+*731DnG*A^-pY