[DB-SIG] Prepared statements in python drivers

Federico Di Gregorio fog at initd.org
Wed Apr 9 11:24:22 CEST 2014


On 09/04/2014 04:49, INADA Naoki wrote:
> Prepared statement holds resource on server side.
> For example, following code is dangerous when combined with connection pool.
> 
> def myexecute(params):
>     cur = con.cursor()
>     cur.prepare(MY_STMT)  # allocate resource on server-side that is
> freed when connection is closed.
>     return cur.execute(params)
> 
> I think prepared statement should be bound to connection.
> 
> Connection.prapare(name, stmt, skip_on_dup=False)
> Prepare stmt as name.
> If skip_on_dup is true and same name is prepared before, do nothing.
> 
> Cursor.execute_prepared(name, params, stmt=None)
> Execute prepared statement named name.
> If stmt is not None, call Cursor.prepare(name, stmt, skip_on_dup=True)
> before execute.

This seems to complicate the code for no gain. The API previously
proposed is much better IMO.

federico

-- 
Federico Di Gregorio                         federico.digregorio at dndg.it
Di Nunzio & Di Gregorio srl                               http://dndg.it
 E tu usa il prefisso corretto Re: non R:, questa è una ML seria.
                                            -- cosmos, su debian-italian


More information about the DB-SIG mailing list