diff options
Diffstat (limited to 'src/queries.h')
-rw-r--r-- | src/queries.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/queries.h b/src/queries.h new file mode 100644 index 0000000..d4c3ae0 --- /dev/null +++ b/src/queries.h @@ -0,0 +1,65 @@ +/* queries.h - Database stuff for ck -----------------------------------*- C -*- + * + * This file is part of ck, the config keeper + * + * ----------------------------------------------------------------------------- + * + * Copyright (C) 2018 Anastasis Grammenos + * GPLv3 (see LICENCE for the full notice) + * + * ----------------------------------------------------------------------------- + * + * SQlite tables and columns. + * Form query functions. + * + * -------------------------------------------------------------------------- */ +#ifndef DBHELPER_H +#define DBHELPER_H + +#include <sqlite3.h> + +#include "clparser.h" +#include "ckutil.h" + +/********************/ +/* sqlite constants */ +/********************/ +#define TBL_PROGRAM "PROGRAM" +#define TBL_CONFIG "CONFIG" +#define TBL_REL "REL" + +#define COL_PROGRAM_ID "ID" +#define COL_PROGRAM_NAME "NAME" + +#define COL_CONFIG_ID "ID" +#define COL_CONFIG_PATH "PATH" +#define COL_CONFIG_SECRET "SECRET" +#define COL_CONFIG_PRIMARY "PRIME" + +#define COL_REL_PROGRAM_ID "PID" +#define COL_REL_CONFIG_ID "CID" + +#define __BEGIN_TRANSACTION__ sqlite3_exec(db->ptr, "BEGIN TRANSACTION;", NULL, NULL, NULL); +#define __END_TRANSACTION__ sqlite3_exec(db->ptr, "END TRANSACTION;", NULL, NULL, NULL); + +/****************/ +/* form queries */ +/****************/ + +void dbh_form_query_make_tables(char *query); +void dbh_form_query_insert_program(char *query); +void dbh_form_query_insert_config(char *query); +void dbh_form_query_select_id_from(char *query, const char* tableName); +void dbh_form_query_select_all_tables(char *query); +void dhb_form_query_insert_relationship(char *query); +void dhb_form_query_find_program(char *query); +void dhb_form_query_find_config(char *query); +void dhb_form_query_find_relationship(char *query); +void dbh_form_query_select_paths_with_attributes(char *query); +void dbh_form_query_select_programs(char *query); +void dbh_form_query_select_from_joined_eq(char *query, const char *selection, const char* condition); +void dbh_form_query_select_from_joined_like(char *query, const char *selection, const char* condition); +void dbh_form_query_delete_x_from_y(char *query, const char *x, const char *y); +void dbh_form_query_count_program_relations(char *query); +void dbh_form_query_get_pid_from_cid(char *query); +#endif /* DBHELPER_H */ |