diff options
author | Joshua Liu <joshua.liu@sourceobby.com> | 2025-09-20 18:35:41 -0400 |
---|---|---|
committer | Joshua Liu <joshua.liu@sourceobby.com> | 2025-09-20 18:35:41 -0400 |
commit | 84b420394e66e401df65cbf79f548e529161ce5f (patch) | |
tree | c3e43307c203ef611c5b55e59f8af95987dcd17c | |
parent | 6b4d7e0d84d7b065df46ac97c19c8b3e71c15cdd (diff) |
feat: starting to implement sqlite functionality
-rw-r--r-- | util.c | 41 | ||||
-rw-r--r-- | util.h | 3 |
2 files changed, 39 insertions, 5 deletions
@@ -1,6 +1,10 @@ #include "util.h" #include <stdint.h> +sqlite3* initialize_db_con (char* target); +char* format_sql_query (char* data); +int read_db_callback (void*, int, char**, char**); + int die(const char* msg) { @@ -27,11 +31,40 @@ spin (int* target, int success, int fail) } } -int -initialize_db_con () +/* + * Database structure: + * The plan is to have one master database, which contains a list of all the different + * streamdecks that are available. Each streamdeck has a unique serial number, so that + * is going to be a field, another field being the name of the database for that streamdeck. + * Then in another folder, there will be a bunch of databases, and we will just open and read + * the appropriate one. + */ +sqlite3* +initialize_db_con (char* target) { + sqlite3* res; + return (sqlite3_open(target, &res)) ? NULL : res; } int -parsestreamdeckdata() -{} +parsestreamdeckdata(char* serial_num) +{ + int sql_exec_res = 0; + char* errmsg; + char* query_res; + sqlite3* master = initialize_db_con("master.db"); + if (!master) + return 1; + char* query_for_serial = format_sql_query(serial_num); + sql_exec_res = sqlite3_exec(master, query_for_serial, read_db_callback, &query_res, &errmsg); + if (sql_exec_res) + fprintf (stderr, "%s\n", errmsg); + free (query_for_serial); + + return 0; +} + +int +read_db_callback (void* data, int argc, char** argv, char** azcolname) +{ +} @@ -4,8 +4,9 @@ #include <string.h> #include <pthread.h> #include <sys/epoll.h> +#include <sqlite3.h> int die(const char* msg); int set_data(unsigned char* data); -int parsestreamdeckdata(); +int parsestreamdeckdata(char* serial_num); int writestreamdeckdata(); |