create and insert ok

This commit is contained in:
QuentinPerret 2023-06-02 12:48:29 +02:00
parent 4672159f50
commit 49060a8419
7 changed files with 107 additions and 67 deletions

7
.vscode/launch.json vendored
View file

@ -1,7 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}

26
.vscode/settings.json vendored
View file

@ -1,26 +0,0 @@
{
"C_Cpp.errorSquiggles": "Disabled",
"files.associations": {
"time.h": "c",
"b2hd.h": "c",
"main.h": "c",
"stdio.h": "c",
"string.h": "c",
"initialparameters.h": "c",
"filegestion.h": "c",
"power.h": "c",
"getarray.h": "c",
"math.h": "c",
"limits": "c",
"*.tcc": "c",
"type_traits": "c",
"simulateflux.h": "c",
"pthread.h": "c",
"types.h": "c",
"average.h": "c",
"queue.h": "c",
"growthrate.h": "c",
"stdbool.h": "c"
},
"cmake.configureOnOpen": false
}

20
.vscode/tasks.json vendored
View file

@ -1,20 +0,0 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:/msys64/mingw64/bin/gcc.exe",
"args": ["-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}"],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:/msys64/mingw64/bin/gcc.exe"
}
],
"version": "2.0.0"
}

View file

@ -1,5 +0,0 @@
{
"files.associations": {
"power.h": "c"
}
}

View file

@ -40,6 +40,19 @@ int initializeCaptorMetadataTable()
sqlite3_close(db); sqlite3_close(db);
} }
char *generateDataTableName(int trialId, int captorNumber)
{
char *tableName;
tableName = (char *)malloc(8 * sizeof(char));
strcpy(tableName, "T");
strcat(tableName, convertIntegerToChar(trialId));
strcat(tableName, "C");
strcat(tableName, convertIntegerToChar(captorNumber));
strcat(tableName, "Data");
return tableName;
}
int createCaptorDataTable(int trialId, int captorNumber) int createCaptorDataTable(int trialId, int captorNumber)
{ {
sqlite3 *db; sqlite3 *db;
@ -48,12 +61,7 @@ int createCaptorDataTable(int trialId, int captorNumber)
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
// Create Table Name // Create Table Name
char tableName[8]; char *tableName = generateDataTableName(trialId, captorNumber);
strcpy(tableName, "T");
strcat(tableName, convertIntegerToChar(trialId));
strcat(tableName, "C");
strcat(tableName, convertIntegerToChar(captorNumber));
strcat(tableName, "Data");
rc = sqlite3_open("robotgowest.db", &db); rc = sqlite3_open("robotgowest.db", &db);
if (rc != SQLITE_OK) if (rc != SQLITE_OK)
@ -107,12 +115,102 @@ char *convertIntegerToChar(int N)
return (char *)arr; return (char *)arr;
} }
int insertTrailElement(char *position, int start, double frequency, int duration)
{
sqlite3 *db;
sqlite3_stmt *stmt;
char *err_msg;
int rc;
int idx;
rc = sqlite3_open("robotgowest.db", &db);
rc = sqlite3_prepare_v2(db, "INSERT INTO Trials(Position,Start,Frequency,Duration) VALUES ( :position , :start , :frequency , :duration )", -1, &stmt, NULL);
if (rc != SQLITE_OK)
return 1;
sqlite3_bind_text(stmt, 1, position, -1, SQLITE_STATIC);
sqlite3_bind_int(stmt, 2, start);
sqlite3_bind_double(stmt, 3, frequency);
sqlite3_bind_int(stmt, 4, duration);
rc = sqlite3_step(stmt);
rc = sqlite3_finalize(stmt);
sqlite3_close(db);
}
int insertCaptorMetadataElement(int captorNumber, int trialId)
{
sqlite3 *db;
sqlite3_stmt *stmt;
char *err_msg;
int rc;
int idx;
rc = sqlite3_open("robotgowest.db", &db);
rc = sqlite3_prepare_v2(db, "INSERT INTO CaptorMetadata(CaptorNumber,TrialId) VALUES ( :captorNumber , :trialId)", -1, &stmt, NULL);
if (rc != SQLITE_OK)
return 1;
sqlite3_bind_int(stmt, 1, captorNumber);
sqlite3_bind_int(stmt, 2, trialId);
rc = sqlite3_step(stmt);
rc = sqlite3_finalize(stmt);
sqlite3_close(db);
}
int insertCaptorDataElement(int trialId, int captorNumber, double lux, double mean, double power)
{
char *tableName = generateDataTableName(trialId, captorNumber);
sqlite3 *db;
sqlite3_stmt *stmt;
char *err_msg;
int rc;
int idx;
rc = sqlite3_open("robotgowest.db", &db);
char sql[70] = "INSERT INTO ";
strcat(sql, tableName);
strcat(sql, "(Lux,Mean,Power) VALUES ( :lux , :mean , :power)");
printf(sql);
rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
if (rc != SQLITE_OK)
return 1;
sqlite3_bind_double(stmt, 1, lux);
sqlite3_bind_double(stmt, 2, mean);
sqlite3_bind_double(stmt, 3, power);
rc = sqlite3_step(stmt);
rc = sqlite3_finalize(stmt);
sqlite3_close(db);
}
int main(void) int main(void)
{ {
sqlite3_initialize(); sqlite3_initialize();
initializeTrailsTable(); // initializeTrailsTable();
initializeCaptorMetadataTable(); // initializeCaptorMetadataTable();
createCaptorDataTable(12, 8); // createCaptorDataTable(12, 8);
// insertTrailElement("test", 1, 3.0, 9);
// insertCaptorMetadataElement(1, 2);
// insertCaptorDataElement(12, 8, 10, 121, 1513);
sqlite3_shutdown(); sqlite3_shutdown();
} }

Binary file not shown.

Binary file not shown.