SQLite 查询进度条 [英] SQLite query progress bar

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

问题描述

我正在使用 C++ 中的 sqlite 并且我想实现一个进度条来通知用户搜索的进度.

I am using sqlite from c++ and I want to implement a progress bar that will inform user about the progress of a search.

使用 sqlite3_progress_handler 我可以将 ca 回调设置为每 N 个虚拟机调用一次说明.这对于通知用户应用仍在运行的无限进度条来说没问题.

Using sqlite3_progress_handler I can set ca callback to be called every N virtual machine instructions. This is ok for an infinite progress bar that is notifying user the app is still working.

我需要的是从 0 -> 100% 的进步.可以这样做吗?

What I need is a progress from 0 -> 100%. Can this be done ?

推荐答案

我意识到这有点晚了,这个问题已经有一个公认的答案,但我认为多一点信息会很有用.

I realize that this is a bit late, and that this question already has an accepted answer, but I think a little more information would be useful.

正如问题中的 OP 所指出的,sqlite3_progress_handler 可以配置为每 N 个 VM 指令调用一次回调函数.这不是时间进度监视器或查询语句进度监视器,而是查询规划器为查询计算的 VM 指令的监视器(这将在紧要关头完成).

As the OP noted in the question, the sqlite3_progress_handler can be configured to call the callback function every N VM instructions. This is not a time progress monitor or a query statement progress monitor, but a monitor for the VM instructions that the query planner has calculated for the query (which will do in a pinch).

通过在查询前加上EXPLAIN QUERY PLAN"(或简称EXPLAIN")并步进结果以获得计数,您将知道查询计划中有多少 VM 指令.这是你的 100% 数字.

By prefacing the query with 'EXPLAIN QUERY PLAN' (or just 'EXPLAIN' for short) and stepping the results to get a count, you will know how many VM instructions are in the query plan. There's your 100% figure.

请务必阅读 SQLite.org 网站上有关 EXPLAIN QUERY PLAN 命令的警告,尤其是关于不依赖输出格式的部分.但是对于这种情况,我们不关心结果中的信息,而只关心指令的数量.

BE SURE to read the caveats on the SQLite.org website about the EXPLAIN QUERY PLAN command, especially the part about not relying on the output format. But for this situation, we're not concerned with the information in the results, but only the number of instructions.


从 SQLite 版本 3.24.0 (2018-06-04) 开始,EXPLAIN QUERY PLAN 命令的输出格式与 EXPLAIN 命令有很大不同.EXPLAIN QUERY PLAN 不再适合这个用例;您必须指定 EXPLAIN 命令本身.


As of SQLite version 3.24.0 (2018-06-04), the output format for the EXPLAIN QUERY PLAN command diverged significantly from the EXPLAIN command. EXPLAIN QUERY PLAN is no longer suitable for this use case; you have to specify the EXPLAIN command itself.

需要明确的是,EXPLAIN 命令并未发布为支持 sqlite3_progress_handler() API.在这种情况下可以使用它的事实纯属巧合.您应该始终测试这是否适用于您使用的任何版本的 SQLite.

To be clear, the EXPLAIN command is not published as supporting the sqlite3_progress_handler() API. The fact that it can be used in this case is purely coincidental. You should always test that this works on whichever version of SQLite you are using.

这篇关于SQLite 查询进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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