[DB-SIG] Use of context managers with DB API 2
cito at online.de
Sun Nov 4 12:31:43 CET 2012
Am 04.11.2012 00:07, schrieb M.-A. Lemburg:
> * The short-cuts don't make the underlying cursors available for
> error handling.
> * The shortcut methods only work for non result-set generating
> SQL statements, since there's no way to fetch the result sets
> without access to the cursors.
But the cursor could be returned as the result value of con.execute() as
it's implemented in SQLite.
> * Creating new cursors for each .execute() is inefficient, since
> setting up and tearing down cursors can be time consuming
> (e.g. if cursors are mirrored on the server side).
> * Optimizations such as reusing prepared statements is not
> (easily) possible using such short-cuts, unless the database
> module works with cursor pools.
That does not hold for SQLite, since it does not have real cursors
anyway. But it's an argument for not following the example of SQLite in
"real database" modules.
More information about the DB-SIG