...
 
Commits (2)
# travis configuration file
# Copyright 2018 Ilya Shipitsin <chipitsine@gmail.com>
# Nicolas Mora <mail@babelouest.org>
sudo: required
language: c
addons:
apt:
packages: [ autoconf, automake, libtool, libsqlite3-dev, libmysqlclient-dev, libpq-dev, check, libsubunit-dev, cppcheck ]
matrix:
include:
- os: linux
compiler: gcc
- os: linux
compiler: clang
- env: LABEL=cppcheck
os: linux
script:
- cppcheck --force --enable=warning,missingInclude --error-exitcode=1 . >build.log 2>&1 || (cat build.log && exit 1)
install:
- wget https://github.com/akheron/jansson/archive/v2.11.tar.gz -O jansson-2.11.tar.gz
- tar xzf jansson-2.11.tar.gz
- pushd jansson-2.11 && autoreconf -i && ./configure && make && sudo make install && popd
- rm -rf jansson-2.11
script:
- cmake -DWITH_JOURNALD=off -DBUILD_HOEL_TESTING=on .
- make
- sqlite3 /tmp/test.db < test/test.sql
- make test
# Hoel Changelog
## 1.4.4
- Add Travis CI
- Change cmake option BUILD_TESTING to BUILD_HOEL_TESTING
- Add RPM in CMake script package
## 1.4.3
- Fix memory leak
- Fix pkg-config information, add requires fields as mentionned in babelouest/ulfius#62
- Improve example_mariadb_json.c to make it more readable and understandable, clean code
- Removing the my_global.h include in hoel-mariadb.c
- Fix static library output file name babelouest/ulfius#55
## 1.4.2
- Fix Makefile soname
......
......@@ -24,14 +24,16 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
# library info
set(PROJECT_DESCRIPTION "C Database abstraction library with json based language")
set(PROJECT_HOMEPAGE_URL "https://github.com/babelouest/hoel/")
set(PROJECT_BUGREPORT_PATH "https://github.com/babelouest/hoel/issues")
set(LIBRARY_VERSION_MAJOR "1")
set(LIBRARY_VERSION_MINOR "4")
set(LIBRARY_VERSION_PATCH "2")
set(LIBRARY_VERSION_PATCH "4")
set(YDER_VERSION_DOWNLOAD "1.4.2")
set(PROJECT_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
set(LIBRARY_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
set(LIBRARY_SOVERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}")
set(YDER_VERSION_DOWNLOAD "1.3.3")
# cmake modules
......@@ -129,6 +131,18 @@ if (NOT WITH_PGSQL AND NOT WITH_MARIADB AND NOT WITH_SQLITE3)
MESSAGE(FATAL_ERROR "You must enable at least one databasse backend: Sqlite3, MariaDB/MySQL or PostgreSQL")
endif ()
set (PKGCONF_REQ "")
set (PKGCONF_REQ_PRIVATE "liborcania, libyder")
if (WITH_SQLITE3)
set (PKGCONF_REQ_PRIVATE "${PKGCONF_REQ_PRIVATE}, sqlite3")
endif ()
if (WITH_MARIADB)
set (PKGCONF_REQ_PRIVATE "${PKGCONF_REQ_PRIVATE}, mariadb")
endif ()
if (WITH_PGSQL)
set (PKGCONF_REQ_PRIVATE "${PKGCONF_REQ_PRIVATE}, libpq")
endif ()
# static library
option(BUILD_STATIC "Build static library." OFF)
......@@ -137,7 +151,7 @@ if (BUILD_STATIC)
add_library(hoel_static STATIC ${LIB_SRC})
target_compile_definitions(hoel_static PUBLIC -DO_STATIC_LIBRARY)
set_target_properties(hoel_static PROPERTIES
OUTPUT_NAME libhoel)
OUTPUT_NAME hoel)
endif ()
# shared library
......@@ -175,9 +189,9 @@ endif ()
# tests
option(BUILD_TESTING "Build the testing tree." OFF) # because we don not use include(CTest)
option(BUILD_HOEL_TESTING "Build the testing tree." OFF) # because we don not use include(CTest)
if (BUILD_TESTING)
if (BUILD_HOEL_TESTING)
include(FindCheck)
find_package(Check)
if (CHECK_FOUND)
......@@ -191,19 +205,13 @@ if (BUILD_TESTING)
set(CMAKE_CTEST_COMMAND ctest -V)
set(TST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
set(LIBS hoel ${LIBS} ${CHECK_LIBRARIES})
set(LIBS hoel yder orcania ${LIBS} ${CHECK_LIBRARIES})
if (NOT WIN32)
find_package(Threads REQUIRED)
set(LIBS ${LIBS} ${SUBUNIT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} m rt)
endif ()
set(TESTS
str_test
split_test
memory_test)
if (WITH_JANSSON)
set(TESTS ${TESTS} jansson_test)
endif ()
set(TESTS core)
configure_file(
"${CMAKE_MODULE_PATH}/CTestCustom.cmake.in"
......@@ -228,7 +236,7 @@ option(INSTALL_HEADER "Install the header files" ON) # Install hoel.h or not
configure_file(libhoel.pc.in libhoel.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libhoel.pc
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
set(TARGETS hoel)
if (BUILD_STATIC)
......@@ -279,9 +287,20 @@ endif ()
set(PACKAGE_IGNORED_FILES
"${CMAKE_CURRENT_BINARY_DIR}/;/.git/;.gitignore;~$;${CPACK_SOURCE_IGNORE_FILES}")
set(CPACK_PACKAGE_NAME "libhoel")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Database abstraction library in C")
set(CPACK_GENERATOR "TGZ;DEB")
set(CPACK_PACKAGE_VERSION_MAJOR ${LIBRARY_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${LIBRARY_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${LIBRARY_VERSION_PATCH})
option(BUILD_RPM "Build a RPM for your system" OFF)
if (BUILD_RPM)
set(CPACK_GENERATOR "TGZ;DEB;RPM")
set(CPACK_RPM_PACKAGE_LICENSE "LGPL")
set(CPACK_RPM_PACKAGE_URL "http://babelouest.github.io/hoel/")
endif ()
set(CPACK_DEBIAN_PACKAGE_NAME "libhoel")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "mail@babelouest.org")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${PROJECT_DESCRIPTION})
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/babelouest/hoel")
......
# Hoel
[![Build Status](https://travis-ci.com/babelouest/hoel.svg?branch=master)](https://travis-ci.com/babelouest/hoel)
Database abstraction library written in C.
Simple and easy to use database access library. Works with SQLite 3, MariaDB/Mysql and PostgreSQL databases. Uses a JSON-based language with `jansson` to execute simples queries based on one table.
......@@ -23,14 +25,15 @@ Install Hoel database dependencies based on your requirements:
- MariaDB/Mysql: Install the package `libmysqlclient-dev` or `libmariadbclient-dev`
- PostgreSQL: Install the package `libpq-dev`
## Debian-ish distribution package
### Distribution packages
[![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:
Hoel is available in multiple distributions as official package. Check out your distribution documentation to install the package automatically.
```shell
# apt install libhoel-dev
$ # Example for Debian testing
$ sudo apt install libhoel-dev
```
### Pre-compiled packages
......@@ -40,7 +43,7 @@ You can install Hoel with a pre-compiled package available in the [release pages
For example, to install Hoel with the `hoel-dev-full_2.3.0_Debian_stretch_x86_64.tar.gz` package downloaded on the `releases` page, you must execute the following commands:
```shell
$ sudo apt install -y libjansson-dev libmariadbclient-dev libsqlite3-dev libpq-dev
$ sudo apt install -y libjansson-dev libmariadbclient-dev libsqlite3-dev libpq-dev libsystemd-dev
$ wget https://github.com/babelouest/hoel/releases/download/v1.4.0/hoel-dev-full_1.4.0_Debian_stretch_x86_64.tar.gz
$ tar xf hoel-dev-full_1.4.0_Debian_stretch_x86_64.tar.gz
$ sudo dpkg -i liborcania-dev_1.2.0_Debian_stretch_x86_64.deb
......@@ -71,9 +74,11 @@ The available options for cmake are:
- `-DWITH_SQLITE3=[on|off]` (default `on`): Enable/disabe SQLite3 database backend
- `-DWITH_MARIADB=[on|off]` (default `on`): Enable/disabe MariaDB/Mysql database backend
- `-DWITH_PGSQL=[on|off]` (default `on`): Enable/disabe PostgreSQL database backend
- `-DWITH_JOURNALD=[on|off]` (default `on`): Build with journald (SystemD) support for logging
- `-DBUILD_STATIC=[on|off]` (default `off`): Build the static archive in addition to the shared library
- `-DBUILD_TESTING=[on|off]` (default `off`): Build unit tests
- `-DDBUILD_HOEL_TESTING=[on|off]` (default `off`): Build unit tests
- `-DINSTALL_HEADER=[on|off]` (default `on`): Install header file `hoel.h`
- `-DBUILD_RPM=[on|off]` (default `off`): Build RPM package when running `make package`
- `-DCMAKE_BUILD_TYPE=[Debug|Release]` (default `Release`): Compile with debugging symbols or not
### Good ol' Makefile
......
hoel (1.4.4-1) unstable; urgency=medium
* New upstream release
-- Nicolas Mora <nicolas@babelouest.org> Fri, 12 Oct 2018 18:27:04 -0400
hoel (1.4.2-1) unstable; urgency=medium
* New upstream release
......
......@@ -12,7 +12,7 @@ Build-Depends: debhelper (>= 11)
, libpq-dev
, libmariadbclient-dev
, cmake
Standards-Version: 4.1.3
Standards-Version: 4.2.1
Homepage: https://github.com/babelouest/hoel
Vcs-Browser: https://salsa.debian.org/debian-iot-team/oauth2/hoel.git
Vcs-Git: https://salsa.debian.org/debian-iot-team/oauth2/hoel.git
......
Description: Adapt examples for debian package
Author: Nicolas Mora <nicolas@babelouest.org>
Index: hoel-1.4.2/examples/
===================================================================
diff -ru hoel-1.4.2.orig/examples/example_mariadb.c hoel-1.4.2/examples/example_mariadb.c
--- hoel-1.4.2.orig/examples/example_mariadb.c 2018-04-12 21:50:15.000000000 -0400
+++ hoel-1.4.2/examples/example_mariadb.c 2018-04-28 14:20:51.926022256 -0400
@@ -2,7 +2,7 @@
#include <stdlib.h>
#include <jansson.h>
#define _HOEL_MARIADB
-#include "../include/hoel.h"
+#include <hoel.h>
/**
* Implementation of sprintf that return a malloc'd char * with the string construction
diff -ru hoel-1.4.2.orig/examples/example_mariadb_json.c hoel-1.4.2/examples/example_mariadb_json.c
--- hoel-1.4.2.orig/examples/example_mariadb_json.c 2018-04-12 21:50:15.000000000 -0400
+++ hoel-1.4.2/examples/example_mariadb_json.c 2018-04-28 14:20:51.976022833 -0400
@@ -2,7 +2,7 @@
#include <stdlib.h>
#include <jansson.h>
#define _HOEL_MARIADB
-#include "../include/hoel.h"
+#include <hoel.h>
void unit_tests(struct _h_connection * conn) {
json_t * j_result, * j_where, * j_array, * j_set, * j_data, * j_query;
diff -ru hoel-1.4.2.orig/examples/example_pgsql.c hoel-1.4.2/examples/example_pgsql.c
--- hoel-1.4.2.orig/examples/example_pgsql.c 2018-04-12 21:50:15.000000000 -0400
+++ hoel-1.4.2/examples/example_pgsql.c 2018-04-28 14:20:52.026023410 -0400
@@ -3,7 +3,7 @@
#include <yder.h>
#define _HOEL_PGSQL
-#include "../include/hoel.h"
+#include <hoel.h>
void print_result(struct _h_result result) {
int col, row, i;
diff -ru hoel-1.4.2.orig/examples/example_sqlite3.c hoel-1.4.2/examples/example_sqlite3.c
--- hoel-1.4.2.orig/examples/example_sqlite3.c 2018-04-12 21:50:15.000000000 -0400
+++ hoel-1.4.2/examples/example_sqlite3.c 2018-04-28 14:20:52.066023871 -0400
@@ -3,7 +3,7 @@
#include <jansson.h>
#include <yder.h>
#define _HOEL_SQLITE
-#include "../include/hoel.h"
+#include <hoel.h>
/**
* Implementation of sprintf that return a malloc'd char * with the string construction
diff -ru hoel-1.4.2.orig/examples/Makefile hoel-1.4.2/examples/Makefile
--- hoel-1.4.2.orig/examples/Makefile 2018-04-12 21:50:15.000000000 -0400
+++ hoel-1.4.2/examples/Makefile 2018-04-28 14:20:52.096024217 -0400
@@ -19,17 +19,14 @@
LIBS=-lc -lhoel -ljansson -lyder -L$(HOEL_LOCATION)
ADDITIONALFLAGS=-O3
-all: libhoel.so example_sqlite3 example_mariadb example_pgsql example_mariadb_json
+all: example_sqlite3 example_mariadb example_pgsql example_mariadb_json
clean:
rm -f *.o example_sqlite3 example_mariadb example_pgsql example_mariadb_json
debug: ADDITIONALFLAGS=-DDEBUG -g -O0
-debug: libhoel.so example_sqlite3 example_mariadb example_pgsql example_mariadb_json
-
-libhoel.so:
- cd $(HOEL_LOCATION) && $(MAKE) debug
+debug: example_sqlite3 example_mariadb example_pgsql example_mariadb_json
example_sqlite3: example_sqlite3.c
$(CC) -c $(CFLAGS) example_sqlite3.c
......@@ -14,9 +14,10 @@
# GNU GENERAL PUBLIC LICENSE for more details.
#
CC=gcc
CFLAGS=-c -Wall -D_REENTRANT -I$(PREFIX)/include $(ADDITIONALFLAGS)
HOEL_INCLUDE=../include
CFLAGS=-c -Wall -I$(HOEL_INCLUDE) -D_REENTRANT -I$(PREFIX)/include $(ADDITIONALFLAGS)
HOEL_LOCATION=../src
LIBS=-lc -lhoel -ljansson -lyder -L$(HOEL_LOCATION)
LIBS=-lc -lhoel -ljansson -lyder -lorcania -L$(HOEL_LOCATION)
ADDITIONALFLAGS=-O3
all: libhoel.so example_sqlite3 example_mariadb example_pgsql example_mariadb_json
......
......@@ -2,35 +2,13 @@
#include <stdlib.h>
#include <jansson.h>
#define _HOEL_MARIADB
#include "../include/hoel.h"
/**
* Implementation of sprintf that return a malloc'd char * with the string construction
* because life is too short to use 3 lines instead of 1
* but don't forget to free the returned value after use!
*/
char * cur_msprintf(const char * message, ...) {
va_list argp, argp_cpy;
size_t out_len = 0;
char * out = NULL;
va_start(argp, message);
va_copy(argp_cpy, argp);
out_len = vsnprintf(NULL, 0, message, argp);
out = malloc(out_len+sizeof(char));
if (out == NULL) {
return NULL;
}
vsnprintf(out, (out_len+sizeof(char)), message, argp_cpy);
va_end(argp);
va_end(argp_cpy);
return out;
}
#include <hoel.h>
void print_result(struct _h_result result) {
int col, row;
char buf[64];
int i;
printf("rows: %d, col: %d\n", result.nb_rows, result.nb_columns);
printf("rows: %u, col: %u\n", result.nb_rows, result.nb_columns);
for (row = 0; row<result.nb_rows; row++) {
for (col=0; col<result.nb_columns; col++) {
switch(result.data[row][col].type) {
......@@ -70,7 +48,8 @@ void unit_tests(struct _h_connection * conn) {
char * query = NULL, * sanitized = NULL, * dump, * table = "other_test";
int last_id = -1;
query = cur_msprintf("select * from %s", table);
// Execute a sql query and retrieve results in a json structure
query = msprintf("select * from %s", table);
if (h_query_select_json(conn, query, &j_result) == H_OK) {
dump = json_dumps(j_result, JSON_INDENT(2));
printf("json result is\n%s\n", dump);
......@@ -81,13 +60,14 @@ void unit_tests(struct _h_connection * conn) {
}
free(query);
// insert escaped string
sanitized = h_escape_string(conn, "Hodor son of H'rtp'ss");
query = cur_msprintf("insert into %s (name, age, temperature, birthdate) values ('%s', %d, %f, '%s')", table, sanitized, 33, 37.2, "1412-03-08 12:00:22");
query = msprintf("insert into %s (name, age, temperature, birthdate) values ('%s', %d, %f, '%s')", table, sanitized, 33, 37.2, "1412-03-08 12:00:22");
printf("insert result: %d\n", h_query_insert(conn, query));
free(sanitized);
free(query);
query = cur_msprintf("select * from %s", table);
query = msprintf("select * from %s", table);
if (h_query_select(conn, query, &result) == H_OK) {
print_result(result);
h_clean_result(&result);
......@@ -97,13 +77,12 @@ void unit_tests(struct _h_connection * conn) {
free(query);
sanitized = h_escape_string(conn, "Ygritte you know nothing");
query = cur_msprintf("insert into %s (name, age, temperature, birthdate) values ('%s', %d, %f, '%s')", table, sanitized, 25, 30.1, "1424-06-01 03:05:11");
query = msprintf("insert into %s (name, age, temperature, birthdate) values ('%s', %d, %f, '%s')", table, sanitized, 25, 30.1, "1424-06-01 03:05:11");
printf("insert result: %d\n", h_query_insert(conn, query));
printf("COIN COIN COIN\n");
free(sanitized);
free(query);
query = cur_msprintf("select * from %s", table);
query = msprintf("select * from %s", table);
if (h_query_select(conn, query, &result) == H_OK) {
print_result(result);
h_clean_result(&result);
......@@ -113,7 +92,7 @@ void unit_tests(struct _h_connection * conn) {
free(query);
sanitized = h_escape_string(conn, "Littlefinger I will betray you");
query = cur_msprintf("insert into %s (name, age, temperature, birthdate) values ('%s', %d, %f, '%s')", table, sanitized, 44, 40.5, "1410-10-25 14:30:00");
query = msprintf("insert into %s (name, age, temperature, birthdate) values ('%s', %d, %f, '%s')", table, sanitized, 44, 40.5, "1410-10-25 14:30:00");
printf("insert result: %d\n", h_query_insert(conn, query));
free(sanitized);
free(query);
......@@ -124,7 +103,7 @@ void unit_tests(struct _h_connection * conn) {
h_clean_data_full(data);
printf("last id is %d\n", last_id);
query = cur_msprintf("select * from %s", table);
query = msprintf("select * from %s", table);
if (h_query_select(conn, query, &result) == H_OK) {
print_result(result);
h_clean_result(&result);
......@@ -134,12 +113,12 @@ void unit_tests(struct _h_connection * conn) {
free(query);
sanitized = h_escape_string(conn, "Littlefinger I am nothing");
query = cur_msprintf("update %s set name='%s' where id=%d", table, sanitized, last_id);
query = msprintf("update %s set name='%s' where id=%d", table, sanitized, last_id);
printf("update result: %d\n", h_query_update(conn, query));
free(sanitized);
free(query);
query = cur_msprintf("select * from %s", table);
query = msprintf("select * from %s", table);
if (h_query_select(conn, query, &result) == H_OK) {
print_result(result);
h_clean_result(&result);
......@@ -148,11 +127,11 @@ void unit_tests(struct _h_connection * conn) {
}
free(query);
query = cur_msprintf("delete from %s where id=%d", table, last_id);
query = msprintf("delete from %s where id=%d", table, last_id);
printf("delete result: %d\n", h_query_delete(conn, query));
free(query);
query = cur_msprintf("select * from %s", table);
query = msprintf("select * from %s", table);
if (h_query_select_json(conn, query, &j_result) == H_OK) {
dump = json_dumps(j_result, JSON_INDENT(2));
printf("json result is\n%s\n", dump);
......
DROP TABLE IF EXISTS other_test;
CREATE TABLE other_test (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(128),
age INTEGER,
birthdate DATE,
temperature FLOAT
);
This diff is collapsed.
......@@ -3,7 +3,7 @@
#include <yder.h>
#define _HOEL_PGSQL
#include "../include/hoel.h"
#include <hoel.h>
void print_result(struct _h_result result) {
int col, row, i;
......
......@@ -3,33 +3,11 @@
#include <jansson.h>
#include <yder.h>
#define _HOEL_SQLITE
#include "../include/hoel.h"
/**
* Implementation of sprintf that return a malloc'd char * with the string construction
* because life is too short to use 3 lines instead of 1
* but don't forget to free the returned value after use!
*/
char * msprintf(const char * message, ...) {
va_list argp, argp_cpy;
size_t out_len = 0;
char * out = NULL;
va_start(argp, message);
va_copy(argp_cpy, argp);
out_len = vsnprintf(NULL, 0, message, argp);
out = malloc(out_len+sizeof(char));
if (out == NULL) {
return NULL;
}
vsnprintf(out, (out_len+sizeof(char)), message, argp_cpy);
va_end(argp);
va_end(argp_cpy);
return out;
}
#include <hoel.h>
void print_result(struct _h_result result) {
int col, row, i;
printf("rows: %d, col: %d\n", result.nb_rows, result.nb_columns);
printf("rows: %u, col: %u\n", result.nb_rows, result.nb_columns);
for (row = 0; row<result.nb_rows; row++) {
for (col=0; col<result.nb_columns; col++) {
switch(result.data[row][col].type) {
......
......@@ -24,7 +24,7 @@
#ifndef __HOEL_H__
#define __HOEL_H__
#define HOEL_VERSION 1.4.2
#define HOEL_VERSION 1.4.4
#include <jansson.h>
......
......@@ -7,5 +7,7 @@ Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
URL: @PROJECT_BUGREPORT_PATH@
Version: @LIBRARY_VERSION@
Requires: @PKGCONF_REQ@
Requires.private: @PKGCONF_REQ_PRIVATE@
Libs: -L${libdir} -lhoel
Cflags: -I${includedir}
......@@ -35,11 +35,12 @@ FLAGS_PGSQL=-D_HOEL_PGSQL -I/usr/include/postgresql/
LIBS_PGSQL=-lpq
endif
HOEL_INCLUDE=../include
DESTDIR=/usr/local
CFLAGS+=-c -fPIC -Wall -I$(DESTDIR)/include $(FLAGS_SQLITE) $(FLAGS_MARIADB) $(FLAGS_PGSQL) -D_REENTRANT $(ADDITIONALFLAGS) $(CPPFLAGS)
CFLAGS+=-c -fPIC -Wall -I$(HOEL_INCLUDE) -I$(DESTDIR)/include $(FLAGS_SQLITE) $(FLAGS_MARIADB) $(FLAGS_PGSQL) -D_REENTRANT $(ADDITIONALFLAGS) $(CPPFLAGS)
LIBS=-L$(DESTDIR)/lib -lc -ljansson -lyder -lorcania $(LIBS_SQLITE) $(LIBS_PGSQL) $(LIBS_MARIADB)
OUTPUT=libhoel.so
VERSION=1.4.2
VERSION=1.4.4
all: release
......@@ -50,19 +51,19 @@ libhoel.so: hoel-sqlite.o hoel-mariadb.o hoel-pgsql.o hoel-simple-json.o hoel.o
libhoel.a: hoel-sqlite.o hoel-mariadb.o hoel-pgsql.o hoel-simple-json.o hoel.o
ar rcs libhoel.a hoel-sqlite.o hoel-mariadb.o hoel-pgsql.o hoel-simple-json.o hoel.o
hoel.o: hoel.c ../include/hoel.h
hoel.o: hoel.c $(HOEL_INCLUDE)/hoel.h
$(CC) $(CFLAGS) hoel.c
hoel-sqlite.o: hoel-sqlite.c ../include/hoel.h
hoel-sqlite.o: hoel-sqlite.c $(HOEL_INCLUDE)/hoel.h
$(CC) $(CFLAGS) hoel-sqlite.c
hoel-mariadb.o: hoel-mariadb.c ../include/hoel.h
hoel-mariadb.o: hoel-mariadb.c $(HOEL_INCLUDE)/hoel.h
$(CC) $(CFLAGS) hoel-mariadb.c
hoel-pgsql.o: hoel-pgsql.c ../include/hoel.h
hoel-pgsql.o: hoel-pgsql.c $(HOEL_INCLUDE)/hoel.h
$(CC) $(CFLAGS) hoel-pgsql.c
hoel-simple-json.o: hoel-simple-json.c ../include/hoel.h
hoel-simple-json.o: hoel-simple-json.c $(HOEL_INCLUDE)/hoel.h
$(CC) $(CFLAGS) hoel-simple-json.c
clean:
......@@ -70,12 +71,12 @@ clean:
install: all
cp $(OUTPUT).$(VERSION) $(DESTDIR)/lib
cp ../include/hoel.h $(DESTDIR)/include
cp $(HOEL_INCLUDE)/hoel.h $(DESTDIR)/include
/sbin/ldconfig
static-install: static
cp libhoel.a $(DESTDIR)/lib
cp ../include/hoel.h $(DESTDIR)/include
cp $(HOEL_INCLUDE)/hoel.h $(DESTDIR)/include
uninstall:
rm -f $(DESTDIR)/lib/$(OUTPUT) $(DESTDIR)/lib/libhoel.a
......
......@@ -20,12 +20,11 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "../include/hoel.h"
#include "../include/h-private.h"
#include "hoel.h"
#include "h-private.h"
#ifdef _HOEL_MARIADB
/* MariaDB library Includes */
#include <my_global.h>
#include <mysql.h>
#include <string.h>
......@@ -70,11 +69,13 @@ struct _h_connection * h_connect_mariadb(const char * host, const char * user, c
}
if (mysql_library_init(0, NULL, NULL)) {
y_log_message(Y_LOG_LEVEL_ERROR, "mysql_library_init error, aborting");
free(conn);
return NULL;
}
((struct _h_mariadb *)conn->connection)->db_handle = mysql_init(NULL);
if (((struct _h_mariadb *)conn->connection)->db_handle == NULL) {
y_log_message(Y_LOG_LEVEL_ERROR, "mysql_init error, aborting");
free(conn);
return NULL;
}
if (mysql_real_connect(((struct _h_mariadb *)conn->connection)->db_handle,
......@@ -82,6 +83,7 @@ struct _h_connection * h_connect_mariadb(const char * host, const char * user, c
y_log_message(Y_LOG_LEVEL_ERROR, "Error connecting to mariadb database %s", db);
y_log_message(Y_LOG_LEVEL_DEBUG, "Error message: \"%s\"", mysql_error(((struct _h_mariadb *)conn->connection)->db_handle));
mysql_close(((struct _h_mariadb *)conn->connection)->db_handle);
free(conn);
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) */
......
......@@ -20,8 +20,8 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "../include/hoel.h"
#include "../include/h-private.h"
#include "hoel.h"
#include "h-private.h"
#ifdef _HOEL_PGSQL
/* PostgreSQL library includes */
......
......@@ -24,13 +24,13 @@
#include <string.h>
#include <ctype.h>
#include "../include/hoel.h"
#include "../include/h-private.h"
#include "hoel.h"
#include "h-private.h"
static char * h_get_insert_values_from_json_object(const struct _h_connection * conn, json_t * data) {
char * new_data = NULL, * escape, * insert_data = NULL, * tmp;
const char * key;
json_t * value, * raw;
const char * key = NULL;
json_t * value = NULL, * raw;
int i = 0;
json_object_foreach((json_t *)data, key, value) {
......@@ -110,8 +110,8 @@ static char * h_get_insert_values_from_json_object(const struct _h_connection *
static char * h_get_insert_columns_from_json_object(json_t * data) {
char * insert_cols = NULL, * tmp;
const char * key;
json_t * value;
const char * key = NULL;
json_t * value = NULL;
int i = 0;
json_object_foreach((json_t *)data, key, value) {
......@@ -163,8 +163,8 @@ static char * h_get_insert_query_from_json_object(const struct _h_connection * c
* Returned value must be o_free'd after use
*/
static char * h_get_insert_query_from_json_array(const struct _h_connection * conn, json_t * j_array, const char * table) {
json_t * j_row;
size_t index;
json_t * j_row = NULL;
size_t index = 0;
char * to_return = NULL, * insert_cols, * insert_data, * tmp;
json_array_foreach(j_array, index, j_row) {
......@@ -206,11 +206,11 @@ static char * h_get_insert_query_from_json_array(const struct _h_connection * co
* the returned value must be o_free'd after use
*/
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, * j_element;
const char * key = NULL;
json_t * value = NULL, * ope, * val, * j_element;
char * where_clause = NULL, * dump = NULL, * escape = NULL, * tmp, * clause = NULL, * dump2 = NULL;
int i = 0;
size_t index;
size_t index = 0;
if (conn == NULL) {
y_log_message(Y_LOG_LEVEL_DEBUG, "Hoel/h_get_where_clause_from_json_object - Error conn is NULL");
......@@ -377,8 +377,8 @@ static char * h_get_where_clause_from_json_object(const struct _h_connection * c
* the returned value must be o_free'd after use
*/
static char * h_get_set_clause_from_json_object(const struct _h_connection * conn, const json_t * set) {
const char * key;
json_t * value, * raw;
const char * key = NULL;
json_t * value = NULL, * raw;
char * where_clause = NULL, * escape = NULL, * tmp;
int i = 0;
......@@ -461,7 +461,7 @@ int h_select(const struct _h_connection * conn, const json_t * j_query, json_t *
json_int_t limit, offset;
char * query, * columns = NULL, * where_clause = NULL, * tmp, * str_where_limit, * str_order_by;
const char * col;
size_t index;
size_t index = 0;
json_t * value;
int res;
......@@ -607,7 +607,7 @@ int h_insert(const struct _h_connection * conn, const json_t * j_query, char **
/* 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) {
switch (json_typeof(values)) {
case JSON_OBJECT:
query = h_get_insert_query_from_json_object(conn, values, table);
if (query != NULL) {
......
......@@ -20,8 +20,8 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "../include/hoel.h"
#include "../include/h-private.h"
#include "hoel.h"
#include "h-private.h"
#ifdef _HOEL_SQLITE
......
......@@ -23,8 +23,8 @@
#include <ctype.h>
#include <string.h>
#include "../include/hoel.h"
#include "../include/h-private.h"
#include "hoel.h"
#include "h-private.h"
/**
* free data allocated by hoel functions
......
......@@ -19,8 +19,9 @@
# License along with this program. If not, see <http://www.gnu.org/licenses/>.
#
HOEL_INCLUDE=../include
CC=gcc
CFLAGS=-Wall -D_REENTRANT -DDEBUG -g -O0
CFLAGS=-Wall -I$(HOEL_INCLUDE) -D_REENTRANT -DDEBUG -g -O0
HOEL_LOCATION=../src
LIBS=-lc -lyder -lhoel -ljansson -lcheck -lpthread -lm -lrt -lsubunit -L$(HOEL_LOCATION)
......
......@@ -9,8 +9,10 @@
#include <jansson.h>
#include <check.h>
#define _HOEL_SQLITE
#include "../src/hoel.h"
#ifndef _HOEL_SQLITE
#define _HOEL_SQLITE
#endif
#include "hoel.h"
#define DEFAULT_BD_PATH "/tmp/test.db"
#define WRONG_BD_PATH "nope.db"
......@@ -37,7 +39,7 @@ const char * db_path;
void print_result(struct _h_result result) {
int col, row, i;
printf("rows: %d, col: %d\n", result.nb_rows, result.nb_columns);
printf("rows: %u, col: %u\n", result.nb_rows, result.nb_columns);
for (row = 0; row<result.nb_rows; row++) {
for (col=0; col<result.nb_columns; col++) {
switch(result.data[row][col].type) {
......