sqlite icon indicating copy to clipboard operation
sqlite copied to clipboard

sqlitex.ExecScript fails to run scripts that include statements that cannot be executed within a transaction

Open DrGo opened this issue 5 years ago • 2 comments

@crawshaw @AdamSLevy

Currently, ExecScript executes passed script within a SAVEPOINT transaction. This prevents certain commands from running, eg, vacuum, begin. These are commonly used commands in SQL scripts. Should we have a different version that does not automatically SAVEPOINT?

Thanks,

DrGo avatar Jan 02 '21 22:01 DrGo

@DrGo ExecScript runs a SAVEPOINT by design so that scripts can be run atomically. I understand there are certain operations you can't do inside of a transaction such as vacuuming, but why would you want to use BEGIN when you could just use SAVEPOINT or break up your script using the go APIs for nested transactions?

For the one off vacuum, which I generally do after a database migration, I just use sqlitex.Exec instead. Or rather ExecTransient because I don't think its a Stmt worth caching.

Can you expand on the usecase of having an ExecScript-like function that did not use a SAVEPOINT, or an option to not use it?

AdamSLevy avatar Nov 07 '21 01:11 AdamSLevy

I think perhaps this is the explanation for the issue I opened: https://github.com/crawshaw/sqlite/issues/131

So the use case for me is to run a PRAGMA statement on all connections - for example to enforce FOREIGN_KEYS.

I see @DrGo have a solution here which seems reasonable: https://github.com/DrGo/sqlite/commit/018b2434e9e4ab2ed9712caf59df8ce7e902dcbf

boutros avatar May 09 '22 23:05 boutros