From 2447bd561e14a9cfc2773d46037af76bbf316ade Mon Sep 17 00:00:00 2001 From: anon Date: Thu, 3 Aug 2023 11:31:07 +0200 Subject: [PATCH] raw prototype --- include/api.h | 1 + include/stmt.h | 12 ++++++++++-- src/api.c | 15 +++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/api.h b/include/api.h index 3c62846..06f047f 100644 --- a/include/api.h +++ b/include/api.h @@ -4,6 +4,7 @@ DECL int api_init(void); DECL void api_rope(void); DECL void rope(void); DECL char * remind(char * who); +DECL char * raw(const char * const sql); #define API_H_ #endif diff --git a/include/stmt.h b/include/stmt.h index 2a8d78b..e593e35 100644 --- a/include/stmt.h +++ b/include/stmt.h @@ -1,3 +1,6 @@ +#define stmt_prepare(stmt) \ + sqlite3_prepare_v2(connection, stmt ## _template, -1, &stmt, NULL) + static sqlite3_stmt* remind_stmt; static const char remind_stmt_template[] = "SELECT " @@ -12,5 +15,10 @@ static const char remind_stmt_template[] = "WHERE who = ?;" ; -#define stmt_prepare(stmt) \ - sqlite3_prepare_v2(connection, stmt ## _template, -1, &stmt, NULL) +static sqlite3_stmt* set_repo_stmt; +static const char set_repo_stmt_template[] = + "UPDATE assignment " + "SET " + "repo_link = ? " + "WHERE who = ?;" +; diff --git a/src/api.c b/src/api.c index 2cd25d8..f31d207 100644 --- a/src/api.c +++ b/src/api.c @@ -33,7 +33,8 @@ DECL int api_init(void) { DBERR(sqlite3_open(DBFILE, &connection)); - stmt_prepare(remind_stmt); + DBERR(stmt_prepare(remind_stmt)); + DBERR(stmt_prepare(set_repo_stmt)); return 0; } @@ -76,6 +77,16 @@ remind(char * who) return r; } +DECL char * +set_repo(char* who, char* link) +{ + char * r; + DBERR(sqlite3_bind_text(set_repo_stmt, 1, link, -1, SQLITE_STATIC)); + DBERR(sqlite3_bind_text(set_repo_stmt, 2, who, -1, SQLITE_STATIC)); + DBERR(sqlite3_step(set_repo_stmt)); + return r; +} + DECL int rtos(void* data, int argc, @@ -101,7 +112,7 @@ rtos(void* data, } DECL char * -raw(char * sql) +raw(const char * const sql) { char* errmsg; char* r = (char*)malloc(10000);