[unixODBC-support] invoking unixODBC from python is not working

Vijay Sekhri sekhri at fnal.gov
Thu Sep 15 16:21:41 BST 2005


Hi Nick,
I am using unixODBC on Scientific Linux for some time now succesfully. 
The driver that I am using  is the latest psqlodbc.so for postgres 
database. It works fine when I run my application on the shell. It 
succesfully loads this driver by reading the configuration 
/etc/odbcinst.ini. Here is the entry for my database
[postgres]
Description             =
Driver          = /home/sekhri/apps/odbc/psql/lib/psqlodbc.so
Driver64                = /home/sekhri/apps/odbc/psql/lib/psqlodbc.so
Setup           = /home/sekhri/apps/unixodbc/lib/libodbcpsqlS.so
Setup64         = /home/sekhri/apps/unixodbc/lib/libodbcpsqlS.so
UsageCount              = 1
CPTimeout               =
CPReuse         =


Now I used swig to make a shared library (for python) for my application 
that uses unixODBC. When I invoke the shared library from python it 
fails to load this driver. It seems to be a LD_LIBRARY_PATH problem 
soemhow, but setting it correctly and then running it in python does not 
help either

Here is how I make the shared library . Please note that this doesnot 
include the psqlodbc.so beacuse it is loaded anyways by the DriverManager
[sekhri at venom teststruc]$ rm -rf *o *.cxx *py* ; swig -python -c++ 
struc.i ; g++ -c struc.cpp struc_wrap.cxx -I/usr/include/python2.3/ 
-I/home/sekhri/work/dm/new/cms_dm_dev/ThinServer/include ; g++ 
-static-libgcc  -shared struc.o struc_wrap.o -o _struc.so 
/home/sekhri/work/dm/new/cms_dm_dev/ThinServer/cpp/common/db/DBException.o 
/home/sekhri/work/dm/new/cms_dm_dev/ThinServer/cpp/common/db/DBManagement.o 
/home/sekhri/work/dm/new/cms_dm_dev/ThinServer/cpp/common/db/ResultSet.o  
-L/home/sekhri/apps/unixodbc/lib/   -lodbc


Here is how I invoke it in python

[sekhri at venom teststruc]$ python
Python 2.3.3 (#1, May  7 2004, 10:31:40)
[GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import struc
 >>> s = struc.Struc(34,'d',"dddd")
trying .... SQLConnect
rc1 is not equal to SQL_NO_DATA
While Diagnosing ...:[unixODBC][Driver Manager]Can't open lib 
'/home/sekhri/apps/odbc/psql/lib/psqlodbc.so' : /home/sekh
sqlstate is 01000
errCode 0
Aborted


Now my LD_LIBRARY_PATH is
[sekhri at venom teststruc]$ echo $LD_LIBRARY_PATH
/home/sekhri/apps/unixodbc/lib/


If I include my psqlodbc.so  in my shared lib then I get a segfault 
while SQLConnect
[sekhri at venom teststruc]$ rm -rf *o *.cxx *py* ; swig -python -c++ 
struc.i ; g++ -c struc.cpp struc_wrap.cxx -I/usr/include/python2.3/ 
-I/home/sekhri/work/dm/new/cms_dm_dev/ThinServer/include ; g++ 
-static-libgcc  -shared struc.o struc_wrap.o -o _struc.so 
/home/sekhri/work/dm/new/cms_dm_dev/ThinServer/cpp/common/db/DBException.o 
/home/sekhri/work/dm/new/cms_dm_dev/ThinServer/cpp/common/db/DBManagement.o 
/home/sekhri/work/dm/new/cms_dm_dev/ThinServer/cpp/common/db/ResultSet.o  
-L/home/sekhri/apps/unixodbc/lib/  
/home/sekhri/apps/odbc/psql/lib/psqlodbc.so  -lodbc

[sekhri at venom teststruc]$ python
Python 2.3.3 (#1, May  7 2004, 10:31:40)
[GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import struc
 >>> s = struc.Struc(34,'d',"dddd")
trying .... SQLConnect
rc1 is equal to SQL_NO_DATA
While Diagnosing ...:
sqlstate is 00000
errCode 0
Segmentation fault



Strangely enougf if I add the path of psqlodbc.so in the LD_LIBRARY_PATH 
then I get a different error
[sekhri at venom teststruc]$ export 
LD_LIBRARY_PATH=/home/sekhri/apps/odbc/psql/lib/:$LD_LIBRARY_PATH
[sekhri at venom teststruc]$ ls /home/sekhri/apps/odbc/psql/lib/
psqlodbc.la  psqlodbc.so

[sekhri at venom teststruc]$ python
Python 2.3.3 (#1, May  7 2004, 10:31:40)
[GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import struc
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "struc.py", line 5, in ?
    import _struc
ImportError: /home/sekhri/apps/odbc/psql/lib/psqlodbc.so: undefined 
symbol: ucs2_to_utf8



Any help in this reagrd would be greatly appreciated.
Thank you
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sekhri.vcf
Type: text/x-vcard
Size: 322 bytes
Desc: not available
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-support/attachments/20050915/adb2dd3f/attachment.vcf>


More information about the unixODBC-support mailing list