Commit cf63943e authored by Nicolas Mora's avatar Nicolas Mora

New upstream version 1.4.8

parent 08adb2f7
......@@ -8,3 +8,4 @@ example_mariadb_json
example_multi_mariadb
core
valgrind.txt
hoel-cfg.h
......@@ -26,7 +26,36 @@ install:
- rm -rf jansson-2.11
script:
- cmake -DWITH_JOURNALD=off -DBUILD_HOEL_TESTING=on .
- mkdir build && cd build
- cmake -DWITH_JOURNALD=off -DBUILD_HOEL_TESTING=on ..
- make
- sqlite3 /tmp/test.db < ../test/test.sql
- make test package
- sudo make install
- rm -rf * && cmake -DWITH_JOURNALD=OFF -DWITH_SQLITE3=off -DWITH_MARIADB=off -DWITH_PGSQL=on ..
- make package
- rm -rf * && cmake -DWITH_JOURNALD=OFF -DWITH_SQLITE3=off -DWITH_MARIADB=on -DWITH_PGSQL=off ..
- make package
- rm -rf * && cmake -DWITH_JOURNALD=OFF -DWITH_SQLITE3=off -DWITH_MARIADB=on -DWITH_PGSQL=on ..
- make package
- rm -rf * && cmake -DWITH_JOURNALD=OFF -DWITH_SQLITE3=on -DWITH_MARIADB=off -DWITH_PGSQL=off ..
- make package
- rm -rf * && cmake -DWITH_JOURNALD=OFF -DWITH_SQLITE3=on -DWITH_MARIADB=off -DWITH_PGSQL=on ..
- make package
- rm -rf * && cmake -DWITH_JOURNALD=OFF -DWITH_SQLITE3=on -DWITH_MARIADB=on -DWITH_PGSQL=off ..
- make package
- rm -rf * && cmake -DWITH_JOURNALD=OFF -DWITH_SQLITE3=on -DWITH_MARIADB=on -DWITH_PGSQL=on ..
- make package
- rm -rf *
- if $(cmake -DWITH_JOURNALD=OFF -DWITH_SQLITE3=off -DWITH_MARIADB=off -DWITH_PGSQL=off .. 1>/dev/null 2&>1); then echo "Build with no DB fail" && exit 1; else echo "Build with no DB success"; fi
- cd ../
- make clean debug
- make clean debug DISABLE_SQLITE=1 DISABLE_MARIADB=1
- make clean debug DISABLE_SQLITE=1 DISABLE_POSTGRESQL=1
- make clean debug DISABLE_SQLITE=1
- make clean debug DISABLE_MARIADB=1 DISABLE_POSTGRESQL=1
- make clean debug DISABLE_MARIADB=1
- make clean debug DISABLE_POSTGRESQL=1
- if $(make clean debug DISABLE_SQLITE=1 DISABLE_MARIADB=1 DISABLE_POSTGRESQL=1 1>/dev/null 2&>1); then echo "Build with no DB fail" && exit 1; else echo "Build with no DB success"; fi
- sqlite3 /tmp/test.db < test/test.sql
- make test
- make clean check
# Hoel Changelog
## 1.4.8
- Fix mariadb bug when empty column was returned as NULL
## 1.4.7
- Add support for binary columns in `struct _h_data` by adding length parameter in `struct _h_type_text`
- Code cleaning and bug fixes thanks to clang static analyzer
## 1.4.6
- CMake scripts improvements
## 1.4.5
- Add config file hoel-cfg.h dynamically built with the options
- Improve CI
## 1.4.4
- Add Travis CI
......
......@@ -28,8 +28,9 @@ 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 "4")
set(YDER_VERSION_DOWNLOAD "1.4.2")
set(LIBRARY_VERSION_PATCH "8")
set(ORCANIA_VERSION_DOWNLOAD "1.2.9")
set(YDER_VERSION_DOWNLOAD "1.4.4")
set(PROJECT_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
set(LIBRARY_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
......@@ -45,16 +46,16 @@ include(CheckSymbolExists)
# check if _GNU_SOURCE is available
if (NOT _GNU_SOURCE)
check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)
check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)
if (NOT _GNU_SOURCE)
unset(_GNU_SOURCE CACHE)
check_symbol_exists(_GNU_SOURCE "features.h" _GNU_SOURCE)
endif ()
if (NOT _GNU_SOURCE)
unset(_GNU_SOURCE CACHE)
check_symbol_exists(_GNU_SOURCE "features.h" _GNU_SOURCE)
endif ()
endif ()
if (_GNU_SOURCE)
add_definitions(-D_GNU_SOURCE)
add_definitions(-D_GNU_SOURCE)
endif ()
# directories and source
......@@ -65,13 +66,13 @@ set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories(${INC_DIR})
set(LIB_SRC
${INC_DIR}/hoel.h
${INC_DIR}/h-private.h
${SRC_DIR}/hoel-simple-json.c
${SRC_DIR}/hoel-mariadb.c
${SRC_DIR}/hoel-pgsql.c
${SRC_DIR}/hoel-sqlite.c
${SRC_DIR}/hoel.c)
${INC_DIR}/hoel.h
${INC_DIR}/h-private.h
${SRC_DIR}/hoel-simple-json.c
${SRC_DIR}/hoel-mariadb.c
${SRC_DIR}/hoel-pgsql.c
${SRC_DIR}/hoel-sqlite.c
${SRC_DIR}/hoel.c)
# dependencies
......@@ -79,54 +80,68 @@ include(FindJansson)
set(JANSSON_MIN_VERSION 2.4)
find_package(Jansson ${JANSSON_MIN_VERSION} REQUIRED)
if (JANSSON_FOUND)
set(LIBS ${JANSSON_LIBRARIES})
set(LIBS ${JANSSON_LIBRARIES})
endif ()
option(WITH_SQLITE3 "Use SQLite3 library" ON)
if (WITH_SQLITE3)
include(FindSQLite3)
find_package(SQLite3 REQUIRED)
if (SQLITE3_FOUND)
set(LIBS ${LIBS} ${SQLITE3_LIBRARIES})
add_definitions(-D_HOEL_SQLITE)
include_directories(${SQLITE3_INCLUDE_DIR})
set(LIBS ${LIBS} ${SQLITE3_LIBRARIES})
include(FindSQLite3)
find_package(SQLite3 REQUIRED)
if (SQLITE3_FOUND)
set(LIBS ${LIBS} ${SQLITE3_LIBRARIES})
include_directories(${SQLITE3_INCLUDE_DIR})
set(LIBS ${LIBS} ${SQLITE3_LIBRARIES})
set(_HOEL_SQLITE ON)
else ()
message("SQLite3 not found")
endif ()
message("SQLite3 not found")
set(_HOEL_SQLITE OFF)
endif ()
else ()
set(_HOEL_SQLITE OFF)
endif ()
option(WITH_MARIADB "Use MariaDB/MySQL library" ON)
if (WITH_MARIADB)
include(FindMYSQL)
find_package(MYSQL REQUIRED)
if (MYSQL_FOUND)
set(LIBS ${LIBS} ${MYSQL_LIBRARIES})
add_definitions(-D_HOEL_MARIADB)
include_directories(${MYSQL_INCLUDE_DIRS})
set(LIBS ${LIBS} ${MYSQL_LIBRARIES})
include(FindMYSQL)
find_package(MYSQL REQUIRED)
if (MYSQL_FOUND)
set(LIBS ${LIBS} ${MYSQL_LIBRARIES})
include_directories(${MYSQL_INCLUDE_DIRS})
set(LIBS ${LIBS} ${MYSQL_LIBRARIES})
set(_HOEL_MARIADB ON)
else ()
message("MariaDB not found")
endif ()
message("MariaDB not found")
set(_HOEL_MARIADB OFF)
endif ()
else ()
set(_HOEL_MARIADB OFF)
endif ()
option(WITH_PGSQL "Use PostgreSQL library" ON)
if (WITH_PGSQL)
include(FindLibPQ)
find_package(LibPQ REQUIRED)
find_package(LibPQ REQUIRED)
if(LIBPQ_FOUND)
set(LIBS ${LIBS} ${LIBPQ_LIBRARIES})
add_definitions(-D_HOEL_PGSQL)
include_directories(${LIBPQ_INCLUDE_DIRS})
set(LIBS ${LIBS} ${LIBPQ_LIBRARIES})
set(LIBS ${LIBS} ${LIBPQ_LIBRARIES})
include_directories(${LIBPQ_INCLUDE_DIRS})
set(LIBS ${LIBS} ${LIBPQ_LIBRARIES})
set(_HOEL_PGSQL ON)
else ()
message("LibPQ not found")
message("LibPQ not found")
set(_HOEL_PGSQL OFF)
endif()
else ()
set(_HOEL_PGSQL OFF)
endif ()
# build hoel-cfg.h file
configure_file(${INC_DIR}/hoel-cfg.h.in ${PROJECT_BINARY_DIR}/hoel-cfg.h)
set (CMAKE_EXTRA_INCLUDE_FILES ${PROJECT_BINARY_DIR})
include_directories(${PROJECT_BINARY_DIR})
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 ()
......@@ -159,7 +174,7 @@ endif ()
add_library(hoel SHARED ${LIB_SRC})
set_target_properties(hoel PROPERTIES
COMPILE_OPTIONS -Wextra
PUBLIC_HEADER ${INC_DIR}/hoel.h
PUBLIC_HEADER "${INC_DIR}/hoel.h;${PROJECT_BINARY_DIR}/hoel-cfg.h"
VERSION "${LIBRARY_VERSION}"
SOVERSION "${LIBRARY_SOVERSION}")
if (WIN32)
......@@ -167,24 +182,53 @@ if (WIN32)
endif ()
target_link_libraries(hoel ${LIBS})
option(CHECK_YDER "Check Yder library." ON)
if (CHECK_YDER)
set(Yder_FIND_QUIETLY ON) # force to find Yder quietly
include(FindYder)
find_package(Yder 1.1 QUIET) # try to find Yder
if (NOT YDER_FOUND)
include(DownloadProject)
download_project(PROJ yder # ... otherwise, download archive
URL "https://github.com/babelouest/yder/archive/v${YDER_VERSION_DOWNLOAD}.tar.gz"
QUIET)
add_subdirectory(${yder_SOURCE_DIR} ${yder_BINARY_DIR})
include_directories(${yder_SOURCE_DIR}/include)
include_directories(${orcania_SOURCE_DIR}/include)
add_dependencies(hoel yder)
add_dependencies(hoel orcania)
set(HOEL_LIBRARIES yder orcania)
endif ()
# dependencies
option(SEARCH_ORCANIA_H "Search for Orcania library" ON)
if (SEARCH_ORCANIA_H)
set(Orcania_FIND_QUIETLY ON) # force to find Orcania quietly
include(FindOrcania)
find_package(Orcania 1.1 QUIET) # try to find orcania
if (NOT ORCANIA_FOUND)
include(DownloadProject)
download_project(PROJ orcania # ... otherwise, download archive
URL "https://github.com/babelouest/orcania/archive/v${ORCANIA_VERSION_DOWNLOAD}.tar.gz"
QUIET)
add_subdirectory(${orcania_SOURCE_DIR} ${orcania_BINARY_DIR})
include_directories(${orcania_SOURCE_DIR}/include)
add_dependencies(hoel orcania)
set(ORCANIA_LIBRARIES orcania)
set(LIBS ${LIBS} ${ORCANIA_LIBRARIES})
include_directories(${orcania_BINARY_DIR})
else()
set(LIBS ${LIBS} ${ORCANIA_LIBRARIES})
include_directories(${ORCANIA_INCLUDE_DIRS})
endif ()
target_link_libraries(hoel ${LIBS} ${ORCANIA_LIBRARIES})
endif ()
set(SEARCH_ORCANIA OFF CACHE BOOL "Force to false") # Avoid to search and download orcania during yder search and download
option(SEARCH_YDER "Search for Yder library" ON)
if (SEARCH_YDER)
set(Yder_FIND_QUIETLY ON) # force to find Yder quietly
include(FindYder)
find_package(Yder 1.1 QUIET) # try to find Yder
if (NOT YDER_FOUND)
include(DownloadProject)
download_project(PROJ yder # ... otherwise, download archive
URL "https://github.com/babelouest/yder/archive/v${YDER_VERSION_DOWNLOAD}.tar.gz"
QUIET)
add_subdirectory(${yder_SOURCE_DIR} ${yder_BINARY_DIR})
include_directories(${yder_SOURCE_DIR}/include)
add_dependencies(hoel yder)
set(YDER_LIBRARIES yder orcania)
include_directories(${yder_BINARY_DIR})
else()
set(LIBS ${LIBS} ${YDER_LIBRARIES})
include_directories(${YDER_INCLUDE_DIRS})
endif ()
target_link_libraries(hoel ${LIBS} ${YDER_LIBRARIES})
endif ()
# tests
......@@ -307,15 +351,15 @@ set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/babelouest/hoel")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.14), libjansson4 (>= 2.4), liborcania (>= 1.2), libyder (>= 1.3), zlib1g (>= 1:1.1.4)")
if (WITH_SQLITE3)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libsqlite3-0 (>= 3.5.9)")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libsqlite3-0 (>= 3.5.9)")
endif ()
if (WITH_MARIADB)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libmariadbclient18 (>= 5.5.36)")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libmariadbclient18 (>= 5.5.36)")
endif ()
if (WITH_PGSQL)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libpq5 (>= 9.0~)")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libpq5 (>= 9.0~)")
endif ()
set(CPACK_PACKAGE_FILE_NAME ${PACKAGE_FILE_NAME})
......@@ -328,3 +372,11 @@ include(CPack)
add_custom_target(dist_h
COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
message(STATUS "SQLITE3 library support: ${WITH_SQLITE3}")
message(STATUS "MariaDB library support: ${WITH_MARIADB}")
message(STATUS "PostgreSQL library support: ${WITH_PGSQL}")
message(STATUS "Build static library: ${BUILD_STATIC}")
message(STATUS "Build testing tree: ${BUILD_ULFIUS_TESTING}")
message(STATUS "Install the header files: ${INSTALL_HEADER}")
message(STATUS "Build RPM package: ${BUILD_RPM}")
......@@ -18,34 +18,33 @@ LIBHOEL_LOCATION=./src
EXAMPLE_LOCATION=./examples
TEST_LOCATION=./test
.NOTPARALLEL:
all: libhoel.so example_sqlite3 example_mariadb example_pgsql
all: release
debug:
cd $(EXAMPLE_LOCATION) && $(MAKE) debug
cd $(LIBHOEL_LOCATION) && $(MAKE) debug $*
install:
cd $(EXAMPLE_LOCATION) && $(MAKE) install
cd $(EXAMPLE_LOCATION) && $(MAKE) install $*
clean:
cd $(LIBHOEL_LOCATION) && $(MAKE) clean
cd $(EXAMPLE_LOCATION) && $(MAKE) clean
cd $(TEST_LOCATION) && $(MAKE) clean
libhoel.so:
cd $(LIBHOEL_LOCATION) && $(MAKE) $(*)
release:
cd $(LIBHOEL_LOCATION) && $(MAKE) $*
simple_example:
cd $(EXAMPLE_LOCATION) && $(MAKE)
cd $(EXAMPLE_LOCATION) && $(MAKE) $*
example_sqlite3:
cd $(EXAMPLE_LOCATION) && $(MAKE) example_sqlite3
cd $(EXAMPLE_LOCATION) && $(MAKE) example_sqlite3 $*
example_mariadb:
cd $(EXAMPLE_LOCATION) && $(MAKE) example_mariadb
cd $(EXAMPLE_LOCATION) && $(MAKE) example_mariadb $*
example_pgsql:
cd $(EXAMPLE_LOCATION) && $(MAKE) example_pgsql
cd $(EXAMPLE_LOCATION) && $(MAKE) example_pgsql $*
test:
cd $(TEST_LOCATION) && $(MAKE) test
check:
cd $(TEST_LOCATION) && $(MAKE) test $*
......@@ -163,19 +163,9 @@ By default, the shared library and the header file will be installed in the `/us
## Header files and compilation
To use hoel in your code, you must use the `#define` corresponding to the backend you use before including the file `hoel.h`. For example:
To use hoel in your code, include the file `hoel.h`.
```c
#define _HOEL_SQLITE
#include <hoel.h>
```
If you want to use different backends in your source code, just add its `#define` before including `hoel.h`.
```c
#define _HOEL_SQLITE
#define _HOEL_MARIADB
#define _HOEL_PGSQL
#include <hoel.h>
```
......
#.rst:
# FindOrcania
# -----------
#
# Find Orcania
#
# Find Orcania headers and libraries.
#
# ::
#
# ORCANIA_FOUND - True if Orcania found.
# ORCANIA_INCLUDE_DIRS - Where to find orcania.h.
# ORCANIA_LIBRARIES - List of libraries when using Orcania.
# ORCANIA_VERSION_STRING - The version of Orcania found.
#=============================================================================
# Copyright 2018 Silvio Clecio <silvioprog@gmail.com>
# Copyright 2018 Nicolas Mora <mail@babelouest.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation;
# version 2.1 of the License.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
#=============================================================================
find_package(PkgConfig QUIET)
pkg_check_modules(PC_ORCANIA QUIET liborcania)
find_path(ORCANIA_INCLUDE_DIR
NAMES orcania.h
HINTS ${PC_ORCANIA_INCLUDEDIR} ${PC_ORCANIA_INCLUDE_DIRS})
find_library(ORCANIA_LIBRARY
NAMES orcania liborcania
HINTS ${PC_ORCANIA_LIBDIR} ${PC_ORCANIA_LIBRARY_DIRS})
set(ORCANIA_VERSION_STRING 0.0.0)
if (PC_ORCANIA_VERSION)
set(ORCANIA_VERSION_STRING ${PC_ORCANIA_VERSION})
elseif (ORCANIA_INCLUDE_DIR AND EXISTS "${ORCANIA_INCLUDE_DIR}/orcania.h")
set(regex_orcania_version "^#define[ \t]+ORCANIA_VERSION[ \t]+([^\"]+).*")
file(STRINGS "${ORCANIA_INCLUDE_DIR}/orcania.h" orcania_version REGEX "${regex_orcania_version}")
string(REGEX REPLACE "${regex_orcania_version}" "\\1" ORCANIA_VERSION_STRING "${orcania_version}")
unset(regex_orcania_version)
unset(orcania_version)
if (NOT ORCANIA_VERSION_STRING)
set(regex_orcania_version "^#define[ \t]+ORCANIA_VERSION[ \t]+([^\"]+).*")
file(STRINGS "${ORCANIA_INCLUDE_DIR}/orcania-cfg.h" orcania_version REGEX "${regex_orcania_version}")
string(REGEX REPLACE "${regex_orcania_version}" "\\1" ORCANIA_VERSION_STRING "${orcania_version}")
unset(regex_orcania_version)
unset(orcania_version)
endif ()
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Orcania
REQUIRED_VARS ORCANIA_LIBRARY ORCANIA_INCLUDE_DIR
VERSION_VAR ORCANIA_VERSION_STRING)
if (ORCANIA_FOUND)
set(ORCANIA_LIBRARIES ${ORCANIA_LIBRARY})
set(ORCANIA_INCLUDE_DIRS ${ORCANIA_INCLUDE_DIR})
endif ()
mark_as_advanced(ORCANIA_INCLUDE_DIR ORCANIA_LIBRARY)
......@@ -32,7 +32,7 @@
#=============================================================================
find_package(PkgConfig QUIET)
pkg_check_modules(PC_YDER QUIET yder)
pkg_check_modules(PC_YDER QUIET libyder)
find_path(YDER_INCLUDE_DIR
NAMES yder.h
......@@ -51,6 +51,13 @@ elseif (YDER_INCLUDE_DIR AND EXISTS "${YDER_INCLUDE_DIR}/yder.h")
string(REGEX REPLACE "${regex_yder_version}" "\\1" YDER_VERSION_STRING "${yder_version}")
unset(regex_yder_version)
unset(yder_version)
if (NOT YDER_VERSION_STRING)
set(regex_yder_version "^#define[ \t]+YDER_VERSION[ \t]+([^\"]+).*")
file(STRINGS "${YDER_INCLUDE_DIR}/yder-cfg.h" yder_version REGEX "${regex_yder_version}")
string(REGEX REPLACE "${regex_yder_version}" "\\1" YDER_VERSION_STRING "${yder_version}")
unset(regex_yder_version)
unset(yder_version)
endif ()
endif ()
include(FindPackageHandleStandardArgs)
......
......@@ -20,10 +20,10 @@ HOEL_LOCATION=../src
LIBS=-lc -lhoel -ljansson -lyder -lorcania -L$(HOEL_LOCATION)
ADDITIONALFLAGS=-O3
all: libhoel.so example_sqlite3 example_mariadb example_pgsql example_mariadb_json
all: libhoel.so example_sqlite3 example_mariadb example_pgsql example_mariadb_json example_mariadb_binary
clean:
rm -f *.o example_sqlite3 example_mariadb example_pgsql example_mariadb_json
rm -f *.o example_sqlite3 example_mariadb example_pgsql example_mariadb_json example_mariadb_binary
debug: ADDITIONALFLAGS=-DDEBUG -g -O0
......@@ -48,6 +48,10 @@ example_mariadb_json: example_mariadb_json.c
$(CC) -c $(CFLAGS) example_mariadb_json.c
$(CC) -o example_mariadb_json example_mariadb_json.o $(LIBS)
example_mariadb_binary: example_mariadb_binary.c
$(CC) -c $(CFLAGS) example_mariadb_binary.c
$(CC) -o example_mariadb_binary example_mariadb_binary.o $(LIBS)
test: test_pgsql test_mariadb test_sqlite3 test_mariadb_json
test_pgsql: example_pgsql
......@@ -61,3 +65,6 @@ test_sqlite3: example_sqlite3
test_mariadb_json: example_mariadb_json
LD_LIBRARY_PATH=$(HOEL_LOCATION):${LD_LIBRARY_PATH} ./example_mariadb_json
test_mariadb_binary: example_mariadb_binary
LD_LIBRARY_PATH=$(HOEL_LOCATION):${LD_LIBRARY_PATH} ./example_mariadb_binary
#include <hoel.h>
#include <yder.h>
// The table structure is: 'create table test( integer_col int(10), string_col varchar(128), blob_col blob, binary_col binary(16));'
int main() {
struct _h_connection * conn = h_connect_mariadb("localhost", "test", "test", "test_binary", 0, NULL);
y_init_logs("test binary", Y_LOG_MODE_CONSOLE, Y_LOG_LEVEL_DEBUG, NULL, "Starting test binary");
if (conn != NULL) {
struct _h_result result;
char * query = "insert into test (integer_col, string_col, blob_col, binary_col) values (42, 'nope', 'contribution', 'a')";
y_log_message(Y_LOG_LEVEL_DEBUG, "Insert result: %d", h_query_insert(conn, query));
query = "select * from test";
if (h_query_select(conn, query, &result) == H_OK) {
int row, col;
for (row=0; row<result.nb_rows; row++) {
for (col=0; col<result.nb_columns; col++) {
if (result.data[row][col].type == HOEL_COL_TYPE_INT) {
y_log_message(Y_LOG_LEVEL_DEBUG, "int value: %d", ((struct _h_type_int *)result.data[row][col].t_data)->value);
} else if (result.data[row][col].type == HOEL_COL_TYPE_TEXT) {
y_log_message(Y_LOG_LEVEL_DEBUG, "text value: %.*s", ((struct _h_type_text *)result.data[row][col].t_data)->length, ((struct _h_type_text *)result.data[row][col].t_data)->value);
} else if (result.data[row][col].type == HOEL_COL_TYPE_BLOB) {
y_log_message(Y_LOG_LEVEL_DEBUG, "blob value: %.*s", ((struct _h_type_blob *)result.data[row][col].t_data)->length, ((struct _h_type_blob *)result.data[row][col].t_data)->value);
}
}
}
} else {
y_log_message(Y_LOG_LEVEL_DEBUG, "Error executing select");
}
query = "delete from test";
y_log_message(Y_LOG_LEVEL_DEBUG, "Delete result: %d", h_query_delete(conn, query));
} else {
y_log_message(Y_LOG_LEVEL_DEBUG, "Error connecting to database");
}
y_close_logs();
h_close_db(conn);
}
......@@ -36,7 +36,7 @@ struct _h_data * h_new_data_double(const double value);
* return pointer to the new structure
* return NULL on error
*/
struct _h_data * h_new_data_text(const char * value);
struct _h_data * h_new_data_text(const char * value, const size_t length);
/**
* Allocate memory for a new struct _h_data * containing a blob
......
/**
*
* Hoel database abstraction library
*
* hoel.h: structures and functions declarations
*
* Copyright 2015-2018 Nicolas Mora <mail@babelouest.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef _HOEL_CFG_H_
#define _HOEL_CFG_H_
#define HOEL_VERSION ${PROJECT_VERSION}
#cmakedefine _HOEL_SQLITE
#cmakedefine _HOEL_MARIADB
#cmakedefine _HOEL_PGSQL
#endif /* _HOEL_CFG_H_ */
......@@ -24,7 +24,7 @@
#ifndef __HOEL_H__
#define __HOEL_H__
#define HOEL_VERSION 1.4.4
#include "hoel-cfg.h"
#include <jansson.h>
......@@ -102,6 +102,7 @@ struct _h_type_datetime {
* sql value string type
*/
struct _h_type_text {
size_t length;
char * value;
};
......
......@@ -21,67 +21,95 @@
CC=gcc
ifndef DISABLE_SQLITE
FLAGS_SQLITE=-D_HOEL_SQLITE
ENABLE_SQLITE=1
LIBS_SQLITE=-lsqlite3
else
ENABLE_SQLITE=0
endif
ifndef DISABLE_MARIADB
FLAGS_MARIADB=-D_HOEL_MARIADB $(shell mysql_config --cflags)
ENABLE_MARIADB=1
FLAGS_MARIADB=$(shell mysql_config --cflags)
LIBS_MARIADB=$(shell mysql_config --libs_r)
else
ENABLE_MARIADB=0
endif
ifndef DISABLE_POSTGRESQL
FLAGS_PGSQL=-D_HOEL_PGSQL -I/usr/include/postgresql/
LIBS_PGSQL=-lpq
ENABLE_PGSQL=1
FLAGS_PGSQL=$(shell pkg-config --cflags libpq)
LIBS_PGSQL=$(shell pkg-config --libs libpq)
else
ENABLE_PGSQL=0
endif
HOEL_INCLUDE=../include
DESTDIR=/usr/local
CFLAGS+=-c -fPIC -Wall -I$(HOEL_INCLUDE) -I$(DESTDIR)/include $(FLAGS_SQLITE) $(FLAGS_MARIADB) $(FLAGS_PGSQL) -D_REENTRANT $(ADDITIONALFLAGS) $(CPPFLAGS)
CONFIG_TEMPLATE=$(HOEL_INCLUDE)/hoel-cfg.h.in
CONFIG_FILE=$(HOEL_INCLUDE)/hoel-cfg.h
CFLAGS+=-c -fPIC -Wall -I$(HOEL_INCLUDE) $(FLAGS_MARIADB) $(FLAGS_PGSQL) -D_REENTRANT $(ADDITIONALFLAGS) $(CPPFLAGS)
LIBS=-L$(DESTDIR)/lib -lc -ljansson -lyder -lorcania $(LIBS_SQLITE) $(LIBS_PGSQL) $(LIBS_MARIADB)
OBJECTS=hoel-sqlite.o hoel-mariadb.o hoel-pgsql.o hoel-simple-json.o hoel.o
OUTPUT=libhoel.so
VERSION=1.4.4
VERSION=1.4.8
all: release
libhoel.so: hoel-sqlite.o hoel-mariadb.o hoel-pgsql.o hoel-simple-json.o hoel.o
$(CC) -shared -fPIC -Wl,-soname,$(OUTPUT) -o $(OUTPUT).$(VERSION) hoel-sqlite.o hoel-mariadb.o hoel-pgsql.o hoel-simple-json.o hoel.o $(LIBS) $(LDFLAGS)
$(CONFIG_FILE):
@cp $(CONFIG_TEMPLATE) $(CONFIG_FILE)
@echo Config file $(CONFIG_FILE) generated
@sed -i -e 's/$${PROJECT_VERSION}/$(VERSION)/g' $(CONFIG_FILE)
@if [ "$(ENABLE_SQLITE)" = "1" ]; then \
sed -i -e 's/\#cmakedefine _HOEL_SQLITE/\#define _HOEL_SQLITE/g' $(CONFIG_FILE); \
echo "SQLITE SUPPORT ENABLED"; \
else \
sed -i -e 's/\#cmakedefine _HOEL_SQLITE/\/* #undef _HOEL_SQLITE *\//g' $(CONFIG_FILE); \
echo "SQLITE SUPPORT DISABLED"; \
fi
@if [ "$(ENABLE_MARIADB)" = "1" ]; then \
sed -i -e 's/\#cmakedefine _HOEL_MARIADB/\#define _HOEL_MARIADB/g' $(CONFIG_FILE); \
echo "MARIADB SUPPORT ENABLED"; \
else \
sed -i -e 's/\#cmakedefine _HOEL_MARIADB/\/* #undef _HOEL_MARIADB *\//g' $(CONFIG_FILE); \
echo "MARIADB SUPPORT DISABLED"; \
fi
@if [ "$(ENABLE_PGSQL)" = "1" ]; then \
sed -i -e 's/\#cmakedefine _HOEL_PGSQL/\#define _HOEL_PGSQL/g' $(CONFIG_FILE); \
echo "PGSQL SUPPORT ENABLED"; \
else \
sed -i -e 's/\#cmakedefine _HOEL_PGSQL/\/* #undef _HOEL_PGSQL *\//g' $(CONFIG_FILE); \
echo "PGSQL SUPPORT DISABLED"; \
fi
libhoel.so: $(OBJECTS)
$(CC) -shared -fPIC -Wl,-soname,$(OUTPUT) -o $(OUTPUT).$(VERSION) $(OBJECTS) $(LIBS) $(LDFLAGS)
ln -sf $(OUTPUT).$(VERSION) $(OUTPUT)
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
libhoel.a: $(OBJECTS)
ar rcs libhoel.a $(OBJECTS)
hoel.o: hoel.c $(HOEL_INCLUDE)/hoel.h
$(CC) $(CFLAGS) hoel.c
hoel-sqlite.o: hoel-sqlite.c $(HOEL_INCLUDE)/hoel.h
$(CC) $(CFLAGS) hoel-sqlite.c
hoel-mariadb.o: hoel-mariadb.c $(HOEL_INCLUDE)/hoel.h
$(CC) $(CFLAGS) hoel-mariadb.c
hoel-pgsql.o: hoel-pgsql.c $(HOEL_INCLUDE)/hoel.h
$(CC) $(CFLAGS) hoel-pgsql.c
hoel-simple-json.o: hoel-simple-json.c $(HOEL_INCLUDE)/hoel.h
$(CC) $(CFLAGS) hoel-simple-json.c
%.o: %.c $(CONFIG_FILE) $(HOEL_INCLUDE)/hoel.h $(HOEL_INCLUDE)/h-private.h
$(CC) $(CFLAGS) $<
clean:
rm -f *.o *.so *.a $(OUTPUT) $(OUTPUT).*
rm -f *.o *.so *.a $(OUTPUT) $(OUTPUT).* $(CONFIG_FILE)
install: all
cp $(OUTPUT).$(VERSION) $(DESTDIR)/lib
cp $(HOEL_INCLUDE)/hoel.h $(DESTDIR)/include
install -m644 $(HOEL_INCLUDE)/hoel.h $(DESTDIR)/include
install -m644 $(CONFIG_FILE) $(DESTDIR)/include
/sbin/ldconfig
static-install: static
cp libhoel.a $(DESTDIR)/lib
cp $(HOEL_INCLUDE)/hoel.h $(DESTDIR)/include
install -m644 $(HOEL_INCLUDE)/hoel.h $(DESTDIR)/include
install -m644 $(CONFIG_FILE) $(DESTDIR)/include
uninstall:
rm -f $(DESTDIR)/lib/$(OUTPUT) $(DESTDIR)/lib/libhoel.a
rm -f $(DESTDIR)/lib/$(OUTPUT).*
rm -f $(DESTDIR)/include/hoel.h
rm -f $(DESTDIR)/include/hoel-cfg.h
debug: ADDITIONALFLAGS=-DDEBUG -g -O0
......
......@@ -391,7 +391,7 @@ struct _h_data * h_get_mariadb_value(const char * value, const unsigned long len
case FIELD_TYPE_SET: