Git Product home page Git Product logo

odbc-cpp-wrapper's Introduction

C++ Wrapper for ODBC

REUSE status

odbc-cpp-wrapper is an object-oriented C++-wrapper of the ODBC API. It takes care of

  • managing the lifetime of ODBC resources,
  • allocating and managing resources needed for ODBC operations and
  • converting ODBC errors to exceptions and throwing them.

The odbc-cpp-wrapper API attempts to make usage of ODBC as simple as possible. The API was designed to make wrong usage almost impossible and to ensure proper object lifetime management.

odbc-cpp-wrapper was originally developed for exchanging spatial data with databases. It focuses on batch operations of variable-sized data, which is not very well supported by other ODBC wrappers.

Requirements

To build odbc-cpp-wrapper you need

On Linux platforms you additionally need

To generate the API's documentation, you need

Building and Installation

Linux

  • Clone the repository:

    git clone https://github.com/SAP/odbc-cpp-wrapper.git
    
  • Create a build directory and change to it:

    mkdir odbc-cpp-wrapper/build && cd odbc-cpp-wrapper/build
    
  • Create the makefiles with CMake:

    cmake ..
    
  • Build the library:

    make -j <number of parallel build jobs>
    

    The build will create a shared library libodbccpp.so and a static library libodbccpp_static.a.

  • To build the documentation (optional):

    make doc
    

    The mainpage of the documentation can be found at doc/html/index.html.

  • Install the library:

    sudo make install
    

    This will install the library and header files. CMake will install them to usr/local/lib and usr/local/include by default. If you prefer different locations, you can set CMake's install prefix to a different path. See https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html for details.

Windows

  • Clone the repository:

    git clone https://github.com/SAP/odbc-cpp-wrapper.git
    
  • Create a build directory and change to it:

    mkdir odbc-cpp-wrapper\build && cd odbc-cpp-wrapper\build
    

Visual Studio 2015 and later

  • Generate a Visual Studio solution

    cmake ..
    

    You can then open the odbccpp.sln file and build the desired targets in Visual Studio.

MSBuild (nmake)

  • Start the Visual Studio Native Tools Command Prompt for the desired target and change the directory to the build directory. Create the makefiles for nmake:

    cmake -G "NMake Makefiles" ..
    

    Optionally you can use CMAKE_BUILD_TYPE to define if you'd like to build a Debug or Release build. See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html for details.

  • Build the library:

    nmake
    

    The build will create a dynamic link library odbccpp.dll and a static library odbccpp_static.lib.

  • Build the documentation (optional):

    nmake doc
    

    The mainpage of the documentation can be found at doc\html\index.html.

  • Install the library (optional):

    nmake install
    

    This will install the library and header files. CMake will install them to C:\Program Files\odbccpp by default. If you prefer a different location, you can set CMake's install prefix to a different path. See https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html for details.

Using the library

You can just link against the shared/dynamic or the static library. If you are linking against the static library, you have to additionally define ODBC_STATIC when compiling.

Usage of the library should be pretty straight-forward if you are familiar with ODBC and/or other database connectors.

Example

The following code gives an example how working with odbc-cpp-wrapper looks like. It connects to a database, batch inserts two rows and executes a query.

#include <iostream>
#include <odbc/Connection.h>
#include <odbc/Environment.h>
#include <odbc/Exception.h>
#include <odbc/PreparedStatement.h>
#include <odbc/ResultSet.h>

int main()
{
    try
    {
        odbc::EnvironmentRef env = odbc::Environment::create();

        odbc::ConnectionRef conn = env->createConnection();
        conn->connect("DSN", "user", "pass");
        conn->setAutoCommit(false);

        odbc::PreparedStatementRef psInsert =
            conn->prepareStatement("INSERT INTO TAB (ID, DATA) VALUES (?, ?)");
        psInsert->setInt(1, 101);
        psInsert->setCString(2, "One hundred one");
        psInsert->addBatch();
        psInsert->setInt(1, 102);
        psInsert->setCString(2, "One hundred two");
        psInsert->addBatch();
        psInsert->executeBatch();
        conn->commit();

        odbc::PreparedStatementRef psSelect =
            conn->prepareStatement("SELECT ID, DATA FROM TAB WHERE ID > ?");
        psSelect->setInt(1, 100);
        odbc::ResultSetRef rs = psSelect->executeQuery();
        while (rs->next())
        {
            std::cout << rs->getInt(1) << ", " << rs->getString(2) << std::endl;
        }
    }
    catch (const odbc::Exception& e)
    {
        std::cerr << e.what() << std::endl;
    }
}

How to obtain support

If you experience issues with using the library, please file a report in the GitHub bug tracking system.

License

Copyright 2019-2021 SAP SE or an SAP affiliate company and odbc-cpp-wrapper contributors. Please see our LICENSE for copyright and license information. Please note the GPLv2 Combination Exception for the Apache 2 License! Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.

odbc-cpp-wrapper's People

Contributors

csmu-cenr avatar jonathanbaker7 avatar mrylov avatar sebastianwolf-sap avatar stefanuhrig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar

odbc-cpp-wrapper's Issues

On MacOS 13.3 ld: symbol(s) not found for architecture xxx

Hello,

I get a linker error when compiling the sample program.
I tried on

  • Mac mini : Intel i5 : Ventura 13.3
  • MacBook Pro : Apple M1 Pro : macOS Ventura 13.3

I have the same error on both. ld: symbols(s) not found for architecture xxx.

The prereq unixodbc and odbc-cpp-wrapper:

isql test_42
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| echo [string]                         |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> quit


sudo make install
Password:
[ 41%] Built target odbccpp_static
[ 83%] Built target odbccpp
[100%] Built target OdbcCppTest
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/lib/libodbccpp_static.a
-- Up-to-date: /usr/local/lib/libodbccpp.dylib
-- Up-to-date: /usr/local/include/odbc/Config.h
-- Up-to-date: /usr/local/include/odbc/Connection.h
-- Up-to-date: /usr/local/include/odbc/DatabaseMetaData.h
-- Up-to-date: /usr/local/include/odbc/DatabaseMetaDataBase.h
-- Up-to-date: /usr/local/include/odbc/DatabaseMetaDataUnicode.h
-- Up-to-date: /usr/local/include/odbc/Environment.h
-- Up-to-date: /usr/local/include/odbc/Exception.h
-- Up-to-date: /usr/local/include/odbc/Forwards.h
-- Up-to-date: /usr/local/include/odbc/ParameterMetaData.h
-- Up-to-date: /usr/local/include/odbc/PreparedStatement.h
-- Up-to-date: /usr/local/include/odbc/RefCounted.h
-- Up-to-date: /usr/local/include/odbc/ResultSet.h
-- Up-to-date: /usr/local/include/odbc/ResultSetMetaData.h
-- Up-to-date: /usr/local/include/odbc/ResultSetMetaDataBase.h
-- Up-to-date: /usr/local/include/odbc/ResultSetMetaDataUnicode.h
-- Up-to-date: /usr/local/include/odbc/Statement.h
-- Up-to-date: /usr/local/include/odbc/StatementBase.h
-- Up-to-date: /usr/local/include/odbc/StringConverter.h
-- Up-to-date: /usr/local/include/odbc/Types.h
-- Up-to-date: /usr/local/include/odbc/Util.h

The program taken from github

#include <iostream>
#include <odbc/Connection.h>
#include <odbc/Environment.h>
#include <odbc/Exception.h>
#include <odbc/PreparedStatement.h>
#include <odbc/ResultSet.h>

int main()
{
    try
    {
        odbc::EnvironmentRef env = odbc::Environment::create();

        odbc::ConnectionRef conn = env->createConnection();
        conn->connect("DSN", "user", "pass");
        conn->setAutoCommit(false);

        odbc::PreparedStatementRef psInsert =
            conn->prepareStatement("INSERT INTO TAB (ID, DATA) VALUES (?, ?)");
        psInsert->setInt(1, 101);
        psInsert->setCString(2, "One hundred one");
        psInsert->addBatch();
        psInsert->setInt(1, 102);
        psInsert->setCString(2, "One hundred two");
        psInsert->addBatch();
        psInsert->executeBatch();
        conn->commit();

        odbc::PreparedStatementRef psSelect =
            conn->prepareStatement("SELECT ID, DATA FROM TAB WHERE ID > ?");
        psSelect->setInt(1, 100);
        odbc::ResultSetRef rs = psSelect->executeQuery();
        while (rs->next())
        {
            std::cout << rs->getInt(1) << ", " << rs->getString(2) << std::endl;
        }
    }
    catch (const odbc::Exception& e)
    {
        std::cerr << e.what() << std::endl;
    }
}

My issue

gcc -v -std=c++11 main.cpp
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: x86_64-apple-darwin22.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx13.0.0 -Wundef-prefix=TARGET_OS_ -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fno-strict-return -ffp-contract=on -fno-rounding-math -funwind-tables=2 -target-sdk-version=13.3 -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=lldb -target-linker-version 857.1 -v -fcoverage-compilation-dir=/Users/michel/src/test_odbc/test_odbc -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/14.0.3 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/14.0.3/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/usr/include -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -Wno-elaborated-enum-base -Wno-reserved-identifier -Wno-gnu-folding-constant -std=c++11 -fdeprecated-macro -fdebug-compilation-dir=/Users/michel/src/test_odbc/test_odbc -ferror-limit 19 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fno-cxx-modules -no-opaque-pointers -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcommon -fcolor-diagnostics -clang-vendor-feature=+disableNonDependentMemberExprInCurrentInstantiation -fno-odr-hash-protocols -clang-vendor-feature=+enableAggressiveVLAFolding -clang-vendor-feature=+revert09abecef7bbf -clang-vendor-feature=+thisNoAlignAttr -clang-vendor-feature=+thisNoNullAttr -mllvm -disable-aligned-alloc-awareness=1 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/dw/9qv77fv97rg6ww8y9r2d029c0000gn/T/main-a6c492.o -x c++ main.cpp
clang -cc1 version 14.0.3 (clang-1403.0.22.14.1) default target x86_64-apple-darwin22.4.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1
 /Library/Developer/CommandLineTools/usr/lib/clang/14.0.3/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library /Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -platform_version macos 13.0.0 13.3 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o a.out -L/usr/local/lib /var/folders/dw/9qv77fv97rg6ww8y9r2d029c0000gn/T/main-a6c492.o -lSystem /Library/Developer/CommandLineTools/usr/lib/clang/14.0.3/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "odbc::Connection::setAutoCommit(bool)", referenced from:
      _main in main-a6c492.o
  "odbc::Connection::prepareStatement(char const*)", referenced from:
      _main in main-a6c492.o
  "odbc::Connection::commit()", referenced from:
      _main in main-a6c492.o
  "odbc::Connection::connect(char const*, char const*, char const*)", referenced from:
      _main in main-a6c492.o
  "odbc::Environment::createConnection()", referenced from:
      _main in main-a6c492.o
  "odbc::Environment::create()", referenced from:
      _main in main-a6c492.o
  "odbc::PreparedStatement::setCString(unsigned short, char const*)", referenced from:
      _main in main-a6c492.o
  "odbc::PreparedStatement::executeBatch()", referenced from:
      _main in main-a6c492.o
  "odbc::PreparedStatement::executeQuery()", referenced from:
      _main in main-a6c492.o
  "odbc::PreparedStatement::setInt(unsigned short, odbc::Nullable<int> const&)", referenced from:
      _main in main-a6c492.o
  "odbc::PreparedStatement::addBatch()", referenced from:
      _main in main-a6c492.o
  "odbc::ResultSet::next()", referenced from:
      _main in main-a6c492.o
  "odbc::ResultSet::getInt(unsigned short)", referenced from:
      _main in main-a6c492.o
  "odbc::ResultSet::getString(unsigned short)", referenced from:
      _main in main-a6c492.o
  "odbc::RefCounted::decRef() const", referenced from:
      odbc::Reference<odbc::Environment>::free_() in main-a6c492.o
      odbc::Reference<odbc::Connection>::free_() in main-a6c492.o
      odbc::Reference<odbc::PreparedStatement>::free_() in main-a6c492.o
      odbc::Reference<odbc::ResultSet>::free_() in main-a6c492.o
  "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
      std::__1::ctype<char> const& std::__1::use_facet[abi:v15006]<std::__1::ctype<char>>(std::__1::locale const&) in main-a6c492.o
  "std::__1::ios_base::getloc() const", referenced from:
      std::__1::basic_ios<char, std::__1::char_traits<char>>::widen[abi:v15006](char) const in main-a6c492.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::__init(unsigned long, char)", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string[abi:v15006](unsigned long, char) in main-a6c492.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::~basic_string()", referenced from:
      odbc::Nullable<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>::~Nullable() in main-a6c492.o
      std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>> std::__1::__pad_and_output<char, std::__1::char_traits<char>>(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>, char const*, char const*, char const*, std::__1::ios_base&, char) in main-a6c492.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char>>::put(char)", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::endl<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&) in main-a6c492.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char>>::flush()", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::endl<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&) in main-a6c492.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char>>::sentry::sentry(std::__1::basic_ostream<char, std::__1::char_traits<char>>&)", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in main-a6c492.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char>>::sentry::~sentry()", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in main-a6c492.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char>>::operator<<(int)", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char>>& odbc::operator<<<int>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, odbc::Nullable<int> const&) in main-a6c492.o
  "std::__1::cerr", referenced from:
      _main in main-a6c492.o
  "std::__1::cout", referenced from:
      _main in main-a6c492.o
  "std::__1::ctype<char>::id", referenced from:
      std::__1::ctype<char> const& std::__1::use_facet[abi:v15006]<std::__1::ctype<char>>(std::__1::locale const&) in main-a6c492.o
  "std::__1::locale::~locale()", referenced from:
      std::__1::basic_ios<char, std::__1::char_traits<char>>::widen[abi:v15006](char) const in main-a6c492.o
  "std::__1::ios_base::__set_badbit_and_consider_rethrow()", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in main-a6c492.o
  "std::__1::ios_base::clear(unsigned int)", referenced from:
      std::__1::ios_base::setstate[abi:v15006](unsigned int) in main-a6c492.o
  "std::terminate()", referenced from:
      ___clang_call_terminate in main-a6c492.o
  "typeinfo for odbc::Exception", referenced from:
      GCC_except_table0 in main-a6c492.o
  "___cxa_begin_catch", referenced from:
      _main in main-a6c492.o
      ___clang_call_terminate in main-a6c492.o
      std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in main-a6c492.o
  "___cxa_end_catch", referenced from:
      _main in main-a6c492.o
      std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in main-a6c492.o
  "___gxx_personality_v0", referenced from:
      _main in main-a6c492.o
      std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in main-a6c492.o
      std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>> std::__1::__pad_and_output<char, std::__1::char_traits<char>>(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>, char const*, char const*, char const*, std::__1::ios_base&, char) in main-a6c492.o
      std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>::ostreambuf_iterator[abi:v15006](std::__1::basic_ostream<char, std::__1::char_traits<char>>&) in main-a6c492.o
      std::__1::basic_ios<char, std::__1::char_traits<char>>::widen[abi:v15006](char) const in main-a6c492.o
      odbc::Reference<odbc::Environment>::~Reference() in main-a6c492.o
      odbc::Reference<odbc::Connection>::~Reference() in main-a6c492.o
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Adding path to unixodbc lib doesn't help

gcc -v -std=c++11 -L/usr/local/Cellar/unixodbc/2.3.11/lib main.cpp
...
ld: symbol(s) not found for architecture x86_64

Thanks in advance for your help

[Windows 10] "HY090 Invalid string or buffer length" error

If i use connection string:
conn->connect("DSN='demo';Driver={SQL Server };SERVER=.\SQLEXPRESS;Database=DEMO;", NULL, NULL);
i get an error "HY090 Invalid string or buffer length"

What connection string to use without using ODBC Administrator?

Thank you!

Licence : GPLv2 compatibility

Hello,

This library is licensed as Apache v2. This license is not compatible with GPLv2, making it impossible to link odbc-cpp-wrapper with any software licensed as GPLv2. Note that Apache 2 is compatible with GPLv3.

The problem occurs with this PR for QGIS : qgis/QGIS#30734

QGIS is GPLv2+, the PR adds code and a dependency on odbc-cpp-wrapper, through dynamic linking. This could be ok, under the condition that QGIS with this addition would be distributed as GPLv3.
But at the same time, it would prevent distributing QGIS with a link to any other library not compatible with GPLv3, which is really annoying.

A solution would be to add an exception to the Apache 2 licence of this software, so as to make it explicitly compatible with GPLv2.
The subject has already been discussed in various places, and such an exception already proposed : 

Would SAP be ready to add such an exception to the license, so as to ease the integration of this library ?

Problem of "[Microsoft][ODBC Driver 17 for SQL Server]Invalid Descriptor Index"

My program run on RHEL7 , unixODBC2.3.1 , msodbcsql17-17.9.1.1
It run ok with following
while(rs->next()) {
std::cout<< rs->getString(3) << "," << rs->getString(2) << "," << rs->getInt(1);

However, got exception of "[Microsoft][ODBC Driver 17 for SQL Server]Invalid Descriptor Index" with following
while(rs->next()) {
for(int i=3; i<=1;--) {
std::cout << rs->getString(i) << (i>1?",":"");

odbc pop some errors by the prepareStatement to batch insert into table values

my connectionstring is : "Driver={MySQL ODBC 5.3 Unicode Driver};Server=127.0.0.1;Port=3306;Database=test;User=root;Password=root;Option=67108864;CharSet=utf8mb4;stmt=SET NAMES utf8mb4;"

m_odbc_connection->setAutoCommit(false);
std::string str = "INSERT INTO T(A,B) VALUES (?,?)";
auto statement = m_odbc_connection->prepareStatement(str.data());
statement->setInt(1, 1);
statement->setString(2, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");//more than 32 char,it's an error
statement->addBatch();
statement->setInt(1, 1);
statement->setString(2, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
statement->addBatch();
statement->executeBatch();
m_odbc_connection->commit();

pop errors: ERROR: 0: HYC00 : [MySQL][ODBC 5.3(w) Driver][mysqld-5.7.29]Parameter arrays with data at execution are not supported

Error HY104 on Parameter of Type cString

I am trying to get your wrapper to work with MS SQL Server 2014.
To test it, i already created a TAB table with two Fiels.
ID = int
DATA = varchar(50)

But on this Statement, i get the errorcode posted in the description.

odbc::PreparedStatementRef psInsert =
conn->prepareStatement ("INSERT INTO TAB (ID, DATA) VALUES (?, ?)");
psInsert->setInt (1, 101);
psInsert->setCString (2, "One hundred one");
psInsert->executeQuery ();

You set the ColumnSize parameter of "SQLBindParameter" from the Member "columnSize_"
But this is always 0, because ParameterData::setValue sets always 0.

So would this be a bug?
Or just a problem with older versions?

Because i just cant wrap my head around the documentation of SQLBindParameter:
https://docs.microsoft.com/de-de/sql/odbc/reference/syntax/sqlbindparameter-function?view=sql-server-ver15

Installation in Windows

We would like to understand how to register or install the odbccpp.dll file such that it is part of the list in the Drivers tab of the ODBC Data Source Administrato
Screen Shot 2022-03-09 at 6 09 06 PM

That way client applications can use a data source name and the driver wrapper to then connect to SQL Server. The idea is to have the ability to inspect the SQL and potentially optimize it before submitting it to SQL Server for execution

Thanks!

On MacOS 12.4: odbc-cpp-wrapper/src/odbc/internal/Odbc.h:9:10: fatal error: 'sql.h' file not found

Can it be built on MacOS? And if yes, are there any more dependencies required?

I did brew install gdal and that installed different dependencies, incl unixodbc:

Warning: Building gdal from source as the bottle needs:
- HOMEBREW_CELLAR: /usr/local/Cellar (yours is /usr/local/homebrew/Cellar)
- HOMEBREW_PREFIX: /usr/local (yours is /usr/local/homebrew)
==> Downloading http://download.osgeo.org/gdal/3.5.0/gdal-3.5.0.tar.xz
######################################################################## 100.0%
==> Installing dependencies for gdal: pkg-config, cfitsio, popt, epsilon, expat, freexl, geos, giflib, gmp, isl, mpfr, libmpc, zstd, gcc, libaec, hdf5, jpeg, json-c, bison, readline, libxml2, ca-certificates, [email protected], libdap, libtiff, cmake, m4, libtool, proj, libgeotiff, libpng, krb5, libpq, librttopo, minizip, sqlite, libspatialite, netcdf, openblas, numpy, little-cms2, openjpeg, pcre2, ninja, gdbm, mpdecimal, xz, [email protected], meson, freetype, fontconfig, gettext, libffi, pcre, [email protected], glib, util-macros, xtrans, libpthread-stubs, xorgproto, libxau, libxdmcp, libxcb, libx11, libxext, libxrender, lzo, pixman, cairo, gobject-introspection, nspr, nss, qt@5, poppler-qt5, unixodbc, webp and xerces-c

But when trying to build the wrapper:

I076835@LTV9QWHGWW ProjectsLocal % git clone https://github.com/SAP/odbc-cpp-wrapper.git
Cloning into 'odbc-cpp-wrapper'...
remote: Enumerating objects: 344, done.
remote: Counting objects: 100% (145/145), done.
remote: Compressing objects: 100% (104/104), done.
remote: Total 344 (delta 64), reused 67 (delta 38), pack-reused 199
Receiving objects: 100% (344/344), 170.55 KiB | 3.55 MiB/s, done.
Resolving deltas: 100% (156/156), done.
I076835@LTV9QWHGWW ProjectsLocal % mkdir odbc-cpp-wrapper/build && cd odbc-cpp-wrapper/build
I076835@LTV9QWHGWW build % cmake ..
-- The C compiler identification is AppleClang 13.1.6.13160021
-- The CXX compiler identification is AppleClang 13.1.6.13160021
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ODBC: /usr/local/homebrew/lib/libodbc.dylib
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Could NOT find GTest (missing: GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/I076835/ProjectsLocal/odbc-cpp-wrapper/build
I076835@LTV9QWHGWW build % ls -l
total 72
-rw-r--r--   1 I076835  staff  16692 Jun  7 17:27 CMakeCache.txt
drwxr-xr-x  12 I076835  staff    384 Jun  7 17:27 CMakeFiles
-rw-r--r--   1 I076835  staff    324 Jun  7 17:27 CTestTestfile.cmake
-rw-r--r--   1 I076835  staff   7735 Jun  7 17:27 Makefile
-rw-r--r--   1 I076835  staff   1757 Jun  7 17:27 cmake_install.cmake
drwxr-xr-x   7 I076835  staff    224 Jun  7 17:27 src
I076835@LTV9QWHGWW build % make
[  2%] Building CXX object src/odbc/CMakeFiles/odbccpp_static.dir/Connection.cpp.o
In file included from /Users/I076835/ProjectsLocal/odbc-cpp-wrapper/src/odbc/Connection.cpp:11:
/Users/I076835/ProjectsLocal/odbc-cpp-wrapper/src/odbc/internal/Odbc.h:9:10: fatal error: 'sql.h' file not found
#include <sql.h>
         ^~~~~~~
1 error generated.
make[2]: *** [src/odbc/CMakeFiles/odbccpp_static.dir/Connection.cpp.o] Error 1
make[1]: *** [src/odbc/CMakeFiles/odbccpp_static.dir/all] Error 2
make: *** [all] Error 2

Regards.

Could NOT find ODBC (missing: ODBC_LIBRARY ODBC_INCLUDE_DIR)

I am not much experienced with C++, but I am trying to build this wrapper for GDAL to include access to SAP HANA (https://gdal.org/drivers/vector/hana.html)

I am trying to compile it on
NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
but running into Could NOT find ODBC (missing: ODBC_LIBRARY ODBC_INCLUDE_DIR):

# cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
  Could NOT find ODBC (missing: ODBC_LIBRARY ODBC_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.16/Modules/FindODBC.cmake:198 (find_package_handle_standard_args)
  CMakeLists.txt:7 (FIND_PACKAGE)


-- Configuring incomplete, errors occurred!
See also "/root/odbc-cpp-wrapper/build/CMakeFiles/CMakeOutput.log".

I have unixodbc installed:

# apt info unixodbc
Package: unixodbc
Version: 2.3.6-0.1build1
Priority: optional
Section: universe/libs
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Steve Langasek <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 108 kB
Depends: libc6 (>= 2.14), libodbc1 (>= 2.3.1), libreadline8 (>= 6.0), odbcinst1debian2 (>= 2.3.1)
Homepage: http://www.unixodbc.org/
Download-Size: 24.6 kB
APT-Manual-Installed: yes
APT-Sources: http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages
Description: Basic ODBC tools

What else might I miss?

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.