diff options
Diffstat (limited to 'src/dbhelper.c')
-rw-r--r-- | src/dbhelper.c | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/src/dbhelper.c b/src/dbhelper.c index 2be76ed..66bae7d 100644 --- a/src/dbhelper.c +++ b/src/dbhelper.c @@ -1,3 +1,13 @@ +/* dbhelper.c - Database layer for ck -----------------------------------*- C -*- + * + * This file is part of ck, the config keeper + * + * ----------------------------------------------------------------------------- + * + * Copyright (C) 2018 Anastasis Grammenos + * GPLv3 (see LICENCE for the full notice) + * + * -------------------------------------------------------------------------- */ #include "dbhelper.h" void dbh_form_query_make_tables(char *query) { @@ -18,7 +28,7 @@ void dbh_form_query_make_tables(char *query) { strcat(tmp, " TEXT NOT NULL, "); strcat(tmp, COL_CONFIG_SECRET); strcat(tmp, " INT NOT NULL, "); - strcat(tmp, COL_CONFIG_PRIME); + strcat(tmp, COL_CONFIG_PRIMARY); strcat(tmp, " INT NOT NULL); "); strcat(tmp, "CREATE TABLE "); @@ -103,3 +113,59 @@ void dhb_form_query_find_relationship(char *query) { strcpy(query, tmp); } + +void dbh_format_query_select_from_joined_eq(char *query, const char *selection, const char* condition) { + char tmp[STR_L] = "SELECT "; + strcat(tmp, selection); + strcat(tmp, " FROM "); + strcat(tmp, TBL_REL); + strcat(tmp, " JOIN "); + strcat(tmp, TBL_PROGRAM); + strcat(tmp, " ON "); + strcat(tmp, TBL_PROGRAM); + strcat(tmp, "."); + strcat(tmp, COL_PROGRAM_ID); + strcat(tmp, " = "); + strcat(tmp, COL_REL_PROGRAM_ID); + strcat(tmp, " JOIN "); + strcat(tmp, TBL_CONFIG); + strcat(tmp, " ON "); + strcat(tmp, TBL_CONFIG); + strcat(tmp, "."); + strcat(tmp, COL_CONFIG_ID); + strcat(tmp, " = "); + strcat(tmp, COL_REL_CONFIG_ID); + strcat(tmp, " WHERE "); + strcat(tmp, condition); + strcat(tmp, " = ?;"); + + strcpy(query, tmp); +} + +void dbh_format_query_select_from_joined_like(char *query, const char *selection, const char* condition) { + char tmp[STR_L] = "SELECT "; + strcat(tmp, selection); + strcat(tmp, " FROM "); + strcat(tmp, TBL_REL); + strcat(tmp, " JOIN "); + strcat(tmp, TBL_PROGRAM); + strcat(tmp, " ON "); + strcat(tmp, TBL_PROGRAM); + strcat(tmp, "."); + strcat(tmp, COL_PROGRAM_ID); + strcat(tmp, " = "); + strcat(tmp, COL_REL_PROGRAM_ID); + strcat(tmp, " JOIN "); + strcat(tmp, TBL_CONFIG); + strcat(tmp, " ON "); + strcat(tmp, TBL_CONFIG); + strcat(tmp, "."); + strcat(tmp, COL_CONFIG_ID); + strcat(tmp, " = "); + strcat(tmp, COL_REL_CONFIG_ID); + strcat(tmp, " WHERE "); + strcat(tmp, condition); + strcat(tmp, " LIKE '%' || ? || '%';"); + + strcpy(query, tmp); +} |