Compare commits
3 Commits
662ff18a28
...
ff3ae9ce59
Author | SHA1 | Date | |
---|---|---|---|
ff3ae9ce59 | |||
cbb1f3e3a4 | |||
59a295a756 |
46
include/sql_stmt.inc
Normal file
46
include/sql_stmt.inc
Normal file
@ -0,0 +1,46 @@
|
||||
VARDECL sqlite3_stmt * remind_stmt;
|
||||
VARDECL char const remind_stmt_template[] =
|
||||
"SELECT "
|
||||
"title,"
|
||||
"body,"
|
||||
"difficulty,"
|
||||
"repo_link,"
|
||||
"trigger_date,"
|
||||
"started DATE,"
|
||||
"span"
|
||||
" FROM assignment INNER JOIN project on assignment.project = project.rowid "
|
||||
"WHERE who = ?;";
|
||||
|
||||
VARDECL sqlite3_stmt * set_repo_stmt;
|
||||
VARDECL char const set_repo_stmt_template[] =
|
||||
"UPDATE assignment "
|
||||
"SET "
|
||||
"repo_link = ? "
|
||||
"WHERE who = ?;";
|
||||
|
||||
VARDECL char const dump_stmt[] =
|
||||
"SELECT * FROM project;";
|
||||
|
||||
VARDECL sqlite3_stmt * get_nth_id_stmt;
|
||||
VARDECL char const get_nth_id_stmt_template[] =
|
||||
"SELECT rowid "
|
||||
"FROM project "
|
||||
"LIMIT 1 "
|
||||
"OFFSET ?;";
|
||||
|
||||
VARDECL sqlite3_stmt * new_assignment_stmt;
|
||||
VARDECL char const new_assignment_stmt_template[] =
|
||||
"INSERT INTO assignment "
|
||||
"(who, project)"
|
||||
" VALUES "
|
||||
"(?, ?);";
|
||||
|
||||
VARDECL sqlite3_stmt * purge_assignments_stmt;
|
||||
VARDECL char const purge_assignments_stmt_template[] =
|
||||
"DELETE FROM assignment "
|
||||
"WHERE who = ?;";
|
||||
|
||||
VARDECL sqlite3_stmt* is_no_assignment_stmt;
|
||||
VARDECL const char is_no_assignment_stmt_template[] =
|
||||
"SELECT * FROM assignment "
|
||||
"WHERE who = ?;" ;
|
67
src/api.c
67
src/api.c
@ -1,69 +1,22 @@
|
||||
#define DBFILE "probotic_data.sqlite"
|
||||
|
||||
#define DBERR(l) do { \
|
||||
if(l != SQLITE_OK && l != SQLITE_ROW && l != SQLITE_DONE) \
|
||||
{ \
|
||||
fprintf(stderr, \
|
||||
"sqlite (%d): %s\n", \
|
||||
sqlite3_errcode(connection), sqlite3_errmsg(connection)); \
|
||||
exit(DB_ERROR); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define stmt_prepare(stmt) \
|
||||
sqlite3_prepare_v2(connection, stmt ## _template, -1, &stmt, NULL)
|
||||
|
||||
VARDECL sqlite3_stmt * remind_stmt;
|
||||
VARDECL char const remind_stmt_template[] =
|
||||
"SELECT "
|
||||
"title,"
|
||||
"body,"
|
||||
"difficulty,"
|
||||
"repo_link,"
|
||||
"trigger_date,"
|
||||
"started DATE,"
|
||||
"span"
|
||||
" FROM assignment INNER JOIN project on assignment.project = project.rowid "
|
||||
"WHERE who = ?;";
|
||||
|
||||
VARDECL sqlite3_stmt * set_repo_stmt;
|
||||
VARDECL char const set_repo_stmt_template[] =
|
||||
"UPDATE assignment "
|
||||
"SET "
|
||||
"repo_link = ? "
|
||||
"WHERE who = ?;";
|
||||
|
||||
VARDECL char const dump_stmt[] =
|
||||
"SELECT * FROM project;";
|
||||
|
||||
VARDECL sqlite3_stmt * get_nth_id_stmt;
|
||||
VARDECL char const get_nth_id_stmt_template[] =
|
||||
"SELECT rowid "
|
||||
"FROM project "
|
||||
"LIMIT 1 "
|
||||
"OFFSET ?;";
|
||||
|
||||
VARDECL sqlite3_stmt * new_assignment_stmt;
|
||||
VARDECL char const new_assignment_stmt_template[] =
|
||||
"INSERT INTO assignment "
|
||||
"(who, project)"
|
||||
" VALUES "
|
||||
"(?, ?);";
|
||||
|
||||
VARDECL sqlite3_stmt * purge_assignments_stmt;
|
||||
VARDECL char const purge_assignments_stmt_template[] =
|
||||
"DELETE FROM assignment "
|
||||
"WHERE who = ?;";
|
||||
|
||||
VARDECL sqlite3_stmt* is_no_assignment_stmt;
|
||||
VARDECL const char is_no_assignment_stmt_template[] =
|
||||
"SELECT * FROM assignment "
|
||||
"WHERE who = ?;" ;
|
||||
|
||||
VARDECL char const * db = DBFILE;
|
||||
|
||||
VARDECL sqlite3 * connection = NULL;
|
||||
|
||||
DECL void DBERR(const int l){
|
||||
if(l != SQLITE_OK && l != SQLITE_ROW && l != SQLITE_DONE)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"sqlite (%d): %s\n",
|
||||
sqlite3_errcode(connection), sqlite3_errmsg(connection));
|
||||
exit(DB_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
DECL int
|
||||
api_init(void)
|
||||
{
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "sql_stmt.inc"
|
||||
|
||||
#include "api.h"
|
||||
#include "error.h"
|
||||
#include "free.h"
|
||||
|
Reference in New Issue
Block a user