Version 8 of BWidget example: sqlite progress bar

Updated 2011-02-21 22:12:43 by EE

To display the progress of a longer sqlite-query you can use BWidget::ProgressBar (or ProgressDlg).

 package require Tk
 package require BWidget
 load tclsqlite3.dll

 ProgressBar .p -type infinite -variable value
 pack .p

 # connect to a database
 sqlite db ":memory:"

 # add data to your database
 db eval "INSERT ..."

 # register the callback that which will be invoked every $opcodeNumber opcodes
 # test to find the best opcodeNumber for your application
 # without the update-command an error (callback requested query abort) occurs
 set opcodeNumber 1000
 db progress $opcodeNumber  {
  set value 1
  update
 }

 db eval $longRunningQuery

Because there is no generic way to determine how long the query will run, this example uses an infinite progress bar


EE -- The reason that the error occurs without the update is documented at http://www.sqlite.org/c3ref/progress_handler.html , which states If the progress callback returns non-zero, the operation is interrupted. This feature can be used to implement a "Cancel" button on a GUI progress dialog box.

In general, update is rarely the correct solution. Replacing it with return 0 should probably work.