dont make me stare at sql

This commit is contained in:
anon 2023-08-04 16:25:44 +02:00
parent 59a295a756
commit cbb1f3e3a4
3 changed files with 48 additions and 47 deletions

46
include/sql_stmt.inc Normal file
View 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 = ?;" ;

View File

@ -3,53 +3,6 @@
#define stmt_prepare(stmt) \ #define stmt_prepare(stmt) \
sqlite3_prepare_v2(connection, stmt ## _template, -1, &stmt, NULL) 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 char const * db = DBFILE;
VARDECL sqlite3 * connection = NULL; VARDECL sqlite3 * connection = NULL;

View File

@ -10,6 +10,8 @@
#include <sqlite3.h> #include <sqlite3.h>
#include "sql_stmt.inc"
#include "api.h" #include "api.h"
#include "error.h" #include "error.h"
#include "free.h" #include "free.h"