Checking each item in

Gilles Ganault nospam at
Mon Jun 16 05:43:03 EDT 2008

On Sun, 15 Jun 2008 18:15:38 -0700, Dennis Lee Bieber
<wlfraed at> wrote:
>	I don't know quite what the reason for the sql = sql + ... is -- if
>you are trying to package more than one discrete statement into a single
>query you should be advised that not all adapters/DBMS support that
>function (I think one uses "executescript()" to signify multiple
>distinct statements.

The script will go through about 3,000 lines of text, so I wanted to
create a transaction with BEGIN/COMMIT. It seems like APSW (the
simpler version of PySQLite) doesn't do transactions silently.

>A decent adapter should convert Python's None object into a proper DBMS
>Null. The adapter is also responsible for doing any needed quoting or
>escaping of the data supplied, hence no quoting of the placeholders!

Thanks for the tip. However, after looking at the code you gave, I'm
getting an error when running cur.execute(), so it is only ran once
and the program exits:

import sys, re, apsw, os


textlines = []

p = re.compile("^(\d+)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(\d+)\t(.+?)$")
for line in textlines:
	m =
	if m:
		sql = 'INSERT INTO test (col1,col2,col3,col4,col5,col6,col7)
VALUES (?,?,?,?,?,?,?);'

    cursor.execute(sql, tuple((c, None)[c == ""] for c in m.groups()))
  File "apsw.c", line 3518, in resetcursor
apsw.ConstraintError: ConstraintError: not an error
apsw.ConnectionNotClosedError: apsw.Connection on "test.sqlite".  The
destructor has been called, but you haven't closed the connection. All
connections must be explicitly closed.  The SQLite database object is
being leaked.
		cursor.execute(sql, tuple((c, None)[c == ""] for c in m.groups()))



I read the online sample for APSW, but didn't find what it could be.
Any idea?

Thank you.

More information about the Python-list mailing list