6 static void updateSensor(sqlite3* db, int id, int value);
8 int main(int argc, char *argv[]) {
10 printf ("Usage: %s db_location\n", argv[0]);
17 if (ret = sqlite3_open(argv[1], &db) != SQLITE_OK) {
18 printf("Error opening database: %s\n",
23 sqlite3_stmt *statement;
24 char *query = "insert into sensors values(3,4)";
25 if (ret = sqlite3_prepare(db, query, (int)strlen(query) + 1, &statement, NULL) != SQLITE_OK) {
26 printf("Error in query: %s\n",
30 sqlite3_step(statement);
31 sqlite3_finalize(statement);
33 updateSensor(db, 44, 2332);
38 static void updateSensor(sqlite3* db, int id, int value) {
40 snprintf(query, BUFSIZ, "update sensors set value=%d where id=%d", value, id);
42 //Needs error checking
44 if (ret = sqlite3_exec(db, query, NULL, NULL, NULL) != SQLITE_OK) {
45 printf("Error: %s\n", sqlite3_errstr(ret));
47 if (!sqlite3_changes(db)) {
48 printf("Record doesn't exist; creating!\n");
49 snprintf(query, BUFSIZ, "insert into sensors values(%d, %d)", id, value);
50 sqlite3_exec(db, query, NULL, NULL, NULL);