[reportlab-users] Use With SQLite3

Paul McNett p at ulmcnett.com
Tue Feb 20 18:43:58 EST 2007


Rich Shepard wrote:

> On Tue, 13 Feb 2007, Paul McNett wrote:

>

>> You can configure sqlite to return DictCursors by default. See:

>> http://www.initd.org/tracker/pysqlite/wiki/PysqliteFactories

>

> Paul,

>

> I don't want to change the code already written to accommodate DictCursors

> by default, so ...

>

>> Otherwise, you can run the conversion manually after the fact.

>

> ... please provide a pointer to what I read to learn how to do this

> conversion.


Well, it is pretty simple. Here's an untested example:

import pysqlite2.dbapi2 as sqlite
con = sqlite.connect(":memory:")
cur = con.cursor()

cur.execute("create table test (id INTEGER PRIMARY KEY AUTOINCREMENT,
name CHAR)")
cur.execute("insert into test (name) values ('Paul')")
cur.execute("insert into test (name) values ('Rich')")

cur.execute("select * from test")
rs = cur.fetchall()
dict_cursor = []
for rec in rs:
d = {}
for idx, fld in enumerate(cur.description):
d[fld[0]] = rec[idx]
dict_cursor.append(d)

print dict_cursor



> BTW, your screencasts on using the report designer are helpful.

Glad to hear it!


--
pkm ~ http://paulmcnett.com



More information about the reportlab-users mailing list