aboutsummaryrefslogtreecommitdiffstats
path: root/src/dbhelper.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2018-04-22 18:07:50 +0300
committergramanas <anastasis.gramm2@gmail.com>2018-04-22 18:07:50 +0300
commit225600aadffc6fdb188fef230cdab67e1242e3a3 (patch)
tree026d4017b40906a0aa3b2044cf6b52049a053a1c /src/dbhelper.c
parenteeca7f0151d85d563d1db229e3b7ca936323ffa2 (diff)
downloadck-225600aadffc6fdb188fef230cdab67e1242e3a3.tar.gz
ck-225600aadffc6fdb188fef230cdab67e1242e3a3.tar.bz2
ck-225600aadffc6fdb188fef230cdab67e1242e3a3.zip
Add almost done, opt parsing remains
Diffstat (limited to 'src/dbhelper.c')
-rw-r--r--src/dbhelper.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/dbhelper.c b/src/dbhelper.c
new file mode 100644
index 0000000..2be76ed
--- /dev/null
+++ b/src/dbhelper.c
@@ -0,0 +1,105 @@
+#include "dbhelper.h"
+
+void dbh_form_query_make_tables(char *query) {
+ char tmp[STR_L] = "CREATE TABLE ";
+ strcat(tmp, TBL_PROGRAM);
+ strcat(tmp, "(");
+ strcat(tmp, COL_PROGRAM_ID);
+ strcat(tmp, " INT NOT NULL PRIMARY KEY, ");
+ strcat(tmp, COL_PROGRAM_NAME);
+ strcat(tmp, " TEXT NOT NULL); ");
+
+ strcat(tmp, "CREATE TABLE ");
+ strcat(tmp, TBL_CONFIG);
+ strcat(tmp, "(");
+ strcat(tmp, COL_CONFIG_ID);
+ strcat(tmp, " INT NOT NULL PRIMARY KEY, ");
+ strcat(tmp, COL_CONFIG_PATH);
+ strcat(tmp, " TEXT NOT NULL, ");
+ strcat(tmp, COL_CONFIG_SECRET);
+ strcat(tmp, " INT NOT NULL, ");
+ strcat(tmp, COL_CONFIG_PRIME);
+ strcat(tmp, " INT NOT NULL); ");
+
+ strcat(tmp, "CREATE TABLE ");
+ strcat(tmp, TBL_REL);
+ strcat(tmp, "(");
+ strcat(tmp, COL_REL_PROGRAM_ID);
+ strcat(tmp, " INT NOT NULL, ");
+ strcat(tmp, COL_REL_CONFIG_ID);
+ strcat(tmp, " INT NOT NULL);");
+
+ strcpy(query, tmp);
+}
+
+void dbh_form_query_insert_program(char *query) {
+ char tmp[STR_L] = "INSERT INTO ";
+ strcat(tmp, TBL_PROGRAM);
+ strcat(tmp, " VALUES(?, ?);");
+
+ strcpy(query, tmp);
+}
+
+void dbh_form_query_insert_config(char *query) {
+ char tmp[STR_L] = "INSERT INTO ";
+ strcat(tmp, TBL_CONFIG);
+ strcat(tmp, " VALUES(?, ?, ?, ?);");
+
+ strcpy(query, tmp);
+}
+
+void dbh_form_query_select_id_from(char *query, const char* tableName) {
+ char tmp[STR_M] = "SELECT ID FROM ";
+ strcat(tmp, tableName);
+ strcat(tmp, " ORDER BY ID;");
+
+ strcpy(query, tmp);
+}
+
+void dbh_form_query_select_all_tables(char *query) {
+ strcpy(query, "SELECT * FROM SQLITE_MASTER WHERE type='table';");
+}
+
+void dhb_form_query_insert_relationship(char *query) {
+ char tmp[STR_M] = "INSERT INTO ";
+ strcat(tmp, TBL_REL);
+ strcat(tmp, " VALUES(?, ?);");
+
+ strcpy(query, tmp);
+}
+
+void dhb_form_query_find_program(char *query) {
+ char tmp[STR_M] = "SELECT ID FROM ";
+ strcat(tmp, TBL_PROGRAM);
+ strcat(tmp, " WHERE ");
+ strcat(tmp, COL_PROGRAM_NAME);
+ strcat(tmp, " = ?;");
+
+ strcpy(query, tmp);
+}
+
+void dhb_form_query_find_config(char *query) {
+ char tmp[STR_M] = "SELECT ID FROM ";
+ strcat(tmp, TBL_CONFIG);
+ strcat(tmp, " WHERE ");
+ strcat(tmp, COL_CONFIG_PATH);
+ strcat(tmp, " = ?;");
+
+ strcpy(query, tmp);
+}
+
+void dhb_form_query_find_relationship(char *query) {
+ char tmp[STR_M] = "SELECT ";
+ strcat(tmp, COL_REL_PROGRAM_ID);
+ strcat(tmp, ", ");
+ strcat(tmp, COL_REL_CONFIG_ID);
+ strcat(tmp, " FROM ");
+ strcat(tmp, TBL_REL);
+ strcat(tmp, " WHERE ");
+ strcat(tmp, COL_REL_PROGRAM_ID);
+ strcat(tmp, " = ? AND ");
+ strcat(tmp, COL_REL_CONFIG_ID);
+ strcat(tmp, " = ?;");
+
+ strcpy(query, tmp);
+}