Last active
January 29, 2018 12:21
-
-
Save njamescouk/5620bdcfd4b6fb90b500a1ed477b14b4 to your computer and use it in GitHub Desktop.
using tcl, sqlite and dbedit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looking for code examples pertinent to a
CRUDtcl app I came across dbedit.tcl, explained here and downloadable from hereThis is how I got it to work.