Questions to DB-API 2
Jp Calderone
exarkun at intarweb.us
Fri Feb 21 06:45:46 EST 2003
On Fri, Feb 21, 2003 at 03:00:03AM -0800, Jakob Simon-Gaarde wrote:
> Quiestions to DB-API 2
>
> 1. In DB-API 1 using the odbc module I was able to use question-signs
> to format my SQL, thus things like pings around strings and date
> formats was automatically taken care of. I would write something like
> this:
>
> cur.execute("insert into table (text,number,date) values (?,?,?)",
> (strvar,numvar,datevar))
>
> Unfortunately this doesen't seem to work in DB-API 2 but since I don't
> expect that it is a degrade compared to DB-API 1 I guess there must be
> some other way.
> Can anybody help please. Is there a tutorial to db-api 2 with usage
> examples, because the description on python.org/topics/db isn't very
> informative in the respects of usage.
>
Sadly, DB-API 2 leaves this particular aspect unspecified, and so
implementations vary. If "?" doesn't work, "%s" tends to. The
documentation to the particular module you're using almost certainly
describe which format is supported.
> 2. For debug reasons I would really like if I could print the full
> SQL-statement when a database exception occures, is this possible? I
> can't see any attributes with on the exception classes.
>
Can't help here, except to say that you could probably structure your code
such that you always still had a reference to the most recent query string
and data at any time an exception might be raised, and so could print them
out using those references.
Jp
--
It is practically impossible to teach good programming style to
students that have had prior exposure to BASIC: as potential
programmers they are mentally mutilated beyond hope of
regeneration. -- Dijkstra
--
up 12 days, 16:28, 4 users, load average: 0.22, 0.23, 0.24
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20030221/b23fa769/attachment.sig>
More information about the Python-list
mailing list