是否通过回滚事务来撤消 pragma 语句?

发布于 2024-12-03 20:56:10 字数 102 浏览 4 评论 0原文

如果诸如 foreign_keys = OFFVACUUM 之类的编译指示包含在回滚的事务中,是否会被撤消?文档似乎没有涵盖这一点。

Would pragmas such as foreign_keys = OFF and VACUUM be undone if included in a transaction which gets rolled back? The documentation doesn't seem to cover this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风渺 2024-12-10 20:56:10

不同的编译指示语句是不同的。

SQLite 版本 3.7.15.2 在事务中包含 pragma user_version 并将 COMMIT 和 ROLLBACK 该值。但是,它(在文档和测试中)从交易中排除了 foreign_keys。看来在事务期间未记录为无效的编译指示将参与事务。

It is different for different pragma statements.

SQLite version 3.7.15.2 includes the pragma user_version in transactions and will COMMIT and ROLLBACK the value. However, it excludes (in documentation and testing) foreign_keys from transactions. It appears that pragmas not documented as invalid during transactions will participate in a transaction.

与之呼应 2024-12-10 20:56:10

该文档不涵盖一般事务内发出的 pragma 语句会发生什么,但它确实涵盖了 的主题foreign_keys(可能也适用于其他):

此编译指示是事务中的无操作;外键约束
仅当没有待处理的情况时才可以启用或禁用强制执行
开始或保存点。

VACUUM 不是一个编译指示,文档确实涵盖了事务:

如果有未完成的事务,或者有
运行时的一个或多个活动 SQL 语句。

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.

空城仅有旧梦在 2024-12-10 20:56:10

我可以验证至少以下 PRAGMA 在事务中无效:

PRAGMA journal_mode=WAL;

如果尝试,您将收到以下错误消息:

SQL 逻辑错误:无法从事务内更改为 wal 模式

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文