On Thu, Dec 18, 2014 at 7:39 PM, M.-A. Lemburg <m...@egenix.com> wrote: > On 17.12.2014 19:13, INADA Naoki wrote: >> As I said before, prepared statement is normally bound to connection. >> So `.prepare()` method should be connection's method, not cursor's. >> >> prepared = conn.prepare("SELECT ?+?") >> ... >> cur = conn.cursor() >> cur.execute(prepared, (1, 2)) >> cur.fetchone() # returns (3,) > > I'm not sure which database you are talking about,
I'm a developer of MySQL drivers (PyMySQL and mysqlclient). prepared statement is alive as long as connection is alive. We can use one prepared statement multiple times. > but in terms > of concepts, statements are run on cursors, so adding the method > to connections doesn't look right (we dropped this logic when moving > from DB-API 1.0 to 2.0 a long time ago). PEP 249 says: > Cursor Objects > > These objects represent a database cursor, which is used to manage the > context of a fetch operation. Preparing statement is not fetching query result. > > Also note that the prepare step may need access to the > cursor configuration settings to be correctly interpreted > by the database. I'm not sure which database you are talking about. MySQL has configuration per connection, not per cursor. > > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source (#1, Dec 18 2014) >>>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ > ________________________________________________________________________ > 2014-12-11: Released mxODBC Plone/Zope DA 2.2.0 http://egenix.com/go67 > > ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: > > eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 > D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg > Registered at Amtsgericht Duesseldorf: HRB 46611 > http://www.egenix.com/company/contact/ -- INADA Naoki <songofaca...@gmail.com> _______________________________________________ DB-SIG maillist - DB-SIG@python.org https://mail.python.org/mailman/listinfo/db-sig