$ wget http://www.unixodbc.org/unixODBC-2.3.4.tar.gz
$ tar xvf unixODBC-2.3.4.tar.gz
$ cd unixODBC-2.3.4
$ ./configure
$ make
$ make install
# 버전 확인
$ odbcinst -j
unixODBC 2.3.4
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
mysql odbc driver 설치
$ yum -y install mysql-connector-odbc.x86_64
$ vi /usr/local/etc/odbcinst.ini
[mysql]
Description = Mysql ODBC Driver
Driver64 = /usr/lib64/libmyodbc5.so
Setup64 = /usr/lib64/libodbcmyS.so
본론
odbc lib 빌드
$ git clone https://github.com/lexicalunit/nanodbc
$ cd nanodbc/
$ git checkout v2.12.4
$ mkdir build.release
$ cd build.release
$ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
$ make
$ make install
샘플 코드
샘플 코드 실행
$ g++ -std=c++11 helloodbc.cpp -o helloodbc -lnanodbc
$ ./helloodbc
Connected with driver libmyodbc5w.so
Displaying 4 rows (1 fetched at a time):
row a b
0 (1) (one)
1 (2) (two)
2 (3) (tri)
3 (null) (z)
1, one
Displaying 8 rows (1 fetched at a time):
row a b
0 (1) (one)
1 (2) (two)
2 (3) (tri)
3 (null) (z)
4 (8) (eight)
5 (null) (null)
6 (null) (null)
7 (null) (null)
deleting all rows ... still have 8 rows!
Displaying 4 rows (3 fetched at a time):
row x y z
0 (this) (1) (1)
1 (P) (2) (2)
2 (libmyodb) (3) (3)
3 p�Ó«) (4) (4)
2016-9-23
Displaying -1 rows (1 fetched at a time):
row x
0 (2016-09-23 15:45:28 +0000)
Displaying 13 rows (1 fetched at a time):
row a b
0 (1) (one)
1 (2) (two)
2 (3) (tri)
3 (null) (z)
4 (8) (eight)
5 (null) (null)
6 (null) (null)
7 (null) (null)
8 (null) (null)
9 (88) (I¯p)
10 (null) (null)
11 (null) (null)
12 (null) (null)
Displaying 15 rows (1 fetched at a time):
row a b
0 (1) (one)
1 (2) (two)
2 (3) (tri)
3 (null) (z)
4 (8) (eight)
5 (null) (null)
6 (null) (null)
7 (null) (null)
8 (null) (null)
9 (88) (I¯p)
10 (null) (null)
11 (null) (null)
12 (null) (null)
13 (null) (null)
14 (42) ()