Small. Fast. Reliable.
Choose any three.

This information is obsolete. You are looking at the CVSTrac source management system display for SQLite that was replaced by Fossil on 2009-08-11. The information shown here has not been updated since that cut-over. These pages are retained for historical reference only.

demo.gif The attachment contains Tcl/Tk code that implements a console window that talks directly to an SQLite database. This can be a very useful component for debugging a Tcl/Tk application that uses SQLite.

The code for the SQLite console widget is in the attachment. The attachment is named with a ".txt" extension rather than ".tcl" so that the code will be displayed as plain text when you click on the attachment link. You can then scrape the code into a file for use in your application.

To use this widget, invoke the ::sqlitecon::create command with four arguments:

  1. The name of a new toplevel widget to hold the console
  2. A prompt string to be displayed within the console
  3. The title string to show on the title bar of the toplevel window
  4. The SQLite database handle for the database you want to access

Once the console window is displayed, you can type in SQL command have have their results displayed on the spot. The console widget also supports a few dot-commands:

   .table
   .schema ?TABLE?
   .mode list|column|multicolumn|line
   .exit

In addition, a new SQL function named "edit()" is created. This function takes a single text argument and returns a text result. Whenever the the function is called, it pops up a new toplevel window containing a text editor screen initialized to the argument. When the "OK" button is pressed, whatever revised text is in the text editor is returned as the result of the edit() function. This allows text fields of SQL tables to be edited quickly and easily as follows:

   UPDATE table1 SET dscr = edit(dscr) WHERE rowid=15;

The following short script illustrates how to use the SQLite console widget. This script takes a single argument which is the name of the database. The script opens the database then starts the console widget on that database.

   package require sqlite3
   set dbname [lindex $argv 0]
   sqlite3 db $dbname
   set title [file tail $dbname]
   source sqlitecon.tcl
   sqlitecon::create .console {sqlite> } $title db
   wm withdraw .
   bind .console <Destroy> {+if {"%W"==".console"} exit}

See Also

Attachments:

  • sqlitecon.txt 18817 bytes added by drh on 2005-Sep-23 11:41:57 UTC.
  • demo.gif 13335 bytes added by drh on 2005-Sep-23 11:52:43 UTC.