Re: [sqlite] Deserialize a WAL database file
On Fri, 1 Mar 2019 at 18:26, Lloyd wrote: > I have two database files. One in Rollback mode and the other in WAL mode. > I am able to serialize, deserialize and prepare a SQL query against the > rollback database. When I do the same against the WAL database file, the > 'prepare' statement fails with code '1'. Is it not possible to do this on > WAL based database file? A sample code fragment is given below- > > sqlite3 *dbHandle=nullptr; > if (sqlite3_open_v2("db_filename", &dbHandle, SQLITE_OPEN_READONLY, NULL) > != SQLITE_OK){//error} > > sqlite3_int64 sz=0; > unsigned char* mem=sqlite3_serialize(dbHandle,"main",&sz,0); > > if(sqlite3_deserialize(dbHandle, "main", mem, sz, > sz,SQLITE_DESERIALIZE_READONLY) != SQLITE_OK){//error} > > char* Query = "select * from test"; > sqlite3_stmt *statement = nullptr; > int res=sqlite3_prepare_v2(dbHandle, Query, strlen(Query), &statement, 0); > //res is 1 for WAL > I can't see any obvious reason for this. The WAL database definitely has a table called test? Is sqlite3_serialize returning non-NULL in the WAL case? Check what sqlite3_errmsg(dbHandle) has to say. -Rowan ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Deserialize a WAL database file
On Fri, Mar 1, 2019 at 4:09 PM Simon Slavin wrote: > On 1 Mar 2019, at 10:27am, Lloyd wrote: > > > I am able to serialize, deserialize and prepare a SQL query against the > rollback database. When I do the same against the WAL database file, the > 'prepare' statement fails with code '1'. > > It's possible that some of the data for the WAL database is in the journal > and hasn't been written back to the database properly. Was that database > correctly closed when last used ? > > Using the SQLite command-line tool, > open the database > run "PRAGMA integrity_check;" on it > close the database > > Then try serializing it again. If still fails, do the above again but > "VACUUM;" it instead of the integrity_check. > > Simon. > I forgot to mention that the database is in a good state. No temp WAL/SHM files exist in the directory. I tried the steps you suggested. Integrity check returned 'ok'. Executed vacuum command also. Still, the prepare statement fails with 1. This is a small test database created. I closed the database from shell using '.quit' command. I believe that it closes the connection properly. > ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Deserialize a WAL database file
On 1 Mar 2019, at 10:27am, Lloyd wrote: > I am able to serialize, deserialize and prepare a SQL query against the > rollback database. When I do the same against the WAL database file, the > 'prepare' statement fails with code '1'. It's possible that some of the data for the WAL database is in the journal and hasn't been written back to the database properly. Was that database correctly closed when last used ? Using the SQLite command-line tool, open the database run "PRAGMA integrity_check;" on it close the database Then try serializing it again. If still fails, do the above again but "VACUUM;" it instead of the integrity_check. Simon. ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Deserialize a WAL database file
I have two database files. One in Rollback mode and the other in WAL mode. I am able to serialize, deserialize and prepare a SQL query against the rollback database. When I do the same against the WAL database file, the 'prepare' statement fails with code '1'. Is it not possible to do this on WAL based database file? A sample code fragment is given below- sqlite3 *dbHandle=nullptr; if (sqlite3_open_v2("db_filename", &dbHandle, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK){//error} sqlite3_int64 sz=0; unsigned char* mem=sqlite3_serialize(dbHandle,"main",&sz,0); if(sqlite3_deserialize(dbHandle, "main", mem, sz, sz,SQLITE_DESERIALIZE_READONLY) != SQLITE_OK){//error} char* Query = "select * from test"; sqlite3_stmt *statement = nullptr; int res=sqlite3_prepare_v2(dbHandle, Query, strlen(Query), &statement, 0); //res is 1 for WAL Thanks, Lloyd ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users