如何从命令批处理文件中退出SQLite?

ajsxfq5m  于 2022-11-15  发布在  SQLite
关注(0)|答案(2)|浏览(181)

我正在尝试为我的构建管道创建一个密封的命令,用于插入数据和退出。
到目前为止,我已经创建了我的数据文件
things-to-import-001.sql002等,其中包含我想要运行的所有INSERT语句,每个表一个文件。
我已经创建了一个命令文件来运行它们

-- import-all.sql
.read ./things-to-import-001.sql
.read ./things-to-import-002.sql
.quit

但是当我运行我的命令时

sqlite3 -init ./import-all.sql ./database.sqlite

..数据已插入,但尽管有.quit命令,程序仍保持运行并显示sqlite>提示符。我也尝试过使用.exit 0
sqlite3 --help

-init FILENAME       read/process named file

文档:https://www.sqlite.org/cli.html#reading_sql_from_a_file
插入完成后,如何告诉SQLite退出?

6pp0gazn

6pp0gazn1#

我已经设法为这个问题找到了一个肮脏的解决方法。
我已经更新了我的导入文件以包含一个错误的命令,并使用-bail执行以在出现第一个错误时退出。

-- import-all.sql
.read ./things-to-import-001.sql
.read ./things-to-import-002.sql
.fakeErrorToQuitWithBail

然后您可以使用以下命令执行
sqlite3 -init import-all.sql -bail
它应该退出,带着
Error: unknown command or invalid arguments: "fakeErrorToQuitWithBail". Enter ".help" for help

7fyelxc5

7fyelxc52#

试着用“.it”代替“.it”。出于某种原因,SQLite没有对此命令进行文档整理。
https://www.tutorialspoint.com/sqlite/sqlite_commands.htm

相关问题