Skip to content

Instantly share code, notes, and snippets.

@njamescouk
Last active January 29, 2018 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njamescouk/5620bdcfd4b6fb90b500a1ed477b14b4 to your computer and use it in GitHub Desktop.
Save njamescouk/5620bdcfd4b6fb90b500a1ed477b14b4 to your computer and use it in GitHub Desktop.
using tcl, sqlite and dbedit
package require Tk
package require sqlite3
source "dbedit.tcl"
# open example.db or create if absent
# dbhandle is how we access the db
set dbName ":memory:"
sqlite3 dbhandle $dbName
# set up sql to create & populate table
set createString { DROP TABLE IF EXISTS "rows";
DROP TABLE IF EXISTS "numbers";
CREATE TABLE "rows" (
"col1" TEXT,
"col2" TEXT,
"col3" TEXT);
CREATE TABLE "numbers" (
"number1" INTEGER,
"number2" INTEGER,
"number3" INTEGER);
INSERT INTO "rows"("col1", "col2", "col3")
VALUES ('one', 'two', 'three')
,('four','five','six');
INSERT INTO "numbers"("number1", "number2", "number3")
VALUES (1, 2, 3)
,(4,5,6);
}
# execute sql
dbhandle eval $createString
# create a 'UI' with a button which invokes dbedit on $dbhandle
set blurb "Example use of dbedit.tcl from
https://www.sqlite.org/cvstrac/wiki?p=TclDbEdit"
pack [text .e1 -width 50 -height 2 ]
.e1 insert 1.0 $blurb
.e1 configure -relief flat
.e1 configure -bg gray80
.e1 configure -state disabled
pack [label .l2 -text "Press the button to look at example.db
- this will open another window."]
# and this it where it happens
pack [button .b -text "view $dbName" -command "dbedit::start dbhandle"]
@njamescouk
Copy link
Author

njamescouk commented Jan 23, 2018

Looking for code examples pertinent to a CRUD tcl app I came across dbedit.tcl, explained here and downloadable from here

This is how I got it to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment