MS SQL Server module for Python

Examples

The following is an interactive session which shows how to use the module.

Do not use the Cursor.callproc() method on Windows - at best it will probably fail, at worst it will GP fault. Use Cursor.execute() instead.
drama:/home/dave/work/object-craft/mssql% python
Python 2.0 (#0, Apr 14 2001, 21:24:22) 
[GCC 2.95.3 20010219 (prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import MSSQL
>>> db = MSSQL.connect('rat', 'sa', '', 'pubs')
>>> c = db.cursor()
>>> c.execute('select * from titles')
>>> c.fetchone()
('BU1032', "The Busy Executive's Database Guide", 'business    ', '1389', 19.99,
 5000.00, 10, 4095, 'An overview of available database systems with\015\012empha
sis on common business applications. Illustrated.', Jun 12 1991 12:00:00:000AM)
>>> for f in c.description: print f
... 
('title_id', 47, 0, 7, 0, 0, 0)
('title', 47, 0, 81, 0, 0, 0)
('type', 47, 0, 13, 0, 0, 0)
('pub_id', 47, 0, 5, 0, 0, 0)
('price', 60, 0, 8, 0, 0, 0)
('advance', 60, 0, 8, 0, 0, 0)
('royalty', 56, 0, 4, 0, 0, 0)
('ytd_sales', 56, 0, 4, 0, 0, 0)
('notes', 47, 0, 201, 0, 0, 0)
('pubdate', 61, 0, 8, 0, 0, 0)
>>> c = db.cursor()
>>> c.callproc('sp_help', {'': 'titles'})
>>> c.fetchall()
[]
>>> c.nextset()
1
>>> for f in c.fetchall(): print f
... 
('titles', 'dbo', 'user table', Nov 13 1998  3:10:48:970AM)
>>> c.nextset()
1
>>> for f in c.fetchall(): print f
... 
('title_id', 'tid', 'no', 6, '     ', '     ', 'no', 'yes', 'no')
('title', 'varchar', 'no', 80, '     ', '     ', 'no', 'yes', 'no')
('type', 'char', 'no', 12, '     ', '     ', 'no', 'yes', 'no')
('pub_id', 'char', 'no', 4, '     ', '     ', 'yes', 'yes', 'yes')
('price', 'money', 'no', 8, '19   ', '4    ', 'yes', '(n/a)', '(n/a)')
('advance', 'money', 'no', 8, '19   ', '4    ', 'yes', '(n/a)', '(n/a)')
('royalty', 'int', 'no', 4, '10   ', '0    ', 'yes', '(n/a)', '(n/a)')
('ytd_sales', 'int', 'no', 4, '10   ', '0    ', 'yes', '(n/a)', '(n/a)')
('notes', 'varchar', 'no', 200, '     ', '     ', 'yes', 'yes', 'no')
('pubdate', 'datetime', 'no', 8, '     ', '     ', 'no', '(n/a)', '(n/a)')
>>> c.nextset()
1
>>> for f in c.fetchall(): print f
... 
('No identity column defined.', None, None, None)
>>>