From cbb1f3e3a4c9c8611752081af81cab00bfd66caf Mon Sep 17 00:00:00 2001 From: anon Date: Fri, 4 Aug 2023 16:25:44 +0200 Subject: [PATCH] dont make me stare at sql --- include/sql_stmt.inc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/api.c | 47 ----------------------------------------------- src/unity.c | 2 ++ 3 files changed, 48 insertions(+), 47 deletions(-) create mode 100644 include/sql_stmt.inc diff --git a/include/sql_stmt.inc b/include/sql_stmt.inc new file mode 100644 index 0000000..fa4a293 --- /dev/null +++ b/include/sql_stmt.inc @@ -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 = ?;" ; diff --git a/src/api.c b/src/api.c index 8d724a3..4f51db5 100644 --- a/src/api.c +++ b/src/api.c @@ -3,53 +3,6 @@ #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; diff --git a/src/unity.c b/src/unity.c index 19a0a15..70dce59 100644 --- a/src/unity.c +++ b/src/unity.c @@ -10,6 +10,8 @@ #include +#include "sql_stmt.inc" + #include "api.h" #include "error.h" #include "free.h"