首页 > 解决方案 > 如何使事务在 SQLite 的 DB Browser 中按预期工作?

问题描述

我正在现有数据库上测试一组迁移代码。

我尝试在 SQLite 的 DB Browser 中在一个事务中执行多个 SQLite 语句。

BEGIN TRANSACTION;
CREATE TABLE `plain_note_new` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `label` TEXT, `title` TEXT, `body` TEXT, `type` INTEGER NOT NULL, `color_index` INTEGER NOT NULL, `custom_color` INTEGER NOT NULL, `locked` INTEGER NOT NULL, `pinned` INTEGER NOT NULL, `checked` INTEGER NOT NULL, `archived` INTEGER NOT NULL, `trashed` INTEGER NOT NULL, `sticky` INTEGER NOT NULL, `sticky_icon` INTEGER NOT NULL, `order` INTEGER NOT NULL, `searched_string` TEXT, `reminder_type` INTEGER NOT NULL, `reminder_timestamp` INTEGER NOT NULL, `reminder_repeat` INTEGER NOT NULL, `reminder_end_timestamp` INTEGER NOT NULL, `reminder_active_timestamp` INTEGER NOT NULL, `reminder_last_timestamp` INTEGER NOT NULL, `reminder_repeat_frequency` INTEGER NOT NULL, `reminder_day_of_week_bitwise` INTEGER NOT NULL, `created_timestamp` INTEGER NOT NULL, `modified_timestamp` INTEGER NOT NULL, `trashed_timestamp` INTEGER NOT NULL, `synced_timestamp` INTEGER NOT NULL, `uuid` TEXT NOT NULL);
INSERT INTO `plain_note_new` SELECT `id`, `label`, `title`, `body`, `type`, `color_index`, `custom_color`, `locked`, `pinned`, `checked`, `archived`, `trashed`, `sticky`, `sticky_icon`, `order`, `searched_string`, `reminder_type`, `reminder_timestamp`, `reminder_repeat`, `reminder_end_timestamp`, `reminder_active_timestamp`, `reminder_last_timestamp`, `reminder_repeat_frequency`, `reminder_day_of_week_bitwise`, `created_timestamp`, `modified_timestamp`, `trashed_timestamp`, `synced_timestamp`, `uuid` FROM `plain_note`;
DROP INDEX `index_plain_note_archived`;
DROP INDEX `index_plain_note_label`;
DROP INDEX `index_plain_note_sticky`;
DROP INDEX `index_plain_note_trashed`;
DROP INDEX `index_plain_note_uuid`;
DROP TABLE `plain_note`;

BAD COMMAND;

ALTER TABLE `plain_note_new` RENAME TO `plain_note`;
CREATE INDEX `index_plain_note_archived` ON `plain_note` (`archived`);
CREATE INDEX `index_plain_note_label` ON `plain_note` (`label`);
CREATE INDEX `index_plain_note_sticky` ON `plain_note` (`sticky`);
CREATE INDEX `index_plain_note_trashed` ON `plain_note` (`trashed`);
CREATE UNIQUE INDEX `index_plain_note_uuid` ON `plain_note` (`uuid`);
CREATE INDEX `index_plain_note_uuid_synced_timestamp` ON `plain_note` (`uuid`, `synced_timestamp`);
COMMIT;

我预计由于BAD COMMAND,事务将不会被提交。因此,索引和表都不会被删除。

但是,当我单击播放按钮时

在此处输入图像描述

表和索引仍在被删除。

即使我重新开始,并尝试COMMIT从 UI 中删除,结果仍然不理想(删除了plain_note 表,并删除了多个索引)

我希望由于我们没有结束事务,因此不应该发生实际的表和索引删除。我可以知道,为什么会这样?

标签: sqlite

解决方案


SQLite 的数据库浏览器根据此文档管理事务。观察到,即使是 COMMIT;发出后,Write ChangesRevert Changes按钮仍处于活动状态。我希望 DB4S放弃事务命令(开始、提交、回滚)以保持 Write 和 Revert Changes 按钮的完整性。


推荐阅读