DB-API 2.0 in pysqlite and pgdb

R

Roman Suzi

Happy New Year to all Pythoneers!

I am playing with pysqlite and pgdb and their DB-API conformancy.
It was quite interesting to know:

- sqlite doesn't have mandatory helper-functions Date, Tim, etc.
(due to an error int it's __init__, but this is quite obvious to correct
or just to use mx.Date, mx.Time)

more serious mishaps with pgdb (postgresql-python):
it doesn't know how to quote date-time data for the objects
it has constructors itself.
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.3/site-packages/pgdb.py", line 189, in execute
self.executemany(operation, (params,))
File "/usr/local/lib/python2.3/site-packages/pgdb.py", line 201, in
executemany
sql = _quoteparams(operation, params)
File "/usr/local/lib/python2.3/site-packages/pgdb.py", line 283, in
_quoteparams
x[k] = _quote(v)
File "/usr/local/lib/python2.3/site-packages/pgdb.py", line 275, in _quote
raise InterfaceError, 'do not know how to handle type %s' % type(x)
pgdb.InterfaceError: do not know how to handle type <type 'instance'>

This doesn't happen for strings or numbers:
cu.execute("select %s;", ['s'])
cu.execute("select %s;", [1])
cu.execute("select %(k)s;", {'k': 123})
o
<DateTimeDelta object for '10:00:00.00' at 401e8a48>

Thus, pgdb doesn't know how to handle DateTimeDelta.

The same with

. . .
line 201, in executemany
sql = _quoteparams(operation, params)
File "/usr/local/lib/python2.3/site-packages/pgdb.py",
line 283, in _quoteparams
x[k] = _quote(v)
File "/usr/local/lib/python2.3/site-packages/pgdb.py",
line 275, in _quote
raise InterfaceError, 'do not know how to handle type
%s' % type(x)
pgdb.InterfaceError: do not know how to handle type <type
'DateTime'>

(It was after I commented out exception catch:

# except:
# raise OperationalError, "internal error in '%s'" % sql

in pgdb.py to see where the error occurs)


Am I missing something obvious or is it really a bug/feature of pgdb?

python2.3
postgresql-7.2.1
almost fresh mx.DateTime


Thank you!

Sincerely yours, Roman Suzi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top