[Trac-tickets] Re: [The Trac Project] #1746: PySqLite2
The Trac Project
noreply at edgewall.com
Sun Jul 10 15:04:47 CDT 2005
#1746: PySqLite2
-------------------------+--------------------------------------------------
Id: 1746 | Status: assigned
Component: general | Modified: Sun Jul 10 15:04:47 2005
Severity: enhancement | Milestone: 0.9
Priority: normal | Version: devel
Owner: anonymous | Reporter: anonymous
-------------------------+--------------------------------------------------
Comment (by cmlenz):
Gerhard Haering posted a "proof-of-concept" implementation of this to the
[http://lists.initd.org/mailman/listinfo/pysqlite PySQLite mailing list]
[http://lists.initd.org/pipermail/pysqlite/2005-July/000102.html here]. As
the actual content of the message doesn't show in the pipermail archive,
I'll copy it here:
Message:
Attached is proof-of-concept for code that allows you to use the pyformat
style with pysqlite 2.0. It needs fleshing out for executemany, and maybe
for named parameters (%(foo)s, %(bar)s).
In my opinion, something like this could be used to make TRAC compatible
with pysqlite 2.
Maybe it is a useful starting point for somebody.
Attachment:
{{{
#!python
from pysqlite2 import dbapi2 as sqlite
class PyFormatConnection(sqlite.Connection):
def cursor(self):
return sqlite.Connection.cursor(self, PyFormatCursor)
class PyFormatCursor(sqlite.Cursor):
def execute(self, sql, args=None):
if args:
qmarks = ["?"] * len(args)
sql = sql % tuple(qmarks)
sqlite.Cursor.execute(self, sql, args)
else:
sqlite.Cursor.execute(self, sql)
con = sqlite.connect(":memory:", factory=PyFormatConnection)
cur = con.cursor()
cur.execute("create table test(a, b, c)")
cur.execute("insert into test(a, b, c) values (%s, %s, %s)", ('asdf', 4,
5.2))
cur.execute("select a, b, c from test where c <> %s", (4.27,))
print cur.fetchone()
cur.close()
con.close()
}}}
--
Ticket URL: <http://projects.edgewall.com/trac/ticket/1746>
The Trac Project <>
More information about the Trac-Tickets
mailing list