Just wondering whether pragmas such as foreign_keys = OFF, and VACUUM would be undone if included in a transaction 开发者_如何学编程which gets rolled back.
The online documentation doesn't seem to cover this...
It is different for different pragma statements.
For example, SQLite version 3.7.15.2 includes the pragma 'user_version' in transactions and will COMMIT and ROLLBACK the value.
However, the same version of SQLite specifically excludes (in documentation and testing) foreign_keys from transactions.
It appears, from my limited sampling, that pragma that are not documented as invalid during transactions (foreign_key) will participate in the transaction (like user_version.)
PS: I realize this is a very old question, but it is where Google brought me when I needed this information.
The documentation does not cover what happens with pragma statements issued inside transactions in general, but it does cover the subject for foreign_keys (and possibly for others):
This pragma is a no-op within a transaction; foreign key constraint enforcement may only be enabled or disabled when there is no pending BEGIN or SAVEPOINT.
VACUUM is not a pragma, and the documentation does cover transactions:
A VACUUM will fail if there is an open transaction, or if there are one or more active SQL statements when it is run.
I can verify that at least the following PRAGMA is not valid within a transaction:
PRAGMA journal_mode=WAL;
If attempted, you will receive some flavor of the following error message:
SQL logic error: cannot change into wal mode from within a transaction
精彩评论