Re: Do Not See My Error
dcharno <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
>
> I did see that. Part of my confusion is the sequence type that pysqlite
> expects: string, list, tuples? The example on the web site shows the data as
> tuples (last_name, age); does this matter?
For qmark style params you supply a list or tuple.
> I'll try this. What's the difference between readlines() and
xreadlines()?
For large files xreadlines() is more efficient because it does not first
read all the lines into a list. I think you are supposed to just
iterate over the file after python 2.3. Here is a test I tried:
from pysqlite2 import dbapi2 as sqlite3
con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("CREATE TABLE v (id INTEGER PRIMARY KEY, a REAL, b REAL, c
REAL, d REAL);")
fh = file('c:\\tmp\p.txt', 'r')
for l in fh:
l = l[:-1]
if len(l):
values = l.split(',')
cur.execute("insert into v(a,b,c,d) values(?,?,?,?);", values)
for r in cur.execute("select * from v;"):
print r