1

I have a piece of code looking like this:

 conn=sybpydb.connect(user=args.u, password=args.p,servername=args.s)
 cur = conn.cursor()
 cur.execute(sql)
 print(cur.connections.messages)

The execute takes maybe 5 minutes to run, and then it prints my output. I was wondering if there is any way to print the output line for line while the execute is running instead of waiting until it is done and getting it all as one big batch?

  • Did you try to iterate over your cursor? – filmor Mar 19 '13 at 10:19
  • I think you need smth like a server-side cursor functionality. For example, MySQLdb interface supports it: http://stackoverflow.com/questions/337479/how-to-get-a-row-by-row-mysql-resultset-in-python. Not sure if sybpydb can handle your case. – alecxe Mar 19 '13 at 10:19
  • What do you mean when you say iterate over the cursor? – Alexander Rickardsson Mar 19 '13 at 11:41

1 Answers1

-1

filmor is right : retrieve results running on the cursor.

The sybpydb package is a PEP 249 implementation provided by Sybase. So, the Cursor object you retrieve have some methods, for example fetchone and fetchall.

Your code, to retrieve results line by line and do something with it, would be:

# Preparation your connection and cursor for fetching results
conn = sybpydb.connect(user=args.u, password=args.p, servername=args.s)
cur = conn.cursor()
cur.execute(sql)

# Reading all result one by one
for row in cur.fetchall():
    # Do something with your current results
    print(row)

# Closing cursor and connection
cur.close()
conn.close()
TonyMoutaux
  • 355
  • 6
  • 13