Giter VIP home page Giter VIP logo

sqlpp11-connector-odbc's Introduction

sqlpp11-connector-odbc

ODBC connector for sqlpp11

Sample Code:

namespace odbc = sqlpp::odbc;
int main() {
 	odbc::connection_config config;
 	//DSN between [ ] in odbc.ini for unixodbc
 	config.data_source_name = "MyDSN";
 	//Database to use. Leave empty to execute your own USE statement
	config.database = "my_schema";
	//Username for data source
	config.username = "user";
	//Authentication for data source
	config.password = "password";
	
	//Valid types currently include MySQL, PostgreSQL, SQLite3, or TSQL
	//This is used to get the last insert ID, used by insert function
	config.type = odbc::connection_config::ODBC_Type::MySQL;
	config.debug = true;
	odbc::connection db(config);
	...
}

Requirements:

Compiler: sqlpp11-connector-odbc makes use of C++11 and requires a recent compiler and STL. The following compilers are known to compile the test programs:

  • g++-7.2.0 on Arch Linux as of 2017-10-25
  • Visual Studio on Windows 7 using LLVM toolset as of 2017-10-29

C++ SQL Layer: sqlpp11-connector-odbc depends on sqlpp11 (https://github.com/rbock/sqlpp11).

ODBC: Appropriate ODBC library (like unixodbc or Windows's ODBC library), and ODBC connector capable of ODBC 3.0 or higher. Tested with unixodbc 2.3.4.

Threading: Using the same sqlpp::odbc::connection object on multiple threads is not safe. Instead, pass the sqlpp::odbc::connection_config to create a new connection (which may be safe depending on your ODBC connector) or use mutexes.

Wide Strings: While sqlpp11-connector-odbc should compile on Windows (possibly with some modifications), sqlpp11 uses std::string and std::ostream.

Windows: To build on Windows for 64 bit, first build and install sqlpp11:

mkdir sqlpp11/build
cd sqlpp11/build
cmake .. -G"Visual Studio 15 2017 Win64" -T"LLVM-vs2014" -DHinnantDate_ROOT_DIR="C:/Users/myuser/source/repos/date/include"
# Use VS 2017 to build INSTALL project
# As admin, run the Post Build script for INSTALL project

Then you can build sqlpp11-connector-odbc the same way.

sqlpp11-connector-odbc's People

Contributors

erroneous1 avatar psykora avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sqlpp11-connector-odbc's Issues

cmake checking block unixODBC

I found that the CMake/Modules/FindODBC.cmake is not able to find the libraries installed by unixODBC, because the file installed by latter on is named libodbc but the cmake checking only checks for unixodbc or iodbc.
Please check odbc instead.

cmake error at cmakeLists.txt:39 (include directories)

I am using cmake to build on Windows and VS2019.
sqlpp11 is installed through VCPKG

cmake .. -G"Visual Studio 16 2019" -A Win32 -DCMAKE_TOOLCHAIN_FILE="D:\Tools\vcpkg\scripts\buildsystems\vcpkg.cmake" -DSQLPP11_ODBC_DISABLE_SHARED=ON

results in

-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.17763.
-- The CXX compiler identification is MSVC 19.28.29337.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x86/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ODBC: C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/um
-- Configuring done
CMake Error at CMakeLists.txt:39 (include_directories):
  Error evaluating generator expression:

    $<TARGET_PROPERTY:sqlpp11,INTERFACE_INCLUDE_DIRECTORIES>

  Target "sqlpp11" not found.

When i remove line 39 it works:
include_directories(${HinnantDate_INCLUDE_DIR} $<TARGET_PROPERTY:sqlpp11,INTERFACE_INCLUDE_DIRECTORIES>)

Better return failure return types

Hi,

MSVC users had a hard time debugging certain sqlpp11 errors, since MSVC did not run into the same static_assert as other compilers. As a result

  • I needed to find a better error reporting strategy
  • I am giving a talk about this at CppCon and MeetingC++ :-)
  • I just pushed a new release of sqlpp11 that is using more differentiated failure return types.

This has a small impact on the connector libraries as well. You should update your code like this:

See rbock/sqlpp11-connector-sqlite3@f2cd303

Best,

Roland

Allow SQLDriverConnect instead of SQLConnect

Currently the ODBC connector is using SQLConnect which requires datasource to be defined in the system (Windows) or ini file (Unix).

It would be nice to be able to specify connection string during runtime. Something like this (example for MSSQL server)
Driver={SQL Server};Server=SERVER_HOSTNAME\INSTANCE;Database=DBNAME;Uid=DBUSER;Pwd=DBPASS;

prepare doesnt work.

Prepare doesnt work. I have to specify the prepare_select. Looks there are missing bytes

_auto querystring = prepare_quote_query (quotation);
auto query= sqlpp::custom_query (sqlpp::verbatim(prepare_quote_query(quotation)));
std::cout << "QUERY TO BE EXECUTED: " << querystring << std::endl;
rating::RateTable table;
// auto result2 = (*db) (query).with_result_type_of(select(all_of(table)));
auto p = db->prepare_select(query);

root@Giorgio:/home/giorgio/redis/redisperformance# make
Scanning dependencies of target test_rateservice
[ 12%] Building CXX object CMakeFiles/test_rateservice.dir/test/test_rate_executor.cpp.o
[ 25%] Building CXX object CMakeFiles/test_rateservice.dir/src/rate_executor.cpp.o
In file included from /usr/local/include/sqlpp11/odbc/odbc.h:31,
from /home/giorgio/redis/redisperformance/include/rate_executor.h:4,
from /home/giorgio/redis/redisperformance/src/rate_executor.cpp:20:
/usr/local/include/sqlpp11/odbc/connection.h: In instantiation of ‘decltype (((sqlpp::odbc::connection*)this)->sqlpp::odbc::connection::_prepare(t, typename sqlpp::prepare_check<sqlpp::odbc::serializer_t, T, void>::type::type{})) sqlpp::odbc::connection::prepare(const T&) [with T = sqlpp::custom_query_t<void, sqlpp::verbatim_tsqlpp::no_value_t >; decltype (((sqlpp::odbc::connection*)this)->sqlpp::odbc::connection::prepare(t, typename sqlpp::prepare_check<sqlpp::odbc::serializer_t, T, void>::type::type{})) = sqlpp::prepared_execute_t<sqlpp::odbc::connection, sqlpp::custom_query_t<void, sqlpp::verbatim_tsqlpp::no_value_t > >]’:
/home/giorgio/redis/redisperformance/src/rate_executor.cpp:91:31: required from here
/usr/local/include/sqlpp11/odbc/connection.h:253:56: error: ‘
’ is not a member of ‘sqlpp::prepare_check_t<sqlpp::odbc::serializer_t, sqlpp::custom_query_t<void, sqlpp::verbatim_tsqlpp::no_value_t > >’ {aka ‘sqlpp::consistent_t’}
sqlpp::prepare_check_t<serializer_context_t, T>::();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

Compilation failure with Visual Studio 2017 15.8

CL version:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.15.26732.1 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]
"C:\nph\Code\sqlpp11\sqlpp11-connector-odbc\build\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\nph\Code\sqlpp11\sqlpp11-connector-odbc\build\tests\ODBCTest.vcxproj" (default target) (3) ->
(ClCompile target) ->
  c:\nph\code\sqlpp11\sqlpp11-connector-odbc\include\sqlpp11\odbc\insert_or.h(50): error C2070: 'const char []': illega
l sizeof operand [C:\nph\Code\sqlpp11\sqlpp11-connector-odbc\build\tests\ODBCTest.vcxproj]
  c:\nph\code\sqlpp11\sqlpp11_install\include\sqlpp11\detail\index_sequence.h(49): fatal error C1202: recursive type or
 function dependency context too complex [C:\nph\Code\sqlpp11\sqlpp11-connector-odbc\build\tests\ODBCTest.vcxproj]

    48 Warning(s)
    2 Error(s)

Replacing:

static constexpr const char _literal[] = "insert_or";

with:

static constexpr auto _literal = "insert_or";

fixed the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.