Sybase sybpydb requests do not return anything

I am currently connecting to a Sybase 15.7 server using sybpydb . This seems to be fine:

import sys sys.path.append('/dba/sybase/ase/15.7/OCS-15_0/python/python26_64r/lib') sys.path.append('/dba/sybase/ase/15.7/OCS-15_0/lib') import sybpydb conn = sybpydb.connect(user='usr', password='pass', servername='serv') 

works fine. Changing any of my connection data results in a connection error.

Then I select the database:

 curr = conn.cursor() curr.execute('use db_1') 

however now when i try to run queries it always returns None

 print curr.execute('select * from table_1') 

I tried to run use and select queries in the same execute , I tried to include go commands after each of them, I tried to use curr.connection.commit() after each of them, without success. I have confirmed using dbartisan and isql that the same queries as me use the returned records.

Why am I not getting results from my queries in python?

EDIT:

Just extra info. To make sybpydb import work, I had to change two environment variables. I added the lib paths (the same ones that I added to sys.path ) in $LD_LIBRARY_PATH , i.e.:

 setenv LD_LIBRARY_PATH "$LD_LIBRARY_PATH":dba/sybase/ase/15.7/OCS-15_0/python/python26_64r/lib:/dba/sybase/ase/15.7/OCS-15_0/lib 

and I had to change the SYBASE path from 12.5 to 15.7. All this was done in csh .

If I print conn.error (), after each curr.execute (), I get:

 ("Server message: number(5701) severity(10) state(2) line(0)\n\tChanged database context to 'master'.\n\n", 5701) 
+6
source share
1 answer

I fully understand where the documentation may confuse you. Its not like other db extensions (like psycopg2).

When connecting to most standard db extensions, you can specify a database. Then, when you want to return data from a SELECT query, you either use fetch (the ok way to do this) or an iterator (a more pythonic way to do this).

 import sybpydb as sybase conn = sybase.connect(user='usr', password='pass', servername='serv') cur = conn.cursor() cur.execute("use db_1") cur.execute("SELECT * FROM table_1") print "Query Returned %d row(s)" % cur.rowcount for row in cur: print row # Alternate less-pythonic way to read query results # for row in cur.fetchall(): # print row 

Try it and let us know if that works.

+1
source

All Articles