On Sun, 15 Jun 2008 18:15:38 -0700, Dennis Lee Bieber
<[EMAIL PROTECTED]> 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

connection=apsw.Connection("test.sqlite")
cursor=connection.cursor()

textlines = []
textlines.append("123\titem1\titem2\titem3\titem4\t345\titem6")
textlines.append("123\titem1\t\titem3\titem4\t345\titem6")

p = re.compile("^(\d+)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(\d+)\t(.+?)$")
for line in textlines:
        m = p.search(line)
        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()))

connection.commit()
connection.close(True)

=========

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

Thank you.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to