Using Sqlite with WAL

Viewed 1798

I've been following Python documentation on the SQLite tutorial and I managed to create an Employee table and write to it.

import sqlite3

conn = sqlite3.connect('employee.db')
c = conn.cursor()

firstname = "Ann Marie"
lastname = "Smith"
email = "ams@cia.com"

employee = (email, firstname, lastname)

c.execute('INSERT INTO Employee Values (?,?,?)', employee)
conn.commit()

# Print the table contents
for row in c.execute("select * from Employee"):
    print(row)

conn.close()

I've been reading about the Write-Ahead Logging, but I can't find a tutorial that explains how to implement it. Can someone provide an example?

I notice Firefox, which uses SQLite, locks the file in such a way that if you attempt to delete the sqlite file while using Firefox, it will fail saying "file is open or being used"(or something similar), how do I achieve this? I'm running Python under Windows 10.

2 Answers
conn = sqlite3.connect('app.db', isolation_level=None)

Set journal mode to WAL:

conn.execute('pragma journal_mode=wal')

Or another way (just show how to off wal mode)

cur = conn.cursor()
cur.execute('pragma journal_mode=DELETE')
Related