From luke.zou at ringcentral.com Fri Oct 14 08:46:20 2022 From: luke.zou at ringcentral.com (Luke Zou) Date: Mon Oct 17 07:26:57 2022 Subject: [odb-users] How to enable sqlite WAL in ODB Message-ID: <08A7548E-511D-49B5-9984-E9BD7ACE5B19@ringcentral.com> Hi. Our mobile app(iOS & android) is using the ODB, and we want to enable WAL model?https://www.sqlite.org/wal.html) . We used following code: auto db = std::shared_ptr(new odb::sqlite::database(dbFile, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_SHAREDCACHE | SQLITE_OPEN_FULLMUTEX, false)); odb::transaction t(db->begin()); db->execute ("PRAGMA journal_mode=WAL"); t.commit(); But I get the exception "cannot change into wal mode from within a transaction". Try to put db->execute ("PRAGMA journal_mode=WAL"); without putting it in the transaction will also "operation can only be performed in transaction" this exception. How can I enable WAL through ODB? Will all connections switch to WAL at the same time after opening? thanks. From boris at codesynthesis.com Mon Oct 17 08:30:59 2022 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Oct 17 08:25:07 2022 Subject: [odb-users] How to enable sqlite WAL in ODB In-Reply-To: <08A7548E-511D-49B5-9984-E9BD7ACE5B19@ringcentral.com> References: <08A7548E-511D-49B5-9984-E9BD7ACE5B19@ringcentral.com> Message-ID: Luke Zou writes: > odb::transaction t(db->begin()); > db->execute ("PRAGMA journal_mode=WAL"); > t.commit(); > > But I get the exception "cannot change into wal mode from within a > transaction". Try to put db->execute ("PRAGMA journal_mode=WAL"); > without putting it in the transaction will also "operation can only > be performed in transaction" this exception. The way to execute a statement outside of a transaction is to use the connection directly. Something like this should do the trick: db->connection ()->execute ("PRAGMA journal_mode=WAL"); > Will all connections switch to WAL at the same time after opening? Quoting from 3.3. "Persistence of WAL mode"[1]: "The persistence of WAL mode means that applications can be converted to using SQLite in WAL mode without making any changes to the application itself. One has merely to run "PRAGMA journal_mode=WAL;" on the database file(s) using the command-line shell or other utility, then restart the application." "The WAL journal mode will be set on all connections to the same database file if it is set on any one connection." I would still suggest executing this pragma at the start of your application, before any other connections are created to the database. [1] https://www.sqlite.org/wal.html