SQLite 中的 .quit 和 .exit 有区别吗?

发布于 2024-12-07 20:17:26 字数 1031 浏览 1 评论 0原文

我正在编写一个 VBScript 脚本来在 SQLite shell 中执行 SQL 查询,并且想知道是否需要使用 .quit 或 .exit。

当我在任务计划程序中设置任务来运行此 VBScript 脚本时,SQLite shell 无法正确退出/退出,因此每次任务计划程序运行时都会创建一个新实例,这会导致 SQL 查询无法执行被处决。当我双击 VBScript 脚本时,它运行良好并且 SQLite shell 正常存在。

我该如何解决这个问题?

脚本:

Dim objShell
Dim main_database_file, main_output_file, main_sqlite_file
Dim TAB, LINE

' Set default values here if necessary
main_database_file = "G:\example\data\reporting\lastmonth"
main_sqlite_file = "G:\example\sqlite-shell.exe"
main_output_file="G:\example\scripts\display-time.csv"

Set objShell = createObject("Wscript.Shell")

sql = "select * from project;"

objShell.Run """"& main_sqlite_file &"""" & """"& main_database_file &""""
WScript.Sleep(500)
objShell.Sendkeys(".separator ,{ENTER}")
objShell.Sendkeys(".headers ON{ENTER}")
objShell.Sendkeys(".output '" & main_output_file &"'{ENTER}")
objShell.Sendkeys(sql & "{ENTER}")
WScript.Sleep(500)
objShell.Sendkeys(".quit{ENTER}")
Set objShell = Nothing

I am writing a VBScript script to execute an SQL query in the SQLite shell and was wondering if I needed to use .quit or .exit.

When I set up a task in the task scheduler to run this VBScript script, the SQLite shell doesn’t exit/quit properly due to which I get a new instance created every time the task scheduler run and this is causes the SQL query to not be executed. When I double click on the VBScript script it runs fine and SQLite shell exists gracefully.

How can I fix this?

The script:

Dim objShell
Dim main_database_file, main_output_file, main_sqlite_file
Dim TAB, LINE

' Set default values here if necessary
main_database_file = "G:\example\data\reporting\lastmonth"
main_sqlite_file = "G:\example\sqlite-shell.exe"
main_output_file="G:\example\scripts\display-time.csv"

Set objShell = createObject("Wscript.Shell")

sql = "select * from project;"

objShell.Run """"& main_sqlite_file &"""" & """"& main_database_file &""""
WScript.Sleep(500)
objShell.Sendkeys(".separator ,{ENTER}")
objShell.Sendkeys(".headers ON{ENTER}")
objShell.Sendkeys(".output '" & main_output_file &"'{ENTER}")
objShell.Sendkeys(sql & "{ENTER}")
WScript.Sleep(500)
objShell.Sendkeys(".quit{ENTER}")
Set objShell = Nothing

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

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

发布评论

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

评论(3

梦屿孤独相伴 2024-12-14 20:17:26

好吧,根据 文档.quit.exit 是“退出这个程序”,所以我不相信,不。

Well, according to the documentation, the description of both .quit and .exit is "Exit this program", so I don't believe so, no.

我一向站在原地 2024-12-14 20:17:26

我同意杰克的观点,医生说没有区别。
但是,为什么不将命令输入到命令行处理器呢?您可以创建一个包含上述每个步骤的“SQL”文件,然后执行单个运行命令:

类似于(未测试!)

SQL 文件:

.separator ,
.headers on
etc..

然后运行此文件:

shell.run "sqlite-clp.exe mydb.db < sqlfile.sql"

不需要任意超时,并且您也许也可以传入参数。

PS:问题可能是在计划任务的上下文中运行的 sendkeys

I would agree with Jack that the doc states no difference.
However, why not pipe your commands in to the Command-Line-Processor? You can create a 'SQL' file containing each of the steps above and then execute the single run command:

Something like (not tested!)

SQL file:

.separator ,
.headers on
etc..

Then run this file as:

shell.run "sqlite-clp.exe mydb.db < sqlfile.sql"

There isn't any need for arbitrary timeouts, and you can probably pass in parameters too.

PS: It's probably sendkeys running in the context of a scheduled task that is the problem

¢蛋碎的人ぎ生 2024-12-14 20:17:26

我认为唯一的区别是 .quit 在某些 Unix 系统上不起作用。

I think the only difference is .quit doesn't work on some Unix systems.

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