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

Vijay Sekhri sekhri at fnal.gov
Thu Sep 15 21:02:43 BST 2005


I changed the driver from psqlodbc.so (latest from postgres website) to 
the one that comes with unixODBC (libodbcpsql.so) in the odbcinst.ini 
file and it works fine now.
The strangest thing is that the former also worked fine when inoked 
through the shell but failed when invoked through python. Anyways thanks 
for the quick reply
Vijay

Nick Gorham wrote:

> Vijay Sekhri wrote:
>
>> 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
>
>
> Hi,
>
> Yes that looks ok
>
>>
>>
>> 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
>
>
>
> Ok, as I think you know thats failing because the drive manager is 
> failing to load the driver, the reason its failing was at thge end of 
> the string, but it looks cut off by the app (python in this case).
>
>>
>>
>> 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
>>
> Yes, I would expect this to crash and burn
>
>>
>> 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
>
>
>
> I am guessing the driver is failing to load as its depends on other 
> libs, try
>
> ldd /home/sekhri/apps/odbc/psql/lib/psqlodbc.so
>
> to see what other libs it needs, I guess that including the location 
> on the lib path is allowing it to find what its missing.
>
>>
>> [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
>>
> But now the drive is failing as there is a undefined symbol in the 
> driver, Looking at the postgres source, I think the problem is its 
> building a unicode driver, and the driver manager is then making 
> unicode calls, but the above function is in a module win_unicode.c 
> which from its name I guess is not being built in non windows builds.
>
-------------- 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/0b6a3047/attachment.vcf>


More information about the unixODBC-support mailing list