blob: 502c767103ef775c60bf82b2bd3b98659bc69f51 [file] [log] [blame] [edit]
diff -Naur nanodbc-2.12.4/CMakeLists.txt nanodbc-2.12.4-patched/CMakeLists.txt
--- nanodbc-2.12.4/CMakeLists.txt 2016-03-22 00:55:36.000000000 +0300
+++ nanodbc-2.12.4-patched/CMakeLists.txt 2018-05-15 08:31:25.024541100 +0300
@@ -1,13 +1,10 @@
cmake_minimum_required(VERSION 2.8.7)
project(nanodbc)
-option(NANODBC_USE_UNICODE "build with unicode support turned on" OFF)
option(NANODBC_USE_BOOST_CONVERT "build using Boost.Locale for string convert" OFF)
option(NANODBC_HANDLE_NODATA_BUG "enable special handling for SQL_NO_DATA (required for vertica)" OFF)
-option(NANODBC_STATIC "build static instead of shared library" OFF)
option(NANODBC_EXAMPLES "build examples" ON)
option(NANODBC_TEST "build tests" ON)
-option(NANODBC_INSTALL "generate install target" ON)
option(NANODBC_ENABLE_LIBCXX "Use libc++ if available." ON)
if(APPLE)
@@ -106,9 +103,6 @@
set(CMAKE_FLAGS "${CMAKE_FLAGS} ${ODBC_CFLAGS}")
execute_process(COMMAND ${ODBC_CONFIG} --libs
OUTPUT_VARIABLE ODBC_LINK_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
- if(NANODBC_USE_UNICODE)
- add_definitions(-DNANODBC_USE_IODBC_WIDE_STRINGS)
- endif()
endif()
endif()
@@ -130,17 +124,6 @@
add_definitions(-DNANODBC_ODBC_VERSION=${NANODBC_ODBC_VERSION})
endif()
-if(NANODBC_USE_UNICODE)
- message(STATUS "Unicode support: Turned on")
- add_definitions(-DNANODBC_USE_UNICODE)
- if(MSVC)
- # Sets "Use Unicode Character Set" property in Visual Studio projects
- add_definitions(-DUNICODE -D_UNICODE)
- endif()
-else()
- message(STATUS "Unicode support: Turned off")
-endif()
-
if(NANODBC_USE_BOOST_CONVERT)
message(STATUS "Boost string convert: Turned on")
add_definitions(-DNANODBC_USE_BOOST_CONVERT)
@@ -178,38 +161,109 @@
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ODBC_LINK_FLAGS}")
elseif(MSVC)
set(ODBC_LIBRARIES odbc32.lib odbccp32.lib Ws2_32.lib)
+elseif(MINGW)
+ set(ODBC_LIBRARIES odbc32 odbccp32)
endif()
########################################
-## nanodbc library target
+## nanodbc static library target - non unicode
########################################
-if(NANODBC_STATIC)
- add_library(nanodbc STATIC src/nanodbc.cpp src/nanodbc.h)
- message(STATUS "Build target: STATIC")
-else()
- add_library(nanodbc SHARED src/nanodbc.cpp src/nanodbc.h)
- target_link_libraries(nanodbc ${Boost_LIBRARIES} ${ODBC_LIBRARIES})
- message(STATUS "Build target: SHARED")
+add_library(nanodbc_static STATIC src/nanodbc.cpp src/nanodbc.h)
+set_target_properties(nanodbc_static PROPERTIES OUTPUT_NAME nanodbc)
+target_link_libraries(nanodbc_static PUBLIC ${Boost_LIBRARIES} ${ODBC_LIBRARIES})
+
+if(UNIX)
+ set_target_properties(nanodbc_static PROPERTIES
+ COMPILE_FLAGS "${ODBC_CFLAGS}"
+ LIBRARY_OUTPUT_DIRECTORY "lib")
endif()
+install(
+ TARGETS nanodbc_static
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)
+
+########################################
+## nanodbc shared library target - non unicode
+########################################
+add_library(nanodbc_shared SHARED src/nanodbc.cpp src/nanodbc.h)
+set_target_properties(nanodbc_shared PROPERTIES OUTPUT_NAME nanodbc)
+target_link_libraries(nanodbc_shared PUBLIC ${Boost_LIBRARIES} ${ODBC_LIBRARIES})
+
if(UNIX)
- set_target_properties(nanodbc PROPERTIES
+ set_target_properties(nanodbc_shared PROPERTIES
COMPILE_FLAGS "${ODBC_CFLAGS}"
LIBRARY_OUTPUT_DIRECTORY "lib")
endif()
-if(NANODBC_INSTALL)
- install(FILES src/nanodbc.h DESTINATION include)
- if(NANODBC_STATIC)
- install(TARGETS nanodbc ARCHIVE DESTINATION lib)
- else()
- install(TARGETS nanodbc LIBRARY DESTINATION lib)
- endif()
- message(STATUS "Target install: Turned on")
-else()
- message(STATUS "Target install: Turned off")
+install(
+ TARGETS nanodbc_shared
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)
+
+########################################
+## nanodbc static library target - unicode
+########################################
+add_library(nanodbc_unicode_static STATIC src/nanodbc.cpp src/nanodbc.h)
+set_target_properties(nanodbc_unicode_static PROPERTIES OUTPUT_NAME nanodbc_unicode)
+target_link_libraries(nanodbc_unicode_static PUBLIC ${Boost_LIBRARIES} ${ODBC_LIBRARIES})
+target_compile_definitions(nanodbc_unicode_static PUBLIC -DNANODBC_USE_UNICODE)
+
+if(WIN32)
+ # Sets "Use Unicode Character Set" property in Visual Studio projects
+ target_compile_definitions(nanodbc_unicode_static PUBLIC -DUNICODE -D_UNICODE)
endif()
+if(ODBC_CONFIG)
+ target_compile_definitions(nanodbc_unicode_static PUBLIC -DNANODBC_USE_IODBC_WIDE_STRINGS)
+endif()
+
+if(UNIX)
+ set_target_properties(nanodbc_unicode_static PROPERTIES
+ COMPILE_FLAGS "${ODBC_CFLAGS}"
+ LIBRARY_OUTPUT_DIRECTORY "lib")
+endif()
+
+install(
+ TARGETS nanodbc_unicode_static
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)
+
+########################################
+## nanodbc shared library target - unicode
+########################################
+add_library(nanodbc_unicode_shared SHARED src/nanodbc.cpp src/nanodbc.h)
+set_target_properties(nanodbc_unicode_shared PROPERTIES OUTPUT_NAME nanodbc_unicode)
+target_link_libraries(nanodbc_unicode_shared PUBLIC ${Boost_LIBRARIES} ${ODBC_LIBRARIES})
+target_compile_definitions(nanodbc_unicode_shared PUBLIC -DNANODBC_USE_UNICODE)
+
+if(WIN32)
+ # Sets "Use Unicode Character Set" property in Visual Studio projects
+ target_compile_definitions(nanodbc_unicode_shared PUBLIC -DUNICODE -D_UNICODE)
+endif()
+
+if(ODBC_CONFIG)
+ target_compile_definitions(nanodbc_unicode_shared PUBLIC -DNANODBC_USE_IODBC_WIDE_STRINGS)
+endif()
+
+if(UNIX)
+ set_target_properties(nanodbc_unicode_shared PROPERTIES
+ COMPILE_FLAGS "${ODBC_CFLAGS}"
+ LIBRARY_OUTPUT_DIRECTORY "lib")
+endif()
+
+install(
+ TARGETS nanodbc_unicode_shared
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)
+
+########################################
+## headers
+########################################
+install(FILES src/nanodbc.h DESTINATION include)
+
########################################
## examples
########################################
diff -Naur nanodbc-2.12.4/examples/CMakeLists.txt nanodbc-2.12.4-patched/examples/CMakeLists.txt
--- nanodbc-2.12.4/examples/CMakeLists.txt 2016-03-22 00:55:36.000000000 +0300
+++ nanodbc-2.12.4-patched/examples/CMakeLists.txt 2018-05-15 08:31:25.040141200 +0300
@@ -4,12 +4,10 @@
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src ${ODBC_INCLUDE_DIR})
link_directories(${CMAKE_BINARY_DIR}/lib)
-foreach(example ${examples})
- add_executable(example_${example} ${example}.cpp)
- if (NANODBC_STATIC)
- target_link_libraries(example_${example} nanodbc ${ODBC_LIBRARIES})
- else()
- target_link_libraries(example_${example} nanodbc "${ODBC_LINK_FLAGS}")
- endif()
- add_dependencies(examples example_${example})
+foreach(config "" "_unicode")
+ foreach(example ${examples})
+ add_executable(example_${example}${config} ${example}.cpp)
+ target_link_libraries(example_${example}${config} nanodbc${config}_shared)
+ add_dependencies(examples example_${example}${config})
+ endforeach()
endforeach()
diff -Naur nanodbc-2.12.4/examples/table_schema.cpp nanodbc-2.12.4-patched/examples/table_schema.cpp
--- nanodbc-2.12.4/examples/table_schema.cpp 2016-03-22 00:55:36.000000000 +0300
+++ nanodbc-2.12.4-patched/examples/table_schema.cpp 2018-05-15 08:31:25.040141200 +0300
@@ -11,7 +11,7 @@
#include <string>
#ifdef _WIN32
-#define NOMINMAX
+//#define NOMINMAX
#include <windows.h> // SQLLEN, SQLULEN, SQLHWND
#endif
#include <sql.h>
diff -Naur nanodbc-2.12.4/src/nanodbc.cpp nanodbc-2.12.4-patched/src/nanodbc.cpp
--- nanodbc-2.12.4/src/nanodbc.cpp 2016-03-22 00:55:36.000000000 +0300
+++ nanodbc-2.12.4-patched/src/nanodbc.cpp 2018-05-15 08:31:25.040141200 +0300
@@ -44,7 +44,7 @@
#ifdef _WIN32
// needs to be included above sql.h for windows
- #define NOMINMAX
+ //#define NOMINMAX
#include <windows.h>
#endif
diff -Naur nanodbc-2.12.4/test/base_test_fixture.h nanodbc-2.12.4-patched/test/base_test_fixture.h
--- nanodbc-2.12.4/test/base_test_fixture.h 2016-03-22 00:55:36.000000000 +0300
+++ nanodbc-2.12.4-patched/test/base_test_fixture.h 2018-05-15 08:31:25.040141200 +0300
@@ -31,7 +31,7 @@
#ifdef _WIN32
// needs to be included above sql.h for windows
-#define NOMINMAX
+//#define NOMINMAX
#include <windows.h>
#endif
#include <sql.h>
@@ -39,6 +39,17 @@
struct base_test_fixture
{
+ // Database vendor
+ enum DBVendor
+ {
+ unknown,
+ Oracle,
+ SQLite,
+ PostgreSQL,
+ MySQL,
+ SQLServer
+ };
+
// To invoke a unit test over all integral types, use:
//
typedef std::tuple<
@@ -71,9 +82,87 @@
nanodbc::string_type connection_string_;
+ DBVendor vendor_;
+
+ DBVendor get_vendor(const nanodbc::string_type &dbms)
+ {
+ REQUIRE(!dbms.empty());
+ if (contains_string(dbms, NANODBC_TEXT("Oracle")))
+ return Oracle;
+ else if (contains_string(dbms, NANODBC_TEXT("SQLite")))
+ return Oracle;
+ else if (contains_string(dbms, NANODBC_TEXT("PostgreSQL")))
+ return PostgreSQL;
+ else if (contains_string(dbms, NANODBC_TEXT("MySQL")))
+ return MySQL;
+ else if (contains_string(dbms, NANODBC_TEXT("SQLServer")))
+ return SQLServer;
+ else
+ return unknown;
+ }
+
+ nanodbc::string_type get_binary_type_name()
+ {
+ switch (vendor_)
+ {
+ case SQLite:
+ return NANODBC_TEXT("blob");
+ case PostgreSQL:
+ return NANODBC_TEXT("bytea");
+ case MySQL:
+ return NANODBC_TEXT("varbinary(10)");
+ default:
+ return NANODBC_TEXT("varbinary"); // Oracle, SQL Server,...standard type?
+ }
+ }
+
+ nanodbc::string_type get_primary_key_name(const nanodbc::string_type &assumed)
+ {
+ switch (vendor_)
+ {
+ case MySQL:
+ return NANODBC_TEXT("PRIMARY");
+ default:
+ return assumed;
+ }
+ }
+
+ short get_data_type(const nanodbc::string_type &name)
+ {
+ if (name == NANODBC_TEXT("float"))
+ return (vendor_ == MySQL) ? SQL_REAL : SQL_FLOAT;
+ else
+ return 0;
+ }
+
+ int get_data_type_size(const nanodbc::string_type &name, short radix = -1)
+ {
+ if (name == NANODBC_TEXT("float"))
+ {
+ if (radix == 10)
+ return 17; // total number of digits allowed
+ else if (radix != 2)
+ WARN("numeric radix different than 2 or 10: was " + std::to_string(radix));
+
+ if (vendor_ == MySQL)
+ return 7; // total number of bytes allowed
+ else
+ return 53; // total number of bits allowed
+ }
+ else if (name == NANODBC_TEXT("text"))
+ {
+ static const int get_data_type_size_text[] = {-1, 4000, 8190, 1073741824, 65535, 65535};
+ return get_data_type_size_text[vendor_];
+ }
+ return -1;
+ }
+
nanodbc::connection connect()
{
- return nanodbc::connection(connection_string_);
+ nanodbc::connection connection(connection_string_);
+ REQUIRE(connection.connected());
+ vendor_ = get_vendor(connection.dbms_name());
+ return connection;
}
static void check_rows_equal(nanodbc::result results, int rows)
@@ -169,7 +258,6 @@
void catalog_columns_test()
{
nanodbc::connection connection = connect();
- REQUIRE(connection.connected());
nanodbc::catalog catalog(connection);
// Successfully tested against SQL Server and PostgreSQL (9.x) only.
@@ -193,23 +281,7 @@
// Determine DBMS-specific features, properties and values
// NOTE: If handling DBMS-specific features become overly complicated,
// we may decided to remove such features from the tests.
- nanodbc::string_type binary_type_name;
- {
- nanodbc::string_type const dbms = connection.dbms_name();
- REQUIRE(!dbms.empty());
- if (contains_string(dbms, NANODBC_TEXT("SQLite")))
- {
- binary_type_name = NANODBC_TEXT("blob");
- }
- else if (contains_string(dbms, NANODBC_TEXT("PostgreSQL")))
- {
- binary_type_name = NANODBC_TEXT("bytea");
- }
- else
- {
- binary_type_name = NANODBC_TEXT("varbinary"); // Oracle, MySQL, SQL Server,...standard type?
- }
- }
+ nanodbc::string_type binary_type_name = get_binary_type_name();
REQUIRE(!binary_type_name.empty());
nanodbc::string_type const table_name(NANODBC_TEXT("catalog_columns_test"));
@@ -252,11 +324,9 @@
REQUIRE(columns.next());
REQUIRE(columns.column_name() == NANODBC_TEXT("c2"));
- REQUIRE(columns.sql_data_type() == SQL_FLOAT);
- if (columns.numeric_precision_radix() == 10)
- REQUIRE(columns.column_size() == 17); // total number of digits allowed
- else
- REQUIRE(columns.column_size() == 53); // total number of bits allowed
+ REQUIRE(columns.sql_data_type() == get_data_type(NANODBC_TEXT("float")));
+ REQUIRE(columns.column_size() ==
+ get_data_type_size(NANODBC_TEXT("float"), columns.numeric_precision_radix()));
REQUIRE(columns.nullable() == SQL_NULLABLE);
if (!columns.is_nullable().empty()) // nullability determined
REQUIRE(columns.is_nullable() == NANODBC_TEXT("YES"));
@@ -290,7 +360,7 @@
REQUIRE(columns.column_name() == NANODBC_TEXT("c7"));
REQUIRE((columns.sql_data_type() == SQL_LONGVARCHAR || columns.sql_data_type() == SQL_WLONGVARCHAR));
// PostgreSQL uses MaxLongVarcharSize=8190, which is configurable in odbc.ini
- REQUIRE((columns.column_size() == 2147483647 || columns.column_size() == 8190)); // TODO: confirm "text" max length
+ REQUIRE(columns.column_size() == get_data_type_size(NANODBC_TEXT("text")));
REQUIRE(columns.next());
REQUIRE(columns.column_name() == NANODBC_TEXT("c8"));
@@ -308,7 +378,6 @@
void catalog_primary_keys_test()
{
nanodbc::connection connection = connect();
- REQUIRE(connection.connected());
nanodbc::catalog catalog(connection);
// Successfully tested against SQL Server and PostgreSQL (9.x) only.
@@ -321,12 +390,12 @@
execute(connection, NANODBC_TEXT("create table ") + table_name
+ NANODBC_TEXT("(i int NOT NULL, CONSTRAINT pk_simple_test PRIMARY KEY (i));"));
- nanodbc::catalog::primary_keys keys = catalog.find_primary_keys(table_name);
+ nanodbc::catalog::primary_keys keys = catalog.find_primary_keys(table_name);
REQUIRE(keys.next());
REQUIRE(keys.table_name() == table_name);
REQUIRE(keys.column_name() == NANODBC_TEXT("i"));
REQUIRE(keys.column_number() == 1);
- REQUIRE(keys.primary_key_name() == NANODBC_TEXT("pk_simple_test"));
+ REQUIRE(keys.primary_key_name() == get_primary_key_name(NANODBC_TEXT("pk_simple_test")));
// expect no more records
REQUIRE(!keys.next());
}
@@ -338,18 +407,18 @@
execute(connection, NANODBC_TEXT("create table ") + table_name
+ NANODBC_TEXT("(a int, b smallint, CONSTRAINT pk_composite_test PRIMARY KEY(a, b));"));
- nanodbc::catalog::primary_keys keys = catalog.find_primary_keys(table_name);
+ nanodbc::catalog::primary_keys keys = catalog.find_primary_keys(table_name);
REQUIRE(keys.next());
REQUIRE(keys.table_name() == table_name);
REQUIRE(keys.column_name() == NANODBC_TEXT("a"));
REQUIRE(keys.column_number() == 1);
- REQUIRE(keys.primary_key_name() == NANODBC_TEXT("pk_composite_test"));
+ REQUIRE(keys.primary_key_name() == get_primary_key_name(NANODBC_TEXT("pk_composite_test")));
REQUIRE(keys.next());
REQUIRE(keys.table_name() == table_name);
REQUIRE(keys.column_name() == NANODBC_TEXT("b"));
REQUIRE(keys.column_number() == 2);
- REQUIRE(keys.primary_key_name() == NANODBC_TEXT("pk_composite_test"));
+ REQUIRE(keys.primary_key_name() == get_primary_key_name(NANODBC_TEXT("pk_composite_test")));
// expect no more records
REQUIRE(!keys.next());
@@ -359,7 +428,6 @@
void catalog_tables_test()
{
nanodbc::connection connection = connect();
- REQUIRE(connection.connected());
nanodbc::catalog catalog(connection);
// Successfully tested against SQL Server and PostgreSQL (9.x) only.
@@ -672,7 +740,6 @@
void null_test()
{
nanodbc::connection connection = connect();
- REQUIRE(connection.connected());
drop_table(connection, NANODBC_TEXT("null_test"));
execute(connection, NANODBC_TEXT("create table null_test (a int, b varchar(10));"));
@@ -709,7 +776,6 @@
void simple_test()
{
nanodbc::connection connection = connect();
- REQUIRE(connection.connected());
REQUIRE(connection.native_dbc_handle());
REQUIRE(connection.native_env_handle());
REQUIRE(connection.transactions() == std::size_t(0));
@@ -822,7 +888,6 @@
void string_test()
{
nanodbc::connection connection = connect();
- REQUIRE(connection.connected());
REQUIRE(connection.native_dbc_handle());
REQUIRE(connection.native_env_handle());
REQUIRE(connection.transactions() == std::size_t(0));
@@ -849,10 +914,12 @@
void transaction_test()
{
nanodbc::connection connection = connect();
- REQUIRE(connection.connected());
drop_table(connection, NANODBC_TEXT("transaction_test"));
- execute(connection, NANODBC_TEXT("create table transaction_test (i int);"));
+ if (vendor_ == MySQL)
+ execute(connection, NANODBC_TEXT("create table transaction_test (i int) ENGINE = INNODB;"));
+ else
+ execute(connection, NANODBC_TEXT("create table transaction_test (i int);"));
nanodbc::statement statement(connection);
prepare(statement, NANODBC_TEXT("insert into transaction_test (i) values (?);"));
diff -Naur nanodbc-2.12.4/test/CMakeLists.txt nanodbc-2.12.4-patched/test/CMakeLists.txt
--- nanodbc-2.12.4/test/CMakeLists.txt 2016-03-22 00:55:36.000000000 +0300
+++ nanodbc-2.12.4-patched/test/CMakeLists.txt 2018-05-15 08:31:25.040141200 +0300
@@ -23,20 +23,18 @@
file(GLOB headers *.h *.hpp)
add_custom_target(tests DEPENDS tests catch)
set(test_list mysql odbc sqlite)
-foreach(test_item ${test_list})
- set(test_name ${test_item}_tests)
- add_executable(${test_name} ${test_item}_test.cpp ${headers})
- add_dependencies(${test_name} catch)
- if (NANODBC_STATIC)
- target_link_libraries(${test_name} nanodbc ${ODBC_LIBRARIES})
- else()
- target_link_libraries(${test_name} nanodbc "${ODBC_LINK_FLAGS}")
- endif()
- add_test(NAME ${test_name} COMMAND ${test_name})
- add_custom_target(${test_item}_test
- COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure -R ${test_name})
- add_custom_target(${test_item}_check
- COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure -R ${test_name}
- DEPENDS ${test_name})
- add_dependencies(tests ${test_name})
+foreach(config "" "_unicode")
+ foreach(test_item ${test_list})
+ set(test_name ${test_item}${config}_tests)
+ add_executable(${test_name} ${test_item}_test.cpp ${headers})
+ add_dependencies(${test_name} catch)
+ target_link_libraries(${test_name} nanodbc${config}_shared)
+ add_test(NAME ${test_name} COMMAND ${test_name})
+ add_custom_target(${test_item}${config}_test
+ COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure -R ${test_name})
+ add_custom_target(${test_item}${config}_check
+ COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure -R ${test_name}
+ DEPENDS ${test_name})
+ add_dependencies(tests ${test_name})
+ endforeach()
endforeach()