This has not been tested with the freetds unixodbc driver. This is how I install unixodbc with postgres or mysql. http://k3ut0i.imtqy.com/linux/2015/08/09/odbc-setup-linux.html
The global driver and data source configuration for ODBC is located in /etc/odbc.ini and /etc/odbcinst.ini . some operating systems may have these files empty or with different names. Here are my configuration files.
Drivers, libraries in /etc/odbcinst.ini.
[MySQL] Description = ODBC driver for mariaDB Driver = /usr/lib/libmyodbc.so Setup = /usr/lib/libmyodbc5S.so FileUsage = 1
The pyodbc function in the python file is equivalent to the data source in /etc/odbc.ini.
[mariadb-connector] Description = connection to test database for mariadb Driver = MySQL Database = test Server = 127.0.0.1 UserName = keutoi Trace = No Port = 3306
The piece of code that connects and requests. I just started with your link and cleaned it.
/** * Connect to data source named in /etc/odbc.ini file */ retcode = SQLDriverConnect(hdbc, NULL, (SQLCHAR*)"DSN=mariadb-connector;", SQL_NTS, outstr, sizeof(outstr), &outstrlen, SQL_DRIVER_COMPLETE); check_error(retcode, "connect to the data source"); //Allocate statement handle retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); check_error(retcode, "allocate a statement handle"); /** * statement to be executed. */ retcode = SQLExecDirect (hstmt, (SQLCHAR *) "select * from mytable", SQL_NTS); check_error(retcode, "execute the statement"); /** * Bind a column to a variable */ retcode = SQLBindCol(hstmt, 1, SQL_C_CHAR, szName, NAME_LEN, &cbName); check_error(retcode, "bind 1 column to the statement"); retcode = SQLBindCol(hstmt, 2, SQL_C_CHAR, szID, ID_LEN, &cbID); check_error(retcode, "bind 2 column to the statement"); /** * fetch sql hstmt untill there is no data and print */ for (int i=0 ; ; i++) { retcode = SQLFetch(hstmt); if(retcode == SQL_NO_DATA)break; else printf( "%d: %s %s %s\n", i + 1, szID, szName); }
Full example here . Compile with g++ file.cc -lodbc