diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2018-04-22 21:30:31 +0300 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2018-04-22 21:30:31 +0300 |
commit | 0a5257ea63cce0cebc93eb71e51dbbb3eb14a9a3 (patch) | |
tree | 6cdc4ddeec5727ebb0dd112ef01f8661e2447c0e /src/dbhelper.c | |
parent | 225600aadffc6fdb188fef230cdab67e1242e3a3 (diff) | |
download | ck-0a5257ea63cce0cebc93eb71e51dbbb3eb14a9a3.tar.gz ck-0a5257ea63cce0cebc93eb71e51dbbb3eb14a9a3.tar.bz2 ck-0a5257ea63cce0cebc93eb71e51dbbb3eb14a9a3.zip |
Add read, the actual linking remains
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); +} |