Hoel
C Database abstraction library with json based language
hoel.h
Go to the documentation of this file.
1 
25 #ifndef __HOEL_H__
26 #define __HOEL_H__
27 
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32 
33 #include "hoel-cfg.h"
34 
35 #include <jansson.h>
36 
37 #ifndef __USE_XOPEN
38  #define __USE_XOPEN
39 #endif
40 #include <time.h>
41 #include <pthread.h>
42 
44 #include <yder.h>
45 #include <orcania.h>
46 
52 #define HOEL_DB_TYPE_SQLITE 0
53 #define HOEL_DB_TYPE_MARIADB 1
54 #define HOEL_DB_TYPE_PGSQL 2
55 
56 #define HOEL_COL_TYPE_INT 0
57 #define HOEL_COL_TYPE_DOUBLE 1
58 #define HOEL_COL_TYPE_TEXT 2
59 #define HOEL_COL_TYPE_DATE 3
60 #define HOEL_COL_TYPE_BLOB 4
61 #define HOEL_COL_TYPE_BOOL 5
62 #define HOEL_COL_TYPE_NULL 5
63 
64 #define H_OK 0 /* No error */
65 #define H_ERROR 1 /* Generic error */
66 #define H_ERROR_PARAMS 2 /* Error in input parameters */
67 #define H_ERROR_CONNECTION 3 /* Error in database connection */
68 #define H_ERROR_QUERY 4 /* Error executing query */
69 #define H_ERROR_MEMORY 99 /* Error allocating memory */
70 
71 #define H_OPTION_NONE 0x0000 /* Nothing whatsoever */
72 #define H_OPTION_SELECT 0x0001 /* Execute a SELECT statement */
73 #define H_OPTION_EXEC 0x0010 /* Execute an INSERT, UPDATE or DELETE statement */
74 
87 struct _h_connection {
88  int type;
89  void * connection;
90 };
91 
95 struct _h_type_int {
96  long long int value;
97 };
98 
103  double value;
104 };
105 
110  struct tm value;
111 };
112 
116 struct _h_type_text {
117  size_t length;
118  char * value;
119 };
120 
124 struct _h_type_blob {
125  size_t length;
126  void * value;
127 };
128 
132 struct _h_data {
133  int type;
134  void * t_data;
135 };
136 
140 struct _h_result {
141  unsigned int nb_rows;
142  unsigned int nb_columns;
143  struct _h_data ** data;
144 };
145 
160 int h_close_db(struct _h_connection * conn);
161 
175 void h_free(void * data);
176 
194 char * h_escape_string(const struct _h_connection * conn, const char * unsafe);
195 
204 char * h_escape_string_with_quotes(const struct _h_connection * conn, const char * unsafe);
205 
230 int h_execute_query(const struct _h_connection * conn, const char * query, struct _h_result * result, int options);
231 
239 int h_query_insert(const struct _h_connection * conn, const char * query);
240 
247 struct _h_data * h_query_last_insert_id(const struct _h_connection * conn);
248 
256 int h_query_update(const struct _h_connection * conn, const char * query);
257 
265 int h_query_delete(const struct _h_connection * conn, const char * query);
266 
275 int h_query_select(const struct _h_connection * conn, const char * query, struct _h_result * result);
276 
296 int h_execute_query_json(const struct _h_connection * conn, const char * query, json_t ** j_result);
297 
306 int h_query_select_json(const struct _h_connection * conn, const char * query, json_t ** j_result);
307 
366 int h_select(const struct _h_connection * conn, const json_t * j_query, json_t ** j_result, char ** generated_query);
367 
378 int h_insert(const struct _h_connection * conn, const json_t * j_query, char ** generated_query);
379 
388 json_t * h_last_insert_id(const struct _h_connection * conn);
389 
400 int h_update(const struct _h_connection * conn, const json_t * j_query, char ** generated_query);
401 
412 int h_delete(const struct _h_connection * conn, const json_t * j_query, char ** generated_query);
413 
430 int h_clean_result(struct _h_result * result);
431 
438 int h_clean_data(struct _h_data * data);
439 
446 int h_clean_data_full(struct _h_data * data);
447 
463 int h_clean_connection(struct _h_connection * conn);
464 
471 struct _h_connection * h_connect_sqlite(const char * db_path);
472 
477 void h_close_sqlite(struct _h_connection * conn);
478 
496 char * h_escape_string_sqlite(const struct _h_connection * conn, const char * unsafe);
497 
506 char * h_escape_string_with_quotes_sqlite(const struct _h_connection * conn, const char * unsafe);
507 
524 long long int h_last_insert_id_sqlite(const struct _h_connection * conn);
525 
536 int h_exec_query_sqlite(const struct _h_connection * conn, const char * query);
537 
548 int h_execute_query_json_sqlite(const struct _h_connection * conn, const char * query, json_t ** j_result);
549 
572 int h_select_query_sqlite(const struct _h_connection * conn, const char * query, struct _h_result * result);
573 
594 struct _h_connection * h_connect_mariadb(const char * host, const char * user, const char * passwd, const char * db, const unsigned int port, const char * unix_socket);
595 
599 void h_close_mariadb(struct _h_connection * conn);
600 
618 char * h_escape_string_mariadb(const struct _h_connection * conn, const char * unsafe);
619 
628 char * h_escape_string_with_quotes_mariadb(const struct _h_connection * conn, const char * unsafe);
629 
646 long long int h_last_insert_id_mariadb(const struct _h_connection * conn);
647 
657 int h_execute_query_json_mariadb(const struct _h_connection * conn, const char * query, json_t ** j_result);
658 
681 int h_execute_query_mariadb(const struct _h_connection * conn, const char * query, struct _h_result * result);
682 
693 struct _h_data * h_get_mariadb_value(const char * value, const unsigned long length, const int m_type);
694 
710 struct _h_connection * h_connect_pgsql(const char * conninfo);
711 
716 void h_close_pgsql(struct _h_connection * conn);
717 
735 char * h_escape_string_pgsql(const struct _h_connection * conn, const char * unsafe);
736 
745 char * h_escape_string_with_quotes_pgsql(const struct _h_connection * conn, const char * unsafe);
746 
767 int h_execute_query_json_pgsql(const struct _h_connection * conn, const char * query, json_t ** j_result);
768 
775 long long int h_last_insert_id_pgsql(const struct _h_connection * conn);
776 
799 int h_execute_query_pgsql(const struct _h_connection * conn, const char * query, struct _h_result * result);
800 
805 #ifdef __cplusplus
806 }
807 #endif
808 
809 #endif /* __HOEL_H__ */
h_query_last_insert_id
struct _h_data * h_query_last_insert_id(const struct _h_connection *conn)
Definition: hoel.c:321
h_connect_mariadb
struct _h_connection * h_connect_mariadb(const char *host, const char *user, const char *passwd, const char *db, const unsigned int port, const char *unix_socket)
Definition: hoel-mariadb.c:428
_h_type_blob
Definition: hoel.h:124
h_get_mariadb_value
struct _h_data * h_get_mariadb_value(const char *value, const unsigned long length, const int m_type)
_h_result::nb_columns
unsigned int nb_columns
Definition: hoel.h:142
h_connect_sqlite
struct _h_connection * h_connect_sqlite(const char *db_path)
Definition: hoel-sqlite.c:310
h_clean_result
int h_clean_result(struct _h_result *result)
Definition: hoel.c:416
_h_type_int::value
long long int value
Definition: hoel.h:96
h_select_query_sqlite
int h_select_query_sqlite(const struct _h_connection *conn, const char *query, struct _h_result *result)
h_query_delete
int h_query_delete(const struct _h_connection *conn, const char *query)
Definition: hoel.c:378
h_clean_data_full
int h_clean_data_full(struct _h_data *data)
Definition: hoel.c:460
h_last_insert_id
json_t * h_last_insert_id(const struct _h_connection *conn)
Definition: hoel-simple-json.c:662
h_insert
int h_insert(const struct _h_connection *conn, const json_t *j_query, char **generated_query)
Definition: hoel-simple-json.c:592
h_free
void h_free(void *data)
Definition: hoel.c:32
h_select
int h_select(const struct _h_connection *conn, const json_t *j_query, json_t **j_result, char **generated_query)
Definition: hoel-simple-json.c:458
h_query_insert
int h_query_insert(const struct _h_connection *conn, const char *query)
Definition: hoel.c:308
_h_type_blob::length
size_t length
Definition: hoel.h:125
_h_data
Definition: hoel.h:132
h_execute_query_pgsql
int h_execute_query_pgsql(const struct _h_connection *conn, const char *query, struct _h_result *result)
_h_type_text
Definition: hoel.h:116
_h_data::type
int type
Definition: hoel.h:133
_h_connection::type
int type
Definition: hoel.h:88
h_escape_string
char * h_escape_string(const struct _h_connection *conn, const char *unsafe)
Definition: hoel.c:72
_h_type_text::length
size_t length
Definition: hoel.h:117
_h_type_datetime::value
struct tm value
Definition: hoel.h:110
_h_result
Definition: hoel.h:140
_h_type_blob::value
void * value
Definition: hoel.h:126
_h_type_datetime
Definition: hoel.h:109
h_last_insert_id_mariadb
long long int h_last_insert_id_mariadb(const struct _h_connection *conn)
h_close_mariadb
void h_close_mariadb(struct _h_connection *conn)
Definition: hoel-mariadb.c:439
_h_result::nb_rows
unsigned int nb_rows
Definition: hoel.h:141
h_exec_query_sqlite
int h_exec_query_sqlite(const struct _h_connection *conn, const char *query)
h_escape_string_mariadb
char * h_escape_string_mariadb(const struct _h_connection *conn, const char *unsafe)
h_update
int h_update(const struct _h_connection *conn, const json_t *j_query, char **generated_query)
Definition: hoel-simple-json.c:700
_h_type_double
Definition: hoel.h:102
h_last_insert_id_sqlite
long long int h_last_insert_id_sqlite(const struct _h_connection *conn)
h_execute_query_json_mariadb
int h_execute_query_json_mariadb(const struct _h_connection *conn, const char *query, json_t **j_result)
h_execute_query_mariadb
int h_execute_query_mariadb(const struct _h_connection *conn, const char *query, struct _h_result *result)
h_delete
int h_delete(const struct _h_connection *conn, const json_t *j_query, char **generated_query)
Definition: hoel-simple-json.c:750
h_escape_string_with_quotes_mariadb
char * h_escape_string_with_quotes_mariadb(const struct _h_connection *conn, const char *unsafe)
h_clean_connection
int h_clean_connection(struct _h_connection *conn)
Definition: hoel.c:622
h_last_insert_id_pgsql
long long int h_last_insert_id_pgsql(const struct _h_connection *conn)
h_execute_query
int h_execute_query(const struct _h_connection *conn, const char *query, struct _h_result *result, int options)
Definition: hoel.c:135
h_escape_string_with_quotes
char * h_escape_string_with_quotes(const struct _h_connection *conn, const char *unsafe)
Definition: hoel.c:101
h_clean_data
int h_clean_data(struct _h_data *data)
Definition: hoel.c:439
h_query_select_json
int h_query_select_json(const struct _h_connection *conn, const char *query, json_t **j_result)
Definition: hoel.c:404
_h_result::data
struct _h_data ** data
Definition: hoel.h:143
_h_type_int
Definition: hoel.h:95
h_execute_query_json_pgsql
int h_execute_query_json_pgsql(const struct _h_connection *conn, const char *query, json_t **j_result)
_h_connection::connection
void * connection
Definition: hoel.h:89
h_query_update
int h_query_update(const struct _h_connection *conn, const char *query)
Definition: hoel.c:365
_h_connection
Definition: hoel.h:87
_h_data::t_data
void * t_data
Definition: hoel.h:134
h_escape_string_with_quotes_sqlite
char * h_escape_string_with_quotes_sqlite(const struct _h_connection *conn, const char *unsafe)
h_escape_string_with_quotes_pgsql
char * h_escape_string_with_quotes_pgsql(const struct _h_connection *conn, const char *unsafe)
_h_type_text::value
char * value
Definition: hoel.h:118
h_query_select
int h_query_select(const struct _h_connection *conn, const char *query, struct _h_result *result)
Definition: hoel.c:391
h_escape_string_pgsql
char * h_escape_string_pgsql(const struct _h_connection *conn, const char *unsafe)
h_close_pgsql
void h_close_pgsql(struct _h_connection *conn)
Definition: hoel-pgsql.c:409
h_execute_query_json
int h_execute_query_json(const struct _h_connection *conn, const char *query, json_t **j_result)
Definition: hoel.c:170
h_execute_query_json_sqlite
int h_execute_query_json_sqlite(const struct _h_connection *conn, const char *query, json_t **j_result)
h_connect_pgsql
struct _h_connection * h_connect_pgsql(const char *conninfo)
Definition: hoel-pgsql.c:403
h_escape_string_sqlite
char * h_escape_string_sqlite(const struct _h_connection *conn, const char *unsafe)
h_close_sqlite
void h_close_sqlite(struct _h_connection *conn)
Definition: hoel-sqlite.c:316
h_close_db
int h_close_db(struct _h_connection *conn)
Definition: hoel.c:40