[DB-SIG] Connecting to MS SQL Server, Access, Oracle examples
M.-A. Lemburg
mal@lemburg.com
Thu, 12 Jul 2001 10:03:22 +0200
> If you are prepared to try alternatives, you can use my MSSQL Server
> module.
Note that your description will work with just about any Python
Database API compliant module or package.
> >>> import MSSQL
> >>> db = MSSQL.connect('rat', 'sa', '', 'pubs')
E.g. for mxODBC just change the above lines to
from mx.ODBC import Windows
db = Windows.DriverConnect('DSN=datasourcename;UID=userid;PWD=passwd')
and the rest should work in pretty much the same way (except for
maybe the syntax of calling stored procedures and handling of
multiple result sets).
> >>> 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\012emphasis 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)
There are more examples in the http://www.python.org/topics/database
Database Topic Guide.
--
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company: http://www.egenix.com/
Python Software: http://www.lemburg.com/python/