raw prototype

This commit is contained in:
anon 2023-08-03 11:31:07 +02:00
parent 418ea56174
commit 2447bd561e
3 changed files with 24 additions and 4 deletions

View File

@ -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

View File

@ -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 = ?;"
;

View File

@ -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);