Skip to content Skip to sidebar Skip to footer

Sqlite3 Cursors Live Updating?

Can someone please explain this to me: import sqlite3 db = sqlite3.connect(':memory:') db.execute('create table t1 (id integer primary key, val text)') db.execute('create table t

Solution 1:

SQLite computes results rows on demand, if possible. But this is not always possible, so there is no guarantee.

You should never modify any table that you are currently reading in another query. (The database might scan the table in unobvious ways, so even changes to other rows might change the enumeration.)

If you intend to do such modifications, you have to read all rows before doing the changes, e.g., for row in c.fetchall(). Alternatively, read the table in single steps that re-search for the place where the last query left, i.e.:

SELECT ... FROM MyTable WHERE ID > :LastID ORDERBY ID LIMIT 1;

Post a Comment for "Sqlite3 Cursors Live Updating?"