SQLite Forum

Database WAL snapshot
Login
I have an open database connection, and am opening a second connection to the same database. I need those connections to see the same data, so I'm trying to use the "sqlite3_snapshot_get" functionality.

However, it's not working for me. Could someone help point out what I'm doing wrong?
My process:

 - The database is in WAL mode, and there are no open connections to it (so no "-shm" and "-wal" files)
 - Open database connection 1 read-only
 - Start a transaction on connection 1, and read some things
 - (In another process) write some new data to the database
 - As expected, the "-shm" and "-wal" files exist, and connection 1 cannot see the changes made (if I actually do some queries, which I do not do in this reproduction)
 - Open database connection 2 read-only
 - Call `sqlite3_snapshot_get(connection1, "main", &snapshot)`
 - This returns SQLITE_ERROR

Based on the [documentation](https://www.sqlite.org/c3ref/snapshot_get.html) however, I expected this to return SQLITE_OK and a snapshot:

 - The database is not in autocommit mode (I have an open transaction)
 - Schema "main" is in WAL mode
 - There is no write transaction open on connection 1 (there is no open write transaction at all)
 - The WAL file has a written transaction

Thus, I am unable to apply such a snapshot to connection 2.