All Forums Connectivity
Mikec 28 posts Joined 03/09
16 Sep 2009
Connecting Python to Teradata over ODBC

Has anyone ever connected a Python based script to Teradata using the ODBC driver on Linux? We have a Sales Consultant trying to work with a prospect and getting seg faults while using the ODBC driver.
ODBC connect string for Teradata Express 12.0:
DRIVER={Teradata};DBCNAME=localhost;UID=dbc;PWD=dbc; QUIETMODE=YES;
Example interactive Python session: session: >>> conn = >>> pyodbc.connect('DRIVER={Teradata};DBCNAME=localhost; UID=dbc;PWD=dbc; >>> QUIETMODE=YES;') >>> conn
>>> curs = conn.cursor() >>> curs.execute('select current_timestamp')
>>> curs.fetchone() (datetime.datetime(2009, 8, 13, 11, 34, 1, 250), )

MikeC (for jpm185170)

Jimm 298 posts Joined 09/07
17 Sep 2009

The example you gave is from a pyodbc website.
If you "import pyodbc" before running this example, it works fine (at least on Windows)
See below for example.

Can you give me any details on the actual error you are getting?

>>> import pyodbc
>>> conn=pyodbc.connect('DRIVER={Teradata};DBCNAME=localhost;UID=dbc;PWD=dbc;QUIETMODE=YES;')
>>> conn

>>> curs=conn.cursor()
>>> curs.execute('select current_timestamp')

>>> curs.fetchone()
(datetime.datetime(2009, 9, 17, 10, 40, 8, 870), )
>>>

jpm185170 2 posts Joined 09/09
17 Sep 2009

You are correct - that is where the example came from. pyodbc was imported before getting the seg fault. Driver manager is unixODBC on 64 bit, pyodbc is also built on 64 bit. unixODBC's isql tool and the DataDirect driver can connect as long as I specify uid and pwd on the command line -- e.g. #isql testdsn dbc dbc works fine, #isql testdsn returns with error inavlid username,password, or account string - even though they are specified in the dsn. Windows connectivity is fine no problems. I also tried DataDirect's ddtestlib on pyodbc.so to see if it would load ok. Error was "undefined symbol: _Py_TrueStruct". This might have passed me by in the build process and not sure how this might affect connectivity.

The seg faults do not allow any odbc tracing logs or additional information. I've also tried an strace and ltrace, but nothing I can glean from that either.

jpm185170 2 posts Joined 09/09
28 Sep 2009

Resolution
Once we verified the connection was successful by viewing the ODBC Trace, I called in Vittal to help understand why the isql was encountering a SEGV after the connection. We will investigate this failure later as it might be a problem with the ODBC Driver. Since it was verified that the connection was successful we decided to move ahead and try the actual program python. There was an initial problem identified by Vittal that needed to be corrected by adding the defines below and a SQLSetEnvAttr call to set the SQL_ATTR_APP_UNICODE_TYPE attribute in a python module. Recompile pyodbc using "python setup.py build install".

Defines
#define SQL_CONOPT_START 1040
#define SQL_ATTR_APP_UNICODE_TYPE (SQL_CONOPT_START+24)
#define SQL_DD_CP_ANSI 0
#define SQL_DD_CP_UCS2 1
#define SQL_DD_CP_UTF8 2
#define SQL_DD_CP_UTF16 SQL_DD_CP_UCS2

And added the API call to set the SQL_ATTR_APP_UNICODE_TYPE attribute.

odbc_ret_code = SQLSetEnvAttr(henv, SQL_ATTR_APP_UNICODE_TYPE,
(void *) SQL_DD_CP_UTF16, SQL_IS_INTEGER);

Willimoa 63 posts Joined 10/09
30 Aug 2010

Hello, Anyone out there using Python for database updates ?
I am having trouble getting my very basic first python script to commit a database update to Teradata (TD12, TD13). Using a simple example like Jimm's above, but with an insert statement and followed by a
conn.commit() - as per pyodbc examples.
This isn't working .
A colleague said he had it running OK on V2R6, with matching TTU ODBC driver, where he did a number of inserts and a commit at the end. All OK until the upgrade to TD13 ODBC and now only the last insert is saved.
Any tips on using TD13 ODBC with python ? I suspect the transaction processing with the Teradata ODBC drivers is somewhat different to other OLTP drivers, but I haven't found the answer yet.
Thanks

Willimoa 63 posts Joined 10/09
01 Sep 2010

Hi there Hussey,
I'm glad you found the solution. Did you solve the commit issue for inserts and updates ? I'd be very interested to hear what you did.

Willimoa 63 posts Joined 10/09
01 Sep 2010

A note for the forum: It is now working !

I was actually using conn.commit instead of conn.commit(). The former still compiles and runs without errors which is why I didn't pick it up sooner.

It appears that SQL_AUTOCOMMIT or TMODE in the connection string don't make a difference, you must use conn.commit().

thanks

sreeharsha20 1 post Joined 08/10
01 Sep 2010

hi everyone am trying to use java jdbc type 4 driver to connect to the teradata.........am encountered with following error....

2010-09-01.20:14:05.125 TERAJDBC4 ERROR [main] com.teradata.jdbc.jdbc_4.TDSession@9df354 Connection to localhostcop1 Wed Sep 01 20:14:05 CDT 2010 socket orig=localhostcop1 cid=1a80a69 sess=0 java.net.UnknownHostException: localhostcop1 at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849) at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1200) at java.net.InetAddress.getAllByName0(InetAddress.java:1153) at java.net.InetAddress.getAllByName(InetAddress.java:1083) at java.net.InetAddress.getAllByName(InetAddress.java:1019) at com.teradata.jdbc.jdbc_4.io.TDNetworkIOIF$Lookup.(TDNetworkIOIF.java:148) at com.teradata.jdbc.jdbc_4.io.TDNetworkIOIF.connectToHost(TDNetworkIOIF.java:232) at com.teradata.jdbc.jdbc_4.io.TDNetworkIOIF.(TDNetworkIOIF.java:86) at com.teradata.jdbc.jdbc_4.TDSession.getIO(TDSession.java:580) at com.teradata.jdbc.jdbc.GenericStateController.(GenericStateController.java:41) at com.teradata.jdbc.jdbc.GenericLogonController.(GenericLogonController.java:40) at com.teradata.jdbc.jdbc_4.TDSession.(TDSession.java:198) at com.teradata.jdbc.jdbc_3.ifjdbc_4.TeraLocalConnection.(TeraLocalConnection.java:95) at com.teradata.jdbc.jdbc.ConnectionFactory.createConnection(ConnectionFactory.java:54) at com.teradata.jdbc.TeraDriver.doConnect(TeraDriver.java:217) at com.teradata.jdbc.TeraDriver.connect(TeraDriver.java:150) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at com.jdbc.training.practise.jdbc4.main(jdbc4.java:21)
errorcom.teradata.jdbc.jdbc_4.util.JDBCException: [Teradata JDBC Driver] [TeraJDBC 13.00.00.06] [Error 1000] [SQLState 08S01] Login failure for Connection to localhostcop1 Wed Sep 01 20:14:05 CDT 2010 socket orig=localhostcop1 cid=1a80a69 sess=0 java.net.UnknownHostException: localhostcop1 at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849) at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1200) at java.net.InetAddress.getAllByName0(InetAddress.java:1153) at java.net.InetAddress.getAllByName(InetAddress.java:1083) at java.net.InetAddress.getAllByName(InetAddress.java:1019) at com.teradata.jdbc.jdbc_4.io.TDNetworkIOIF$Lookup.(TDNetworkIOIF.java:148) at com.teradata.jdbc.jdbc_4.io.TDNetworkIOIF.connectToHost(TDNetworkIOIF.java:232) at com.teradata.jdbc.jdbc_4.io.TDNetworkIOIF.(TDNetworkIOIF.java:86) at com.teradata.jdbc.jdbc_4.TDSession.getIO(TDSession.java:580) at com.teradata.jdbc.jdbc.GenericStateController.(GenericStateController.java:41) at com.teradata.jdbc.jdbc.GenericLogonController.(GenericLogonController.java:40) at com.teradata.jdbc.jdbc_4.TDSession.(TDSession.java:198) at com.teradata.jdbc.jdbc_3.ifjdbc_4.TeraLocalConnection.(TeraLocalConnection.java:95) at com.teradata.jdbc.jdbc.ConnectionFactory.createConnection(ConnectionFactory.java:54) at com.teradata.jdbc.TeraDriver.doConnect(TeraDriver.java:217) at com.teradata.jdbc.TeraDriver.connect(TeraDriver.java:150) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at com.jdbc.training.practise.jdbc4.main(jdbc4.java:21)

my program....

public class jdbc4 extends IOException {
public static void main(String[] args) {
try
{
Class.forName("com.teradata.jdbc.TeraDriver");
System.out.println("driver loaded");
Connection con=DriverManager.getConnection("jdbc:teradata://localhostcop1/TMODE=ANSI,CHARSET=UTF8","tduser","tduser");
System.out.println("connection established");
Statement stmt=con.createStatement();
boolean created=stmt.execute("create table tduser.emp4(empno varchar(5),ename varchar(20),sal varchar(20));");
System.out.println("Table Create "+created);
}
catch (Exception e){System.out.println("error"+e);}
}

}

please help me ...
Thanks,
Sreeharsha

tomnolan 594 posts Joined 01/08
02 Sep 2010

The important part of the exception message is: java.net.UnknownHostException: localhostcop1
Which tells you that "localhostcop1" is not a defined hostname.
If the Teradata Database is running on your local machine, then you should specify localhost as the hostname.
If the Teradata Database is running on some other machine, then you should specify the hostname for it.

eilangko 2 posts Joined 01/11
17 Jun 2011

To connect to Teradata using python, this is what I have done.

1. I ensured that the teradata ODBC drivers are correctly installed and I was able to connect via SQL Assistant.
2. Then I installed pyodbc downloaded from http://code.google.com/p/pyodbc/.
3. Then I tested 2 methods. First using the DNS entry used to connect to SQL Assistant. The code for this is as follows:

connection = pyodbc.connect('DSN=TEST_DSN;PWD=xxxx')

3. The second method was as follows:

connection = pyodbc.connect('DRIVER{Teradata};DBCNAME=10.10.10.10;UID=test123;PWD=xxx;QUIETMODE=YES;')

Both methods worked perfectly for 32 Bit Python 2.7.2 and 32 Bit pyodbc 2.1.8 installed on Windows XP 32-Bit and Teradata residing on a remote server.

However, I still have not managed to get these steps work on 64 Bit Windows 7 Professional.

eilangko 2 posts Joined 01/11
17 Jun 2011

On 64 Bit Windows 7 Professional Edition, I tried the following steps and the code worked like a charm:

1. I ensured that the 64 Bit teradata 13 ODBC drivers are correctly installed.
2. Then I installed 64 Bit pyodbc downloaded from http://code.google.com/p/pyodbc/.
3. Then I tested 2 methods. First using the DNS entry used to connect to SQL Assistant. The code for this is as follows:

connection = pyodbc.connect('DSN=TEST_DSN;PWD=xxxx')

3. The second method was as follows:

connection = pyodbc.connect('DRIVER{Teradata};DBCNAME=10.10.10.10; UID=test123;PWD=xxx;QUIETMODE=YES;')

mohitzs 1 post Joined 06/14
18 Jun 2014

Hi,
I have been struggling with getting this to work on Linux.
Can anyone help me with step by step process for linux?
Here is what I have done:
1. Install pyodbc
2. Install TeraGSS , tdicu, cliv2, piom, tdodbc
3. I guess now I need to do some configurations [stuck at this point :\ ]
4. >import pyodbc
5. >conn = pyodbc.connect('DRIVER={Teradata};DBCNAME=<HOST_NAME>;UID=<UID>;PWD=<PWD>;QUIETMODE=YES;')
Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')

 

Kindly Help!

 

Thanks in advance.

padhia 35 posts Joined 06/10
18 Jun 2014

Teradata ODBC driver comes with its own driver manager and does not support unixODBC. On openSUSE 13.1 these steps worked: a) uninstall unixodbc 2) build pyodbc from source. 

stella2015 1 post Joined 04/15
22 Apr 2015

I'm able to setup Teradata ODBC driver with pyodbc in my environment. I changed the pyodbc source code to build pyodbc with Teradata ODBC driver. My environment is SuSE 11.1 + Python 2.7.6 + latest pyodbc 3.0.7
I post the steps I used here and hope this helpful for those people still looking the google results.
1. download and install Teradata ODBC driver
http://downloads.teradata.com/download/connectivity/odbc-driver/linux
run ksh
install tdicu
install TeraGSS
make sure libstdc++ is installed before install tdodbc
install tdodbc
 
2. create a conf file to link teradata driver lib
sudo vi /etc/ld.so.conf.d/teradata.conf
/opt/teradata/client/15.00/odbc_64/lib
/opt/teradata/client/15.00/tdicu/lib64
/opt/teradata/teragss/linux-x8664/client/lib
sudo ldconfig
 
3. make sure 64 bit teradata driver is used in /usr/lib
ls -lha /usr/lib | grep odbc
lrwxrwxrwx   1 root root       47 2015-04-22 02:28 libodbcinst.so -> /opt/teradata/client/ODBC_32/lib/libodbcinst.so
lrwxrwxrwx   1 root root       43 2015-04-22 02:28 libodbc.so -> /opt/teradata/client/ODBC_32/lib/libodbc.so
/usr/lib> ls /opt/teradata/client/ODBC_64/lib
ddtrc27.so      libodbc.so     odbccurs.so  tdwalletdir
libddicu27.so   libtdparse.so  odbctrac.so  vscnctdlg.so
libodbcinst.so  libtdsso.so    tdata.so
sudo ln -s /opt/teradata/client/ODBC_64/lib/libodbc.so libodbc.so
sudo mv libodbcinst.so 32libodbcinst.so
sudo ln -s /opt/teradata/client/ODBC_64/lib/libodbcinst.so libodbcinst.so
 
4. copy out odbc.ini and odbcinst.ini to home directory (this might not be necessary)
cp /opt/teradata/client/15.00/odbc_64/odbc.ini ~/.odbc.ini
cp /opt/teradata/client/15.00/odbc_64/odbcinst.ini ~/.odbcinst.ini
 
5. compile pyodbc
 
First attempt
===========
teradata/pyodbc-3.0.7> sudo  python setup.py build install
running build
running build_ext
building 'pyodbc' extension
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/remote
creating build/temp.linux-x86_64-2.7/remote/repqa11
creating build/temp.linux-x86_64-2.7/remote/repqa11/users
creating build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings
creating build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP
creating build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata
creating build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7
creating build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/buffer.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/buffer.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
In file included from /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/buffer.cpp:12:
/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbc.h:52:17: error: sql.h: No such file or directory
/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbc.h:53:20: error: sqlext.h: No such file or directory
In file included from /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/buffer.cpp:12:
/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbc.h:69: error: âIsSetâ declared as an âinlineâ variable
/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbc.h:69: error: âDWORDâ was not declared in this scope
/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbc.h:69: error: âDWORDâ was not declared in this scope
/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbc.h:69: error: initializer expression list treated as compound expression
/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbc.h:70: error: expected â,â or â;â before â{â token
In file included from /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/buffer.cpp:17:
/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/buffer.h:46: error: âSQLLENâ has not been declared
In file included from /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/buffer.cpp:18:
/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbcmodule.h:36: error: âHENVâ does not name a type
error: command 'gcc' failed with exit status 1
The gcc cannot find the header files in teradata driver.
Resolution:
ls /opt/teradata/client/15.00/odbc_64/include
odbcinst.h  qesqlext.h  sqlext.h  sql.h  sqltypes.h  sqlucode.h  sqlunx.h  tdsql.h
cd /usr/local/include/python2.7
sudo ln -s /opt/teradata/client/15.00/odbc_64/include/* .
 
Second attempt
============
sudo python setup.py build
running build
running build_ext
building 'pyodbc' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/buffer.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/buffer.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/cnxninfo.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/cnxninfo.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/connection.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/connection.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/cursor.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/cursor.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/errors.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/errors.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/getdata.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/getdata.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/params.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/params.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbccompat.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbccompat.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbcdbg.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbcdbg.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbcmodule.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbcmodule.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbcmodule.cpp: In function âbool AllocateEnv()â:
/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbcmodule.cpp:208: error: âSQL_CP_ONE_PER_HENVâ was not declared in this scope
error: command 'gcc' failed with exit status 1
Resolution
The thread helped to resolve this https://groups.google.com/forum/#!topic/pyodbc/2EiSNnzCR-s
Adding #ifdef to pyodbcmodule.cpp resolve the compile error.
pyodbc-3.0.7/src> vi pyodbcmodule.cpp
static bool AllocateEnv()
{
    #ifdef SQL_CP_ONE_PER_HENV
    PyObject* pooling = PyObject_GetAttrString(pModule, "pooling");
    bool bPooling = pooling == Py_True;
    Py_DECREF(pooling);

    if (bPooling)
    {
        if (!SQL_SUCCEEDED(SQLSetEnvAttr(SQL_NULL_HANDLE, SQL_ATTR_CONNECTION_POOLING, (SQLPOINTER)SQL_CP_ONE_PER_HENV, sizeof(int))))
        {
            Py_FatalError("Unable to set SQL_ATTR_CONNECTION_POOLING attribute.");
            return false;
        }
    }
    #endif
 
Third attempt
==========
sudo python setup.py build

running build
running build_ext
building 'pyodbc' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/buffer.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/buffer.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/cnxninfo.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/cnxninfo.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/connection.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/connection.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/cursor.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/cursor.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/errors.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/errors.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/getdata.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/getdata.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/params.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/params.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbccompat.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbccompat.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbcdbg.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbcdbg.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbcmodule.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbcmodule.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/row.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/row.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=3.0.7 -I/usr/local/include/python2.7 -c /remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/sqlwchar.cpp -o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/sqlwchar.o -Wno-write-strings
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
creating build/lib.linux-x86_64-2.7
g++ -pthread -shared build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/buffer.o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/cnxninfo.o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/connection.o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/cursor.o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/errors.o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/getdata.o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/params.o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbccompat.o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbcdbg.o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/pyodbcmodule.o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/row.o build/temp.linux-x86_64-2.7/remote/repqa11/users/lipings/DP/teradata/pyodbc-3.0.7/src/sqlwchar.o -lodbc -o build/lib.linux-x86_64-2.7/pyodbc.so
 
6 install pyodbc
sudo python setup.py install
running install
running bdist_egg
running egg_info
creating pyodbc.egg-info
writing pyodbc.egg-info/PKG-INFO
writing top-level names to pyodbc.egg-info/top_level.txt
writing dependency_links to pyodbc.egg-info/dependency_links.txt
writing manifest file 'pyodbc.egg-info/SOURCES.txt'
reading manifest file 'pyodbc.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'tests/*'
writing manifest file 'pyodbc.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_ext
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.7/pyodbc.so -> build/bdist.linux-x86_64/egg
creating stub loader for pyodbc.so
byte-compiling build/bdist.linux-x86_64/egg/pyodbc.py to pyodbc.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying pyodbc.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pyodbc.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pyodbc.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pyodbc.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/pyodbc-3.0.7-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing pyodbc-3.0.7-py2.7-linux-x86_64.egg
Copying pyodbc-3.0.7-py2.7-linux-x86_64.egg to /usr/local/lib/python2.7/site-packages
Adding pyodbc 3.0.7 to easy-install.pth file

Installed /usr/local/lib/python2.7/site-packages/pyodbc-3.0.7-py2.7-linux-x86_64.egg
Processing dependencies for pyodbc==3.0.7
Finished processing dependencies for pyodbc==3.0.7
 
7 test connectivity
python
>>> import pyodbc
>>> pyodbc.pooling = False
>>> conn=pyodbc.connect('DRIVER={Teradata};DBCNAME=<host/IP>;UID=DPTUSER2;PWD=St33lr0d;QUIETMODE=YES;', ANSI=True, autocommit=True)
>>> curs=conn.cursor()
>>> curs.execute('select current_timestamp')
<pyodbc.Cursor object at 0xa2a750>
>>> print( curs.fetchone() )
(datetime.datetime(2015, 4, 22, 13, 29, 6, 11990), )
>>> conn.close()

Roopalini 13 posts Joined 05/08
04 Aug 2015

With all the information , I am still no where close to getting this accomplished. My first challenge is to install pyodbc on SuSE SP1 64 bit. I get the below error when I try to install the package using zypper.
zypper install pyodbc
Loading repository data...
Reading installed packages...
'pyodbc' not found.
Resolving package dependencies...
 
I also tried to install using 'rpm -ivh package' however failing dependencies not being there. Could one of you point me to the right pyodbc package and the dependencies? Greaty appreciate the help.

ericscheie 3 posts Joined 11/08
04 Aug 2015

I would recommend having a look at the new <a href="https://developer.teradata.com/tools/reference/teradata-python-module">Teradata Python Module</a>.   It doesn't depend on pyodbc and is 100% python so you should find it eaiser to get working.  Also, it provides many capabilities above and beyond pyodbc that you may find useful.

Roopalini 13 posts Joined 05/08
05 Aug 2015

Thanks for sharing the link Eric. I shall go over it and try to get that installed.

ragesz 5 posts Joined 05/15
13 Dec 2015

stella2015 or anyone else, can you specify how to compile and build pyodbc with Teradata ODBC driver?
Thank you!

You must sign in to leave a comment.