在SQLite 3中启用查询日志 [英] Enable Query Logging in SQLite 3

查看:717
本文介绍了在SQLite 3中启用查询日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何内置功能可在SQLite中启用查询日志.

Is there any built-in function to enable query log in SQLite.

我熟悉 Trace API,但是我想知道是否有任何预定义的函数.

I am familiar with Trace API, but I want to know if there is any predefined function for it.

推荐答案

没有像MySQL那样简单的方法,但是有一些选择:

There is no easy way to do this like with MySQL, but there are some options:

一个:

一些包装器库具有类似内置的东西.但是要找到包装器库,您可能首先需要确定目标语言. Perl DBI? Python? C ++?

Some wrapper-libraries have something like this built-in. But to find a wrapper library you would probably first need to identify the target language. Perl DBI? Python? C++?

两个:

对于任何生产级"解决方案,我都不愿意(以任何方式)推荐以下内容,但是如果您主要是进行实验和/或调试,则可以尝试仅检查回滚日志.在每笔交易结束之前. 在此处查看有关回滚日志的信息:http://www.sqlite.org/tempfiles.html 如何检测每笔交易的结束"取决于您的代码和/或调试器中的断点.

I would not (in any way) recommend the following for a "production-grade" solution, but if you are mainly experimenting and/or debugging, then you might try examining the rollback journal just prior to the end of each transaction. See here about the rollback journal: http://www.sqlite.org/tempfiles.html How you would detect 'the end of each transaction' would be up to your code and/or the breakpoints in your debugger.

我必须再次强调:我上面刚刚提到的内容完全是骇客行为,即使提到它,我也感到很肮脏.

I must emphasize again: what I just mentioned above would be a total hack-around, and I feel dirty even having mentioned it.

三:

您可以(非常活跃和亲切)在 sqlite邮件发送中询问列表,但他们可能只会重新强调sqlite3_trace.

You could ask on the (very active and gracious) sqlite mailing list, but they would probably just reemphasize sqlite3_trace.

...其他随机事件:

在某种程度上(几乎没有?)上,当您启动"./sqlite3"命令提示符会话时,可以键入:

On a somewhat (barely?) related note, when you start a './sqlite3' command prompt session, you can type:

.explain

为在提示处执行的每个查询启用有趣且有启发性的详细输出.

which enables interesting and instructive verbose output for each query executed at the prompt.

我刚刚找到的更多信息:

可以传递给"sqlite3_config()"的标志之一是SQLITE_CONFIG_LOG. a>这是另一种方法(除了跟踪API之外),用于设置回调并定期从sqlite库接收状态信息.我认为它主要用于错误日志消息.

One of the flags that can be passed to 'sqlite3_config()' is SQLITE_CONFIG_LOG. This is another way (in addition to the trace API) to set a callback and receive status information from the sqlite library periodically. I think it is mainly for error log messages.

这篇关于在SQLite 3中启用查询日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆