Skip to content

Data conversion: timing data types. Testing #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
95b2242
b/f: use the wide chars variants in switch
bpintea May 16, 2018
730604d
implement type check between DB data and app buff
bpintea May 16, 2018
dd23003
b/f: fix destination buffer pointer as argument
bpintea May 24, 2018
5e92a6d
add support for Google Test framework
bpintea May 25, 2018
65bd930
b/f: two internal functions now no longer exported
bpintea May 25, 2018
831ba55
move JSON specific code to proper module
bpintea May 25, 2018
eb55d46
mask unnecessary symbols exported by 3rdp library
bpintea May 25, 2018
4ec281a
check SQL data types sent by ES/SQL
bpintea May 25, 2018
cebd335
add a 'testing' mode to connecting
bpintea May 25, 2018
a3d339b
export some key functions used by testing
bpintea May 25, 2018
8d50695
data conversions to C timestamp type
bpintea May 26, 2018
feff775
add the tests for conversion to SQL C timestamp
bpintea May 26, 2018
7ce4b97
when running 'suites' abort on failure
bpintea May 29, 2018
908bd33
add convertion to SQL_C_TYPE_DATE and _TIME
bpintea May 29, 2018
7e95add
tests for _TIME and _DATE conversions
bpintea May 29, 2018
ebc307c
add state checking loggic to connected dbc class
bpintea May 29, 2018
ed939ad
renamed timestamp tests file
bpintea May 29, 2018
7961311
add handling of interval C data types
bpintea May 29, 2018
9a8de6d
style: brace single-line blocks
bpintea May 31, 2018
5e8d5c7
use gtest_maind lib for the main
bpintea May 31, 2018
b0a34b4
add the license header in all test files
bpintea May 31, 2018
f3f376e
b/f: uncouple NDEBUG from TEST_API
bpintea Jun 1, 2018
56409a4
add build info to the version string
bpintea Jun 1, 2018
b5087f3
add ability to select the configuration to build
bpintea Jun 1, 2018
a1b0596
add dllimport attribute to TEST_API
bpintea Jun 1, 2018
286f200
added the missing license headers
bpintea Jun 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
233 changes: 136 additions & 97 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
#
# ELASTICSEARCH CONFIDENTIAL
# __________________
#
# [2018] Elasticsearch Incorporated. All Rights Reserved.
#
# NOTICE: All information contained herein is, and remains
# the property of Elasticsearch Incorporated and its suppliers,
# if any. The intellectual and technical concepts contained
# herein are proprietary to Elasticsearch Incorporated
# and its suppliers and may be covered by U.S. and Foreign Patents,
# patents in process, and are protected by trade secret or copyright law.
# Dissemination of this information or reproduction of this material
# is strictly forbidden unless prior written permission is obtained
# from Elasticsearch Incorporated.
#

# 2.8.6: to generate the _EXPORTS define
cmake_minimum_required(VERSION 2.8.6 FATAL_ERROR)
# 3.1.0: CMAKE_GENERATOR_PLATFORM
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)

set(DRIVER_BASE_NAME elasticodbc CACHE STRING
"The base name to give the driver")

# driver's version
set(DRV_VER_MAJOR 0)
set(DRV_VER_MINOR 1)
set(BASE_NAME elasticodbc)

# build a UNICODE driver? (currently only supported way)
# build a UNICODE driver? (the only supported way currently)
set(IS_UNICODE 1)

#include(GenerateExportHeader)

# https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_PLATFORM.html :
# "The value of this variable should never be modified by project code."
# , BUT:
# https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2015%202017.html :
# "The CMAKE_GENERATOR_PLATFORM variable may be set to specify a target
# platform name (architecture)."
if (${WIN32})
if ($ENV{VSCMD_ARG_TGT_ARCH} MATCHES x64)
set(CMAKE_GENERATOR_PLATFORM x64)
if (${CMAKE_GENERATOR_PLATFORM} MATCHES x64)
#set(CMAKE_GENERATOR_PLATFORM x64)
set(TARCH x64) # target arch
set(BARCH ) # bits architecture (64 is the default, silent)
else ($ENV{VSCMD_ARG_TGT_ARCH} MATCHES x64)
else (${CMAKE_GENERATOR_PLATFORM} MATCHES x64)
set(TARCH x86)
set(BARCH 32)
endif ($ENV{VSCMD_ARG_TGT_ARCH} MATCHES x64)
endif (${CMAKE_GENERATOR_PLATFORM} MATCHES x64)
message("Building on Windows, ${TARCH}.")
else (${WIN32})
message(FATAL_ERROR "No support for current platform yet")
endif (${WIN32})

# explicit languages support (Cs are defaults)
project(${BASE_NAME} CXX C)
project(${DRIVER_BASE_NAME} CXX C)

if (${IS_UNICODE})
set(ENCODING u) # Unicode
Expand All @@ -41,14 +56,34 @@ endif (${IS_UNICODE})

# driver name
# XXX: ANSI/Unicode/32/64
set(DRV_NAME "${BASE_NAME}${DRV_VER_MAJOR}${ENCODING}${BARCH}")
set(DRV_NAME "${DRIVER_BASE_NAME}${DRV_VER_MAJOR}${ENCODING}${BARCH}")

# Turn on the ability to create folders to organize projects (.vcproj)
# It creates "CMakePredefinedTargets" folder by default and adds CMake
# defined projects like INSTALL.vcproj and ZERO_CHECK.vcproj
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Set compiler flags and options.


# which version is the code at?
execute_process(COMMAND
git describe --dirty=+ --broken=X --always --tags
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE CMD_RETURN
OUTPUT_VARIABLE CMD_OUTPUT
ERROR_VARIABLE CMD_OUTERR
)
# WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/${DRV_SRC_DIR}"
if (${CMD_RETURN})
message(WARNING "Git command failed:")
message("\tret: ${CMD_RETURN}")
message("\tout: ${CMD_OUTPUT}")
message("\terr: ${CMD_OUTERR}")
set(DRV_SRC_VER "n/a")
else (${CMD_RETURN})
set(DRV_SRC_VER ${CMD_OUTPUT})
endif (${CMD_RETURN})

# Set compiler flags and options.
if (${WIN32})
# set the Visual Studio warning level to 4
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
Expand All @@ -61,39 +96,48 @@ if (${WIN32})
if (${IS_UNICODE})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DUNICODE /D_UNICODE")
endif (${IS_UNICODE})
# set the version
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DDRV_NAME=${DRV_NAME}")

# set the all identifiers
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DDRV_VER_MAJOR=${DRV_VER_MAJOR}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DDRV_VER_MINOR=${DRV_VER_MINOR}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DDRV_SRC_VER=${DRV_SRC_VER}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DDRV_ENCODING=${ENCODING}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DDRV_NAME=${DRV_NAME}")

#set(LIBCURL_PATH_LIB ${LIBCURL_PATH_LIB}\\libcurl.dll)
# ...including the build type indicator
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /DDRV_BUILD_TYPE=d")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /DDRV_BUILD_TYPE=r")
set(CMAKE_C_FLAGS_RELWITHDEBINFO
"${CMAKE_C_FLAGS_RELWITHDEBINFO} /DDRV_BUILD_TYPE=i")
set(CMAKE_C_FLAGS_MINSIZEREL
"${CMAKE_C_FLAGS_MINSIZEREL} /DDRV_BUILD_TYPE=s")

# unless building for stripping Release, export the testing functions
# (this will allow RelWithDebInfo buliding and still be able to test it)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /DTEST_API=")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_RELEASE} /DTEST_API=")
else (${WIN32})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")

#set(LIBCURL_PATH_LIB ${LIBCURL_PATH_LIB}/libcurl.so)
endif (${WIN32})
message("C flags: ${CMAKE_C_FLAGS} .")

set(DRV_SRC_DIR driver)
set(DRV_LIB_DIR lib)
set(DRV_BUILD_DIR builds)
message("Directories: source: '${DRV_SRC_DIR}', output: '${DRV_LIB_DIR}'.")

aux_source_directory(${DRV_SRC_DIR} DRV_SRC)

# generate Module definition file (symbols to export)
execute_process(COMMAND
execute_process(COMMAND
${CMAKE_SOURCE_DIR}/${DRV_SRC_DIR}/build_def.bat ${DRV_NAME}
${CMAKE_SOURCE_DIR}/${DRV_BUILD_DIR}/${DRV_NAME}.def
${CMAKE_BINARY_DIR}/${DRV_NAME}.def
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/${DRV_SRC_DIR}"
RESULT_VARIABLE CMD_RETURN
OUTPUT_VARIABLE CMD_OUTPUT
ERROR_VARIABLE CMD_OUTERR
)
# WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/${DRV_SRC_DIR}"
if (${CMD_RETURN})
message("Generating module .def file failed:")
message(WARNING "Generating module .def file failed:")
message("\tret: ${CMD_RETURN}")
message("\tout: ${CMD_OUTPUT}")
message("\terr: ${CMD_OUTERR}")
Expand All @@ -103,106 +147,101 @@ endif (${CMD_RETURN})
#
# add ODBC-Specification to the project
#
if (IS_DIRECTORY $ENV{ODBC_PATH_SRC})
set(ODBC_PATH_SRC $ENV{ODBC_PATH_SRC})
else (IS_DIRECTORY $ENV{ODBC_PATH_SRC})
if (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/ODBC-Specification)
set(ODBC_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/ODBC-Specification)
else (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/ODBC-Specification)
message(FATAL_ERROR "No ODBC-Specification directory found: set "
"environment var ODBC_PATH_SRC or place an "
"'ODBC-Specification' export into local 'lib' dir.")
endif (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/ODBC-Specification)
endif (IS_DIRECTORY $ENV{ODBC_PATH_SRC})
# TODO: add this as a git subtree and/or as ExternalProject
set(ODBC_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/ODBC-Specification CACHE PATH
"ODBC-Specification source path")
if (NOT IS_DIRECTORY ${ODBC_PATH_SRC})
message(FATAL_ERROR "No ODBC-Specification directory found: use "
"ODBC_PATH_SRC cmake option or place an 'ODBC-Specification' "
"clone into local 'lib' dir.")
endif (NOT IS_DIRECTORY ${ODBC_PATH_SRC})
message("ODBC-Specification source path: ${ODBC_PATH_SRC} .")
set(ODBC_INC ${ODBC_PATH_SRC}/Windows/inc )
set(ODBC_INC ${ODBC_PATH_SRC}/Windows/inc)


#
# add ujson4c to the project
#
if (IS_DIRECTORY $ENV{UJSON4C_PATH_SRC})
set(UJSON4C_PATH_SRC $ENV{UJSON4C_PATH_SRC})
else (IS_DIRECTORY $ENV{UJSON4C_PATH_SRC})
if (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/ujson4c)
set(UJSON4C_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/ujson4c)
else (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/ujson4c)
message(FATAL_ERROR "No ujson4c directory found: set environment var "
"UJSON4C_PATH_SRC or place an 'ujson4c' export into local "
"'libs' dir.")
endif (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/ujson4c)
endif (IS_DIRECTORY $ENV{UJSON4C_PATH_SRC})
# TODO: add this as a git subtree and/or as ExternalProject (with patching)
set(UJSON4C_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/ujson4c CACHE PATH
"Lib ujson4c source path")
if (NOT IS_DIRECTORY ${UJSON4C_PATH_SRC})
message(FATAL_ERROR "No ujson4c directory found: use UJSON4C_PATH_SRC "
"cmake option or place an 'ujson4c' clone into local 'libs' dir.")
endif (NOT IS_DIRECTORY ${UJSON4C_PATH_SRC})
message("Lib ujson4c source path: ${UJSON4C_PATH_SRC} .")
aux_source_directory(${UJSON4C_PATH_SRC}/src DRV_SRC)
aux_source_directory(${UJSON4C_PATH_SRC}/3rdparty DRV_SRC)
set(UJSON4C_INC ${UJSON4C_PATH_SRC}/src ${UJSON4C_PATH_SRC}/3rdparty )

#
# add c-timestamp to the project
#
# TODO: add this as a git subtree and/or as ExternalProject
set(CTIMESTAMP_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/c-timestamp CACHE PATH
"Lib c-timestamp source path")
if (NOT IS_DIRECTORY ${CTIMESTAMP_PATH_SRC})
message(FATAL_ERROR "No c-timestamp directory found: use "
"CTIMESTAMP_PATH_SRC cmake option or place a 'c-timestamp' clone "
"in local 'lib' dir.")
endif (NOT IS_DIRECTORY ${CTIMESTAMP_PATH_SRC})
message("Lib c-timestamp source path: ${CTIMESTAMP_PATH_SRC} .")
aux_source_directory(${CTIMESTAMP_PATH_SRC}/ DRV_SRC)

#
# add libcurl to the project
#
# read libcurl's build paths from the environment (assume local dir otherwise)
if (IS_DIRECTORY $ENV{LIBCURL_PATH_BUILD})
set(LIBCURL_PATH_BUILD $ENV{LIBCURL_PATH_BUILD})
else (IS_DIRECTORY $ENV{LIBCURL_PATH_BUILD})
if (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/libcurl)
set(LIBCURL_PATH_BUILD ${CMAKE_SOURCE_DIR}/libs/libcurl)
else (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/libcurl)
message(FATAL_ERROR "No libcurl directory found: set environment var "
"LIBCURL_PATH_BUILD or place a 'libcurl' dir in local source"
"tree, with 'bin' and 'include' subdirs.")
endif (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/libcurl)
endif (IS_DIRECTORY $ENV{LIBCURL_PATH_BUILD})
message("Lib libcurl build path: ${LIBCURL_PATH_BUILD} .")
# TODO: add this as a git subtree and/or as ExternalProject
set(LIBCURL_LD_PATH
# curl "installs" the .dll and .lib in different directories -> use the
# build dir to find both files in same directory instead of installing
${CMAKE_SOURCE_DIR}/libs/curl/builds/libcurl-vc-${TARCH}-release-dll-ipv6-sspi-winssl-obj-lib/
CACHE PATH "Lib curl load library path")
set(LIBCURL_INC_PATH ${CMAKE_SOURCE_DIR}/libs/curl/include CACHE PATH
"Lib curl include path")
if (NOT IS_DIRECTORY ${LIBCURL_LD_PATH}
OR NOT IS_DIRECTORY ${LIBCURL_INC_PATH})
message(FATAL_ERROR "Missing libcurl lib and/or inc directories: use "
"LIBCURL_LD_PATH and LIBCURL_INC_PATH cmake options or place a built "
"'curl' clone in local 'libs' dir.")
endif()
message("Curl paths load lib: ${LIBCURL_LD_PATH}, inc: ${LIBCURL_INC_PATH} .")
# add libcurl as dependency
add_library(libcurl SHARED IMPORTED)
set(LIBCURL_INC ${LIBCURL_PATH_BUILD}/include)
if (${WIN32})
set_property(TARGET libcurl PROPERTY IMPORTED_LOCATION
${LIBCURL_PATH_BUILD}/bin/libcurl.dll)
set_property(TARGET libcurl PROPERTY IMPORTED_LOCATION
${LIBCURL_LD_PATH}/libcurl${CMAKE_SHARED_LIBRARY_SUFFIX})
set_property(TARGET libcurl PROPERTY IMPORTED_IMPLIB
${LIBCURL_PATH_BUILD}/lib/libcurl.lib)
${LIBCURL_LD_PATH}/libcurl${CMAKE_STATIC_LIBRARY_SUFFIX})
else (${WIN32})
set_property(TARGET libcurl PROPERTY IMPORTED_LOCATION
${LIBCURL_PATH_BUILD}/lib/libcurl.so)
set_property(TARGET libcurl PROPERTY IMPORTED_LOCATION
${LIBCURL_LD_PATH}/libcurl${CMAKE_SHARED_LIBRARY_SUFFIX})
endif (${WIN32})

#
# add c-timestamp to the project
#
if (IS_DIRECTORY $ENV{CTIMESTAMP_PATH_SRC})
set(CTIMESTAMP_PATH_SRC $ENV{CTIMESTAMP_PATH_SRC})
else (IS_DIRECTORY $ENV{CTIMESTAMP_PATH_SRC})
if (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/c-timestamp)
set(CTIMESTAMP_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/c-timestamp)
else (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/c-timestamp)
message(FATAL_ERROR "No c-timestamp directory found: set environment"
" var CTIMESTAMP_PATH_SRC or place an export into "
"'c-timestamp' dir in local source tree.")
endif (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/c-timestamp)
endif (IS_DIRECTORY $ENV{CTIMESTAMP_PATH_SRC})
message("Lib c-timestamp source path: ${CTIMESTAMP_PATH_SRC} .")
aux_source_directory(${CTIMESTAMP_PATH_SRC}/ DRV_SRC)
set(CTIMESTAMP_INC ${CTIMESTAMP_PATH_SRC}/ )


message("Driver source files: ${DRV_SRC} .")
message("Driver include paths: " ${ODBC_INC} ${DRV_SRC_DIR} ${LIBCURL_INC}
${UJSON4C_INC} ${CTIMESTAMP_INC})
message("Driver include paths: " ${ODBC_INC} ${DRV_SRC_DIR}
${LIBCURL_INC_PATH} ${UJSON4C_INC} ${CTIMESTAMP_PATH_SRC})

#
# finally, set destination library
#
add_library(${DRV_NAME} SHARED ${DRV_SRC} ${DRV_BUILD_DIR}/${DRV_NAME}.def)
add_library(${DRV_NAME} SHARED ${DRV_SRC} ${CMAKE_BINARY_DIR}/${DRV_NAME}.def)
#generate_export_header(${DRV_NAME})
target_compile_definitions(${DRV_NAME} PRIVATE "DRIVER_BUILD")

#include_directories(${DRV_SRC_DIR} ${DRV_BUILD_DIR})
include_directories(${ODBC_INC} ${DRV_SRC_DIR} ${LIBCURL_INC} ${UJSON4C_INC}
${CTIMESTAMP_INC})

include_directories(${ODBC_INC} ${DRV_SRC_DIR} ${LIBCURL_INC_PATH}
${UJSON4C_INC} ${CTIMESTAMP_PATH_SRC})

target_link_libraries(${DRV_NAME} libcurl)

# add testing project/target
enable_testing()
# ... and testing directory to build
add_subdirectory(test)

# add instalation project/target
install(TARGETS ${DRV_NAME} DESTINATION ${DRV_LIB_DIR})


install(TARGETS ${DRV_NAME}
DESTINATION ${DRV_LIB_DIR}
)
# vim: set noet fenc=utf-8 ff=dos sts=0 sw=4 ts=4 :
Loading