[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Pyodbc-dev] Need an example
From: |
Alberto Mardegan |
Subject: |
Re: [Pyodbc-dev] Need an example |
Date: |
Thu, 14 Oct 2004 23:14:15 +0200 |
User-agent: |
Mutt/1.5.6+20040722i |
Hi Gregory,
Le die Thu, Oct 14, 2004 at 04:56:08PM -0400, Bakken, Gregory A ha scribite:
> I recently downloaded pyodbc, and seem to have it working OK (import odbc
> works). I was wondering if anyone had some simple examples showing how to
> use pyodbc to connect to an oracle database and do a simple query.
This module is just a port of the Python ODBC Win32 module described
here:
http://www.python.org/windows/win32/odbc.html
I just made some changes (and hacks, maybe) to have it compile in Linux.
I did some very basic tests, and it appears to be working. But indeed it
need some more testing, cleaning and improvements.
Anyway, back to your original question: you can just try the example
made for the win32 module. I cut&paste it here:
import dbi, odbc
try:
s = odbc.odbc('DSN/UID/PASSWORD')
cur = s.cursor()
cur.execute('select * from discounts')
print cur.description
for tup in cur.description:
print tup[0],
print
while 1:
rec = cur.fetchmany(10)
if not rec: break
print rec
except NameError,e:
print 'error ', e, 'undefined'
The original module has a "bug": you have to import the dbi module, too. If I
remember correctly, I did some hack to make this unnecessary. It's been a while
since I didn't work on this project, so please let me know if it works.
Bye and thanks!
--
Saluti,
Mardy
http://interlingua.altervista.org