Re: "database is locked" on first commit?

Gerhard Häring <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dennis Lee Bieber wrote:
> [http://www.sqlite.org/lockingv3.html]
> """
> In autocommit mode, all changes to the database are committed as soon as
> all operations associated with the current database connection complete.
> """"
> 
> ... what is meant by "the current database connection complete"? Is that
> the same as a con.close() in pysqlite2? I can't say... (and since I run
> from prebuilt binaries, I can't browse source code to the library to
> tell)

No, this just means that in autocommit mode, SQLite will transform any DML
statement, like:

UPDATE foo SET bar=42 WHERE ...

INTO

BEGIN
UPDATE foo SET bar=42 WHERE ...
COMMIT

I. e. it will implicitly wrap each statement executed into a transaction.

> 	At this juncture... I'd probably revert to wolf-fencing... (wrap
> each .execute() and .fetch() with a pair of logging calls -- and see if
> the log shows something like:
> 
> thread-m: execute: select
> thread-n: execute: update (insert, delete)
> thread-n: time-out
> 
> ... rather than something like:
> 
> thread-m: execute: select
> thread-n: execute: update
> thread-m: execute complete
> thread-n: ...

Let's hope this works. You can perhaps implement that simpler by using
pysqlite's factories. I've attached a quick example.

- -- Gerhard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHG5d5dIO4ozGCH14RAj4zAKDDW+KfXxIIsO36pC1KhYdhD6YXUgCgj073
O2T/LfEMNAaQFWh8m0TYTfc=
=miHR
-----END PGP SIGNATURE-----

_______________________________________________
pysqlite mailing list
pysqlite-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/pysqlite
log_example.py (text/x-python, 995 B)
from pysqlite2 import dbapi2 as sqlite
from logging import debug
import logging
debug = logging.debug

class LoggingConnection(sqlite.Connection):
    def commit(self):
        debug("COMMIT")
        sqlite.Connection.commit(self)

    def rollback(self):
        debug("ROLLBACK")
        sqlite.Connection.rollback(self)

    def cursor(self, *args):
        return LoggingCursor(self, *args)

class LoggingCursor(sqlite.Cursor):
    def execute(self, sql, *args):
        debug("EXECUTE " + sql)
        sqlite.Cursor.execute(self, sql, *args)

    def executemany(self, sql, *args):
        debug("EXECUTEMANY " + sql)
        sqlite.Cursor.executemany(self, sql, *args)


import sys
logging.basicConfig(level=logging.DEBUG, stream=sys.stderr)
con = sqlite.connect(":memory:", factory=LoggingConnection)

con.execute("create table t(x,y,z)")
con.execute("insert into t(x) values (5)")
con.rollback()

con.execute("insert into t(x) values (4)")
con.commit()

con.execute("select * from t")
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.