SQLite BUSY on commit callback

Viewed 144

The idea is to make backup of a database by calling trace callback. But in some reason sqlite is busy on commit (code 5 - status arg in __progress func). The doc says about backup method.

"This method makes a backup of a SQLite database even while it’s being accessed by other clients, or concurrently by the same connection"

import sqlite3


db_name = "main.db"
init_sql = "CREATE TABLE IF NOT EXISTS app_states (\
sync_state_id INTEGER NOT NULL);\
INSERT INTO app_states (sync_state_id) VALUES (1)"

conn1 = sqlite3.connect(db_name)
conn1.executescript(init_sql)
conn2 = sqlite3.connect(db_name+".temp")
in_memory_db = sqlite3.connect(":memory:")

conn1.backup(in_memory_db)

def __progress(status, remaining, total):
    print(status, remaining, total)

def backup_callback(s):
    print(s)
    if ("commit" in s.lower()):
        in_memory_db.backup(conn2, pages=1, progress=__progress)

in_memory_db.set_trace_callback(backup_callback)

in_memory_db.execute(f"BEGIN TRANSACTION")
in_memory_db.execute("UPDATE app_states SET sync_state_id=2")
in_memory_db.execute("COMMIT")

conn1.close()
conn2.close()
in_memory_db.close()
0 Answers
Related