SQLite User Forum

How to circumvent ”apsw.BusyError: BusyError: database is locked”?
Login
If you execute `pragma journal_mode;` you will get back the journal_mode in effect. Actually, when you execute `pragma journal_mode=WAL;` you will get back the journal mode in effect after the command is executed.

```
if c.execute('pragma journal_mode;').fetchone()[0] <> 'wal':
   if c.execute('pragma journal_mode=wal;').fetchone()[0] <> 'wal':
      raise apsw.Error('Cannot change database to WAL')
```

You can of course skip the testing and just set the journal_mode and see if it worked.

```
if c.execute('pragma journal_mode=wal;').fetchone()[0] <> 'wal':
      raise apsw.Error('Cannot change database to WAL')
```

Changing the database journal_mode is never harmful.  If you change it to something you do not want to change it to, you may be unhappy with the result, but it will not harm anything.  That is, it will cause the expected result.