SQLite Forum

[SOLVED] Getting SQLITE_LOCKED where SQLITE_BUSY is expected
Login
Using a programming language to do it you get the following:

```
Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import apsw
>>> db = apsw.Connection('test.db')
>>> db.begin()
<newapsw.Cursor object at 0x000002BB8208EA00>
>>> for row in db.execute('select x from x'): print(row)
...
Row(x=5)
>>> try:
...  db.execute('update x set x=-1')
... except BaseException as e:
...  x = e
...
>>> x
BusyError('BusyError: database is locked')
>>> x.extendedresult
517
```

Note that the extended error code is 517 (`SQLITE_BUSY_SNAPSHOT`)

This is because an attempt is being made to update a non-top read-locked snapshot to a write lock, but this cannot be done because in order for a read locked snapshot to be upgraded to a write locked snapshot, it must be at the top of stack.  However, another update was done in another connection, so the transaction is no longer able to be upgraded at the present time (and may or may not ever be able to be upgraded -- which case applies is up to the programmer to determine).

** NB:  I have MonkeyPatched APSW to have added methods such as .begin, .execute, and .commit to the apsw Connection class **