Gerhard Häring wrote: > Vittorio wrote: > >>[...] >>Nonetheless, I was unable to find any documentation about such a >>different behaviour between Pysqlite and Pysqlite2; from my beginner >>point of view the Pysqlite (Magnus' version) paramstyle looks a better >>and more pythonic choice and I don't grasp the Pysqlite2 developers' >>intentions deviating from that way. > > > The reason why pysqlite 0.x/1.x used paramstyle "pyformat", based on > Python string substitution for SQL parameters is that at the time > pysqlite was started, SQLite 2.x did not have any support for parameter > binding. So we had to "fake" it in Python, just like the MySQL interface > does (for the same reasons). > > Later SQLite 2.x versions and of course SQLite 3.x supported real bound > parameters and pysqlite2 was developed from scratch to benefit from > them. SQLite 3.x supports both qmark and named paramstyles, so you can > use question marks *or* named parameters: > > >>> from pysqlite2 import dbapi2 as sqlite > >>> con = sqlite.connect(":memory:") > >>> cur = con.cursor() > >>> cur.execute("select 2*?", (14,)) > >>> cur.fetchone() > (28,) > >>> > >>> cur.execute("select 2 * :x", {"x": 14}) > >>> cur.fetchone() > (28,) > >>> > >>> x = 14 > >>> cur.execute("select 2 * :x", locals()) > >>> cur.fetchone() > (28,) > >>> > > I've also once written a wrapper using pysqlite 2.x's hooks that allows [...] > >>I would be very grateful if someone would cast a light over >>Pysqlite/Pysqlite2 discrepancies. > > > I think about the only place I wrote a bit about the differences was in > the pysqlite 2.0 final announcement: > > http://lists.initd.org/pipermail/pysqlite/2005-May/000043.html > Unfortunately this appears to mean that pysqlite2 isn't fully DB API-conformant.
>>> import pysqlite2 >>> pysqlite2.paramstyle Traceback (most recent call last): File "<stdin>", line 1, in ? AttributeError: 'module' object has no attribute 'paramstyle' >>> Of course, given the module's flexibility it's difficult to know what you *would* put in paramstyle. I take it mixing different paramstyles in the same query will fail? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list