Skip to content

Autocommit behaves differently from sqlite3 #58

Closed
@simonw

Description

@simonw

I was getting the error "cannot change into wal mode from within a transaction" when trying to switch to WAL mode using this code:

db.execute('PRAGMA journal_mode=wal;')

Upon further experimentation, it appears that setting db.isolation_level = None fixes this - but this fix is not necessary for sqlite3. Here's a console session illustrating the difference between the two:

>>> import sqlite3
>>> db = sqlite3.connect("/tmp/1.db")
>>> db.isolation_level
''
>>> db.execute('PRAGMA journal_mode;').fetchall()
[('delete',)]
>>> db.execute('PRAGMA journal_mode=wal;')
<sqlite3.Cursor object at 0x7f272ef748c0>
>>> db.execute('PRAGMA journal_mode;').fetchall()
[('wal',)]

Now the same sequence with pysqlite3:

>>> import pysqlite3
>>> db2 = pysqlite3.connect("/tmp/2.db2")
>>> db2.isolation_level
''
>>> db2.execute('PRAGMA journal_mode;').fetchall()
[('delete',)]
>>> db2.execute('PRAGMA journal_mode=wal;')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pysqlite3.dbapi2.OperationalError: cannot change into wal mode from within a transaction
>>> db2.isolation_level = None
>>> db2.execute('PRAGMA journal_mode=wal;')
<pysqlite3.dbapi2.Cursor object at 0x7f272ef45d80>
>>> db2.execute('PRAGMA journal_mode;').fetchall()
[('wal',)]

Is this a deliberate difference, or accidental?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions