create table progression

This commit is contained in:
QuentinPerret 2023-06-01 23:26:13 +02:00
parent b15892d0a0
commit b1a5b8b7bf
5 changed files with 31 additions and 41 deletions

View file

@ -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, 0, 0, &err_msg);
rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
printf("%i\n", rc);
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;
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();
}

Binary file not shown.

Binary file not shown.

View file

@ -1 +0,0 @@
mlxKvuIC8vZ9qQMAVxa4jD9vCLekIMFXI3tdHmx-Ho88ER1IAQfq5J1m3Rfpz_41ML6ZRSh0jZBb-aQAzoZExA==

Binary file not shown.