[Debian-iot-packaging] [hoel] 01/02: Import Upstream version 1.3.1

Thorsten Alteholz alteholz at moszumanska.debian.org
Mon Mar 19 21:43:27 UTC 2018


This is an automated email from the git hooks/post-receive script.

alteholz pushed a commit to branch master
in repository hoel.

commit 67cbba3eac854d18b0e6d1b4006e41d99fa78fcb
Author: Thorsten Alteholz <debian at alteholz.de>
Date:   Mon Mar 19 22:43:18 2018 +0100

    Import Upstream version 1.3.1
---
 Makefile               |  2 +-
 README.md              | 87 ++++++++++++++++++++++++++++++++------------------
 _config.yml            |  1 +
 src/Makefile           | 11 ++++---
 src/h-private.h        |  2 +-
 src/hoel-mariadb.c     | 22 ++++++++++---
 src/hoel-pgsql.c       | 17 ++++++++--
 src/hoel-simple-json.c | 63 ++++++++++++++++++++++++++++++++----
 src/hoel-sqlite.c      | 18 +++++++++--
 src/hoel.c             | 12 +++----
 src/hoel.h             | 22 ++++++-------
 test/core.c            | 19 +++++++++++
 12 files changed, 207 insertions(+), 69 deletions(-)

diff --git a/Makefile b/Makefile
index 173dab4..9f3954c 100644
--- a/Makefile
+++ b/Makefile
@@ -32,7 +32,7 @@ clean:
 	cd $(TEST_LOCATION) && $(MAKE) clean
 
 libhoel.so:
-	cd $(LIBHOEL_LOCATION) && $(MAKE)
+	cd $(LIBHOEL_LOCATION) && $(MAKE) $(*)
 
 simple_example:
 	cd $(EXAMPLE_LOCATION) && $(MAKE)
diff --git a/README.md b/README.md
index 91b5ffd..0c36a24 100644
--- a/README.md
+++ b/README.md
@@ -6,9 +6,11 @@ Simple and easy to use database access library. Works with SQLite 3, MariaDB/Mys
 
 # Installation
 
-## Linux distribution package
+## Debian-ish distribution package
 
-Hoel is now available in Debian Buster (testing), Debian Sid, and soon in Ubuntu. To install the development package on your system, run the command as root:
+[![Packaging status](https://repology.org/badge/vertical-allrepos/hoel.svg)](https://repology.org/metapackage/hoel)
+
+Hoel is now available in Debian Buster (testing) and some Debian based distributions. To install the development package on your system, run the command as root:
 
 ```shell
 # apt install libhoel-dev
@@ -16,13 +18,13 @@ Hoel is now available in Debian Buster (testing), Debian Sid, and soon in Ubuntu
 
 ## Install from the source
 
-Clone, compile and install [Orcania](https://github.com/babelouest/orcania) and [Yder](https://github.com/babelouest/yder) librares.
+Clone, compile and install [Orcania](https://github.com/babelouest/orcania) and [Yder](https://github.com/babelouest/yder) libraries.
 
 ### Orcania (Miscellaneous functions)
 
 ```shell
 $ git clone https://github.com/babelouest/orcania.git
-$ cd orcania
+$ cd orcania/src
 $ make && sudo make install
 ```
 
@@ -30,64 +32,79 @@ $ make && sudo make install
 
 ```shell
 $ git clone https://github.com/babelouest/yder.git
-$ cd yder
+$ cd yder/src
 $ make
 $ sudo make install
 ```
 
+### Jansson
+
 Install [Jansson](http://www.digip.org/jansson/) library for JSON manipulation. On a debian-based platform, run the following command:
 
 ```shell
 $ sudo apt-get install libjansson-dev
 ```
 
+### Hoel
+
+Install Hoel dependencies:
+- SQLite3: Install the package `libsqlite3-dev`
+- MariaDB/Mysql: Install the package `libmysqlclient-dev` or `libmariadbclient-dev`
+- PostgreSQL: Install the package `libpq-dev`
+
 Download hoel from github repository.
 
 ```shell
 $ git clone https://github.com/babelouest/hoel.git
+$ cd hoel/src
+$ make
+$ sudo make install
 ```
 
-Compile hoel for the backend you need, go to hoel source folder, depending on your database backend needs, follow these instructions.
+By default, Hoel is compiled with the 3 databases support. If you don't need one or more database, follow these instructions
 
-## SQLite 3
+#### SQLite 3
 
-Install `libsqlite3-dev` and uncomment the following lines in the `src/Makefile`
+Add DISABLE_SQLITE=1 to the `make` command:
 
-```Makefile
-# HAS_SQLITE=-D_HOEL_SQLITE
-# LIBS_SQLITE=-lsqlite3
+```shell
+$ cd hoel/src
+$ make DISABLE_SQLITE=1
+$ sudo make install
 ```
 
-## MariaDB/Mysql
+#### MariaDB/Mysql
 
-Install `libmysqlclient-dev` and uncomment the following lines in the `src/Makefile`
+Add DISABLE_MARIADB=1 to the `make` command:
 
-```Makefile
-# FLAGS_MARIADB=-D_HOEL_MARIADB -I/usr/include/mysql/
-# LIBS_MYSQL=-lmysqlclient
+```shell
+$ cd hoel/src
+$ make DISABLE_MARIADB=1
+$ sudo make install
 ```
 
-## Postgre SQL
+#### Postgre SQL
 
-Install `libpq-dev` and uncomment the following lines in the `src/Makefile`
+Add DISABLE_POSTGRESQL=1 to the `make` command:
 
-```Makefile
-# HAS_PGSQL=-D_HOEL_PGSQL -I/usr/include/postgresql/
-# LIBS_PGSQL=-lpq
+```shell
+$ cd hoel/src
+$ make DISABLE_POSTGRESQL=1
+$ sudo make install
 ```
 
-### Use different backends
+### Disable 2 backends
 
-You can use different backends at the same time, simply install the required libraries and uncomment all the required backend requirements in the `src/Makefile`.
+You can disable 2 databases backends to keep just one, simply add both parameters to the `make` command:
 
-## Compile and install
-
-```
-$ cd src
-$ make
+```shell
+$ cd hoel/src
+$ make DISABLE_MARIADB=1 DISABLE_POSTGRESQL=1
 $ sudo make install
 ```
 
+### Installation folder
+
 By default, the shared library and the header file will be installed in the `/usr/local` location. To change this setting, you can modify the `PREFIX` value in the `src/Makefile`.
 
 # API Documentation
@@ -393,16 +410,24 @@ A `j_query` has the following form:
     "col1": "value1",               // Generates col1='value1'
     "col2": value_integer,          // Generates col2=value_integer
     "col3": null,                   // Generates col3=NULL
-    "col4", {                       // Generates col4<12
+    "col4": {                       // Generates col4<12
       "operator": "<",
       "value": 12
     },
-    "col5", {                       // Generates col5 IS NOT NULL
+    "col5": {                       // Generates col5 IS NOT NULL
       "operator": "NOT NULL"
     },
-    "col6", {                       // Generates col6 LIKE '%value6%'
+    "col6": {                       // Generates col6 LIKE '%value6%'
       "operator": "raw",
       "value": "LIKE '%value6%'"
+    },
+    "col7": {
+      "operator": "IN",             // Generates col7 IN ('value1',42,4.2)
+      "value": [                    // Values can be string, real or integer
+        "value1",
+        42,
+        4.2
+      ]
     }
   }
 }
diff --git a/_config.yml b/_config.yml
new file mode 100644
index 0000000..2f7efbe
--- /dev/null
+++ b/_config.yml
@@ -0,0 +1 @@
+theme: jekyll-theme-minimal
\ No newline at end of file
diff --git a/src/Makefile b/src/Makefile
index 2ec14b2..b3e5d83 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -20,23 +20,26 @@
 #
 CC=gcc
 
-# comment/uncomment these lines to disable/enable sqlite3 support
+ifndef DISABLE_SQLITE
 FLAGS_SQLITE=-D_HOEL_SQLITE
 LIBS_SQLITE=-lsqlite3
+endif
 
-# comment/uncomment these lines to disable/enable mysql/mariadb support
+ifndef DISABLE_MARIADB
 FLAGS_MARIADB=-D_HOEL_MARIADB $(shell mysql_config --cflags)
 LIBS_MARIADB=$(shell mysql_config --libs_r)
+endif
 
-# comment/uncomment these lines to disable/enable postgresql support
+ifndef DISABLE_POSTGRESQL
 FLAGS_PGSQL=-D_HOEL_PGSQL -I/usr/include/postgresql/
 LIBS_PGSQL=-lpq
+endif
 
 PREFIX=/usr/local
 CFLAGS=-c -fPIC -Wall -I$(PREFIX)/include $(FLAGS_SQLITE) $(FLAGS_MARIADB) $(FLAGS_PGSQL) -D_REENTRANT $(ADDITIONALFLAGS)
 LIBS=-L$(PREFIX)/lib -lc -ljansson -lyder -lorcania $(LIBS_SQLITE) $(LIBS_PGSQL) $(LIBS_MARIADB)
 OUTPUT=libhoel.so
-VERSION=1.2
+VERSION=1.3.1
 
 all: release
 
diff --git a/src/h-private.h b/src/h-private.h
index cad1fd8..20b19b7 100644
--- a/src/h-private.h
+++ b/src/h-private.h
@@ -56,4 +56,4 @@ struct _h_data * h_new_data_datetime(const struct tm * datetime);
  */
 struct _h_data * h_new_data_null();
 
-#endif // __H_PRIVATE_H_
+#endif /* __H_PRIVATE_H_ */
diff --git a/src/hoel-mariadb.c b/src/hoel-mariadb.c
index 86f2a1a..95175fb 100644
--- a/src/hoel-mariadb.c
+++ b/src/hoel-mariadb.c
@@ -24,7 +24,7 @@
 #include "h-private.h"
 
 #ifdef _HOEL_MARIADB
-// MariaDB library Includes
+/* MariaDB library Includes */
 #include <my_global.h>
 #include <mysql.h>
 #include <string.h>
@@ -84,11 +84,11 @@ struct _h_connection * h_connect_mariadb(const char * host, const char * user, c
       mysql_close(((struct _h_mariadb *)conn->connection)->db_handle);
       return NULL;
     } else {
-      // Set MYSQL_OPT_RECONNECT to true to reconnect automatically when connection is closed by the server (to avoid CR_SERVER_GONE_ERROR)
+      /* Set MYSQL_OPT_RECONNECT to true to reconnect automatically when connection is closed by the server (to avoid CR_SERVER_GONE_ERROR) */
       mysql_options(((struct _h_mariadb *)conn->connection)->db_handle, MYSQL_OPT_RECONNECT, &reconnect);
-      // Initialize MUTEX for connection
+      /* Initialize MUTEX for connection */
       pthread_mutexattr_init ( &mutexattr );
-      pthread_mutexattr_settype( &mutexattr, PTHREAD_MUTEX_RECURSIVE_NP );
+      pthread_mutexattr_settype( &mutexattr, PTHREAD_MUTEX_RECURSIVE );
       if (pthread_mutex_init(&(((struct _h_mariadb *)conn->connection)->lock), &mutexattr) != 0) {
         y_log_message(Y_LOG_LEVEL_ERROR, "Impossible to initialize Mutex Lock for MariaDB connection");
       }
@@ -397,4 +397,18 @@ struct _h_data * h_get_mariadb_value(const char * value, const unsigned long len
   }
   return data;
 }
+#else
+
+/**
+ * Dummy functions when Hoel is not built with 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) {
+	y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with MariaDB backend");
+	return NULL;
+}
+
+void h_close_mariadb(struct _h_connection * conn) {
+	y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with MariaDB backend");
+}
+
 #endif
diff --git a/src/hoel-pgsql.c b/src/hoel-pgsql.c
index e28e7c6..abefca5 100644
--- a/src/hoel-pgsql.c
+++ b/src/hoel-pgsql.c
@@ -24,7 +24,7 @@
 #include "h-private.h"
 
 #ifdef _HOEL_PGSQL
-// PostgreSQL library includes
+/* PostgreSQL library includes */
 #include <libpq-fe.h>
 #include <string.h>
 
@@ -49,7 +49,6 @@ struct _h_pgsql {
  * return pointer to a struct _h_connection * on sucess, NULL on error
  */
 struct _h_connection * h_connect_pgsql(char * conninfo) {
-  // TODO get oids and types
   struct _h_connection * conn = NULL;
 	struct _h_result result_types;
 	int res_types, row;
@@ -354,4 +353,18 @@ int h_last_insert_id_pgsql(const struct _h_connection * conn) {
 	PQclear(res);
 	return int_res;
 }
+#else
+
+/**
+ * Dummy functions when Hoel is not built with PostgreSQL
+ */
+struct _h_connection * h_connect_pgsql(char * conninfo) {
+	y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with PostgreSQL backend");
+	return NULL;
+}
+
+void h_close_pgsql(struct _h_connection * conn) {
+	y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with PostgreSQL backend");
+}
+
 #endif
diff --git a/src/hoel-simple-json.c b/src/hoel-simple-json.c
index cbc3820..1c52886 100644
--- a/src/hoel-simple-json.c
+++ b/src/hoel-simple-json.c
@@ -137,9 +137,10 @@ static char * h_get_insert_query_from_json_object(const struct _h_connection * c
  */
 static char * h_get_where_clause_from_json_object(const struct _h_connection * conn, const json_t * where) {
   const char * key;
-  json_t * value, * ope, * val;
-  char * where_clause = NULL, * dump = NULL, * escape = NULL, * tmp, * clause, * dump2 = NULL;
+  json_t * value, * ope, * val, * j_element;
+  char * where_clause = NULL, * dump = NULL, * escape = NULL, * tmp, * clause = NULL, * dump2 = NULL;
   int i = 0;
+  size_t index;
   
   if (conn == NULL) {
     y_log_message(Y_LOG_LEVEL_DEBUG, "Hoel/h_get_where_clause_from_json_object - Error conn is NULL");
@@ -160,7 +161,7 @@ static char * h_get_where_clause_from_json_object(const struct _h_connection * c
           if (ope == NULL ||
               !json_is_string(ope) ||
               (val == NULL && 0 != o_strcasecmp("NOT NULL", json_string_value(ope))) ||
-              (!json_is_string(val) && !json_is_real(val) && !json_is_integer(val) && 0 != o_strcasecmp("NOT NULL", json_string_value(ope)))) {
+              (!json_is_string(val) && !json_is_real(val) && !json_is_integer(val) && 0 != o_strcasecmp("NOT NULL", json_string_value(ope)) && 0 != o_strcasecmp("IN", json_string_value(ope)))) {
             dump = json_dumps(val, JSON_ENCODE_ANY);
             dump2 = json_dumps(ope, JSON_ENCODE_ANY);
             y_log_message(Y_LOG_LEVEL_DEBUG, "Hoel/h_get_where_clause_from_json_object - Error where object value is invalid: %s %s", dump, dump2);
@@ -173,6 +174,49 @@ static char * h_get_where_clause_from_json_object(const struct _h_connection * c
               clause = msprintf("%s IS NOT NULL", key);
             } else if (0 == o_strcasecmp("raw", json_string_value(ope)) && json_is_string(val)) {
               clause = msprintf("%s %s", key, json_string_value(val));
+            } else if (0 == o_strcasecmp("IN", json_string_value(ope))) {
+              if (json_is_array(val) && json_array_size(val) > 0) {
+                clause = NULL, tmp = NULL;
+                json_array_foreach(val, index, j_element) {
+                  if (!json_is_string(j_element) && !json_is_real(j_element) && !json_is_integer(j_element)) {
+                    o_free(clause);
+                    o_free(where_clause);
+                    y_log_message(Y_LOG_LEVEL_ERROR, "Hoel - Error element value in IN statement array must be real, integer or string");
+                    return NULL;
+                  } else {
+                    if (json_is_string(j_element)) {
+                      escape = h_escape_string(conn, json_string_value(j_element));
+                      if (escape == NULL) {
+                        y_log_message(Y_LOG_LEVEL_ERROR, "Hoel - Error escape");
+                        o_free(clause);
+                        o_free(where_clause);
+                        return NULL;
+                      }
+                      dump = msprintf("'%s'", escape);
+                      o_free(escape);
+                    } else if (json_is_real(j_element)) {
+                      dump = msprintf("%f", json_real_value(j_element));
+                    } else {
+                      dump = msprintf("%" JSON_INTEGER_FORMAT, json_integer_value(j_element));
+                    }
+                    if (clause == NULL) {
+                      clause = msprintf("%s IN (%s", key, dump);
+                    } else {
+                      tmp = msprintf("%s,%s", clause, dump);
+                      o_free(clause);
+                      clause = tmp;
+                    }
+                    o_free(dump);
+                  }
+                }
+                tmp = msprintf("%s)", clause);
+                o_free(clause);
+                clause = tmp;
+              } else {
+                o_free(where_clause);
+                y_log_message(Y_LOG_LEVEL_ERROR, "Hoel - Error value in IN statement must be a non empty JSON array");
+                return NULL;
+              }
             } else {
               if (json_is_real(val)) {
                 clause = msprintf("%s %s %f", key, json_string_value(ope), json_real_value(val));
@@ -182,6 +226,7 @@ static char * h_get_where_clause_from_json_object(const struct _h_connection * c
                 escape = h_escape_string(conn, json_string_value(val));
                 if (escape == NULL) {
                   y_log_message(Y_LOG_LEVEL_ERROR, "Hoel - Error escape");
+                  o_free(where_clause);
                   return NULL;
                 }
                 clause = msprintf("%s %s '%s'", key, json_string_value(ope), escape);
@@ -190,6 +235,7 @@ static char * h_get_where_clause_from_json_object(const struct _h_connection * c
             }
             if (clause == NULL) {
               y_log_message(Y_LOG_LEVEL_ERROR, "Hoel - Error allocating memory for clause");
+              o_free(where_clause);
               return NULL;
             }
           }
@@ -200,6 +246,7 @@ static char * h_get_where_clause_from_json_object(const struct _h_connection * c
             escape = h_escape_string(conn, json_string_value(value));
             if (escape == NULL) {
               y_log_message(Y_LOG_LEVEL_ERROR, "Hoel - Error escape");
+              o_free(where_clause);
               return NULL;
             }
             clause = msprintf("%s='%s'", key, escape);
@@ -215,6 +262,7 @@ static char * h_get_where_clause_from_json_object(const struct _h_connection * c
           }
           if (clause == NULL) {
             y_log_message(Y_LOG_LEVEL_ERROR, "Hoel - Error allocating memory for clause");
+            o_free(where_clause);
             return NULL;
           }
         }
@@ -223,6 +271,7 @@ static char * h_get_where_clause_from_json_object(const struct _h_connection * c
           if (where_clause == NULL) {
             y_log_message(Y_LOG_LEVEL_DEBUG, "Hoel/h_get_where_clause_from_json_object - Error where_clause");
             o_free(clause);
+            o_free(where_clause);
             return NULL;
           }
           o_free(clause);
@@ -233,6 +282,7 @@ static char * h_get_where_clause_from_json_object(const struct _h_connection * c
           if (tmp == NULL) {
             y_log_message(Y_LOG_LEVEL_DEBUG, "Hoel/h_get_where_clause_from_json_object - Error tmp where_clause");
             o_free(clause);
+            o_free(where_clause);
             return NULL;
           }
           o_free(clause);
@@ -426,7 +476,6 @@ int h_select(const struct _h_connection * conn, const json_t * j_query, json_t *
   } else {
     str_where_limit = o_strdup("");
   }
-  
   if (order_by != NULL && json_is_string(order_by)) {
     str_order_by = msprintf("ORDER BY %s", json_string_value(order_by));
   } else {
@@ -486,7 +535,7 @@ int h_insert(const struct _h_connection * conn, const json_t * j_query, char **
   int res;
   
   if (conn != NULL && j_query != NULL && json_is_object(j_query) && json_is_string(json_object_get(j_query, "table")) && (json_is_object(json_object_get(j_query, "values")) || json_is_array(json_object_get(j_query, "values")))) {
-    // Construct query
+    /* Construct query */
     table = json_string_value((const json_t *)json_object_get(j_query, "table"));
     values = json_object_get(j_query, "values");
     switch json_typeof(values) {
@@ -509,7 +558,7 @@ int h_insert(const struct _h_connection * conn, const json_t * j_query, char **
           query = h_get_insert_query_from_json_object(conn, j_row, table);
           if (query != NULL) {
             if (generated_query != NULL && index == 0) {
-              // Export just the first query
+              /* Export just the first query */
               *generated_query = o_strdup(query);
             }
             res = h_query_insert(conn, query);
@@ -546,7 +595,7 @@ json_t * h_last_insert_id(const struct _h_connection * conn) {
   json_t * j_data = NULL;
   if (conn != NULL && conn->connection != NULL) {
     if (0) {
-      // Not happening
+      /* Not happening */
 #ifdef _HOEL_SQLITE
     } else if (conn->type == HOEL_DB_TYPE_SQLITE) {
       int last_id = h_last_insert_id_sqlite(conn);
diff --git a/src/hoel-sqlite.c b/src/hoel-sqlite.c
index fc6756f..c0c2ae2 100644
--- a/src/hoel-sqlite.c
+++ b/src/hoel-sqlite.c
@@ -126,7 +126,7 @@ int h_select_query_sqlite(const struct _h_connection * conn, const char * query,
     row = 0;
     if (result != NULL) {
       row_result = sqlite3_step(stmt);
-      // Filling result object with results in array format
+      /* Filling result object with results in array format */
       result->nb_rows = 0;
       result->nb_columns = nb_columns;
       result->data = NULL;
@@ -218,7 +218,7 @@ int h_execute_query_json_sqlite(const struct _h_connection * conn, const char *
   
   if (sql_result == SQLITE_OK) {
     nb_columns = sqlite3_column_count(stmt);
-    // Filling j_result with results in json format
+    /* Filling j_result with results in json format */
     *j_result = json_array();
     if (*j_result == NULL) {
       y_log_message(Y_LOG_LEVEL_ERROR, "Hoel - Error allocating memory for *j_result");
@@ -269,4 +269,18 @@ int h_execute_query_json_sqlite(const struct _h_connection * conn, const char *
     return H_ERROR_QUERY;
   }
 }
+#else
+
+/**
+ * Dummy functions when Hoel is not built with SQLite
+ */
+struct _h_connection * h_connect_sqlite(const char * db_path) {
+	y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with SQLite backend");
+	return NULL;
+}
+
+void h_close_sqlite(struct _h_connection * conn) {
+	y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with SQLite backend");
+}
+
 #endif
diff --git a/src/hoel.c b/src/hoel.c
index 52376a4..9c01676 100644
--- a/src/hoel.c
+++ b/src/hoel.c
@@ -40,7 +40,7 @@ void h_free(void * data) {
 int h_close_db(struct _h_connection * conn) {
   if (conn != NULL && conn->connection != NULL) {
     if (0) {
-      // Not happening
+      /* Not happening */
 #ifdef _HOEL_SQLITE
     } else if (conn->type == HOEL_DB_TYPE_SQLITE) {
       h_close_sqlite(conn);
@@ -72,7 +72,7 @@ int h_close_db(struct _h_connection * conn) {
 char * h_escape_string(const struct _h_connection * conn, const char * unsafe) {
   if (conn != NULL && conn->connection != NULL && unsafe != NULL) {
     if (0) {
-      // Not happening
+      /* Not happening */
 #ifdef _HOEL_SQLITE
     } else if (conn->type == HOEL_DB_TYPE_SQLITE) {
       return h_escape_string_sqlite(conn, unsafe);
@@ -106,7 +106,7 @@ char * h_escape_string(const struct _h_connection * conn, const char * unsafe) {
 int h_execute_query(const struct _h_connection * conn, const char * query, struct _h_result * result, int options) {
   if (conn != NULL && conn->connection != NULL && query != NULL) {
     if (0) {
-      // Not happening
+      /* Not happening */
 #ifdef _HOEL_SQLITE
     } else if (conn->type == HOEL_DB_TYPE_SQLITE) {
       if (options & H_OPTION_EXEC) {
@@ -137,9 +137,9 @@ int h_execute_query(const struct _h_connection * conn, const char * query, struc
  * return H_OK on success
  */
 int h_execute_query_json(const struct _h_connection * conn, const char * query, json_t ** j_result) {
-  if (conn != NULL && conn->connection != NULL && query != NULL) {
+  if (conn != NULL && conn->connection != NULL && query != NULL && j_result != NULL) {
     if (0) {
-      // Not happening
+      /* Not happening */
 #ifdef _HOEL_SQLITE
     } else if (conn->type == HOEL_DB_TYPE_SQLITE) {
       return h_execute_query_json_sqlite(conn, query, j_result);
@@ -290,7 +290,7 @@ struct _h_data * h_query_last_insert_id(const struct _h_connection * conn) {
   struct _h_data * data = NULL;
   if (conn != NULL && conn->connection != NULL) {
     if (0) {
-      // Not happening
+      /* Not happening */
 #ifdef _HOEL_SQLITE
     } else if (conn->type == HOEL_DB_TYPE_SQLITE) {
       int last_id = h_last_insert_id_sqlite(conn);
diff --git a/src/hoel.h b/src/hoel.h
index 5f181c0..c863d5a 100644
--- a/src/hoel.h
+++ b/src/hoel.h
@@ -24,7 +24,7 @@
 #ifndef __HOEL_H__
 #define __HOEL_H__
 
-#define HOEL_VERSION 1.2
+#define HOEL_VERSION 1.3.1
 
 #include <jansson.h>
 
@@ -56,16 +56,16 @@
 #define HOEL_COL_TYPE_BOOL   5
 #define HOEL_COL_TYPE_NULL   5
 
-#define H_OK                0  // No error
-#define H_ERROR             1  // Generic error
-#define H_ERROR_PARAMS      2  // Error in input parameters
-#define H_ERROR_CONNECTION  3  // Error in database connection
-#define H_ERROR_QUERY       4  // Error executing query
-#define H_ERROR_MEMORY      99 // Error allocating memory
+#define H_OK                0  /* No error */
+#define H_ERROR             1  /* Generic error */
+#define H_ERROR_PARAMS      2  /* Error in input parameters */
+#define H_ERROR_CONNECTION  3  /* Error in database connection */
+#define H_ERROR_QUERY       4  /* Error executing query */
+#define H_ERROR_MEMORY      99 /* Error allocating memory */
 
-#define H_OPTION_NONE   0x0000 // Nothing whatsoever
-#define H_OPTION_SELECT 0x0001 // Execute a SELECT statement
-#define H_OPTION_EXEC   0x0010 // Execute an INSERT, UPDATE or DELETE statement
+#define H_OPTION_NONE   0x0000 /* Nothing whatsoever */
+#define H_OPTION_SELECT 0x0001 /* Execute a SELECT statement */
+#define H_OPTION_EXEC   0x0010 /* Execute an INSERT, UPDATE or DELETE statement */
 
 /**
  * handle container
@@ -469,4 +469,4 @@ char * h_escape_string_pgsql(const struct _h_connection * conn, const char * uns
 int h_last_insert_id_pgsql(const struct _h_connection * conn);
 #endif
 
-#endif // __HOEL_H__
+#endif /* __HOEL_H__ */
diff --git a/test/core.c b/test/core.c
index d0336ca..2fa19b0 100644
--- a/test/core.c
+++ b/test/core.c
@@ -547,6 +547,25 @@ START_TEST(test_hoel_json_select)
   json_decref(j_result);
   h_free(str_query);
   
+  str_query = NULL;
+  j_result = NULL;
+  j_query = json_pack("{sss{s{sss[ii]}}}",
+                      "table",
+                      "test_table",
+                      "where",
+                        "integer_col",
+                          "operator",
+                          "IN",
+                          "value",
+                            42,
+                            66);
+  ck_assert_int_eq(h_select(conn, j_query, &j_result, &str_query), H_OK);
+  ck_assert_int_eq(strlen(str_query), strlen("SELECT * FROM `test_table` WHERE integer_col IN (42,66)  "));
+  ck_assert_int_eq(json_array_size(j_result), 0);
+  json_decref(j_query);
+  json_decref(j_result);
+  h_free(str_query);
+  
   j_query = json_pack("{ss}",
                       "table",
                       "test_table");

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-iot/hoel.git



More information about the Debian-iot-packaging mailing list