Sybase module for Python

Examples

Consider the following example program which I use to look at the Sybase stored procedures. If passed an argument, it retrieves the text of the named stored procedure and prints it to stdout. If invoked without argument, it lists all of the stored procedures.

import sys, string, Sybase

db = Sybase.connect('SYBASE', 'sa', '', 'sybsystemprocs')
c = db.cursor()
if len(sys.argv) > 1:
    c.execute('select c.text from syscomments c, sysobjects o'
              ' where o.name = @name and o.type = "P" and c.id = o.id'
              ' order by c.colid', {'@name': sys.argv[1]})
    print string.join([row[0] for row in c.fetchall()], '')
else:
    c.execute('select name from sysobjects where type = "P" order by name')
    print string.join([row[0] for row in c.fetchall()], '\n')