the world's most popular tcl extension · the world's most popular tcl extension d....
TRANSCRIPT
![Page 1: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/1.jpg)
The World's MostPopular TCL Extension
D. Richard Hipp16th Annual Tcl/Tk Conference
Portland, OR2009-09-30
![Page 2: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/2.jpg)
“The only SQL database enginespecifically designed to workwith TCL”
![Page 3: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/3.jpg)
![Page 4: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/4.jpg)
![Page 5: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/5.jpg)
SQLite is a TCL Extension
![Page 6: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/6.jpg)
![Page 7: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/7.jpg)
DatabaseFiles on
Disk
SQL Database
Engine
Client
Client Client
Client
![Page 8: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/8.jpg)
DatabaseFiles on
Disk
SQL Database
Engine
Client
Client Client
Client
![Page 9: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/9.jpg)
![Page 10: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/10.jpg)
DatabaseFiles on
Disk
Client
Client Client
Client
![Page 11: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/11.jpg)
Application Tcl/Tk Code
High-levelSQL statements
Low-level diskreads & writes
![Page 12: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/12.jpg)
● Program at a higher level● Programming by specification● Heads-up programming
– Focus on your product, not on your underlying database
– Maintain “situational awareness”
Why SQL?
![Page 13: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/13.jpg)
Do not underestimate the importance of situational awareness!
![Page 14: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/14.jpg)
SELECT value FROM array WHERE name='userid';
Easier to do with an array or dict:
$array('userid')
![Page 15: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/15.jpg)
SELECT eqptid, enclosureid FROM eqpt WHERE typeid IN ( SELECT typeid FROM typespec WHERE attrid=( SELECT attrid FROM attribute WHERE name='detect_autoactuate' ) AND value=1 INTERSECT SELECT typeid FROM typespec WHERE attrid=( SELECT attrid FROM attribute WHERE name='algorithm' ) AND value IN ('sensor','wetbulb') )
How many lines of TCL are required to do this using justarrays and dicts?
![Page 16: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/16.jpg)
![Page 17: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/17.jpg)
SELECT h.url, h.title, f.url, (SELECT b.parent FROM moz_bookmarks b JOIN moz_bookmarks t ON t.id = b.parent AND t.parent != ?1 WHERE b.type = 1 AND b.fk = h.id ORDER BY b.lastModified DESC LIMIT 1) AS parent, (SELECT b.title FROM moz_bookmarks b JOIN moz_bookmarks t ON t.id = b.parent AND t.parent != ?1 WHERE b.type = 1 AND b.fk = h.id ORDER BY b.lastModified DESC LIMIT 1) AS bookmark, (SELECT GROUP_CONCAT(t.title, ',') FROM moz_bookmarks b JOIN moz_bookmarks t ON t.id = b.parent AND t.parent = ?1 WHERE b.type = 1 AND b.fk = h.id) AS tags, h.visit_count, h.typed, h.frecency FROM moz_places_temp h LEFT OUTER JOIN moz_favicons f ON f.id = h.favicon_id WHERE h.frecency <> 0UNION ALL SELECT h.url, h.title, f.url, (SELECT b.parent FROM moz_bookmarks b JOIN moz_bookmarks t ON t.id = b.parent AND t.parent != ?1 WHERE b.type = 1 AND b.fk = h.id ORDER BY b.lastModified DESC LIMIT 1) AS parent, (SELECT b.title FROM moz_bookmarks b JOIN moz_bookmarks t ON t.id = b.parent AND t.parent != ?1 WHERE b.type = 1 AND b.fk = h.id ORDER BY b.lastModified DESC LIMIT 1) AS bookmark, (SELECT GROUP_CONCAT(t.title, ',') FROM moz_bookmarks b JOIN moz_bookmarks t ON t.id = b.parent AND t.parent = ?1 WHERE b.type = 1 AND b.fk = h.id) AS tags, h.visit_count, h.typed, h.frecency FROM moz_places h LEFT OUTER JOIN moz_favicons f ON f.id = h.favicon_id WHERE h.id NOT IN (SELECT id FROM moz_places_temp) AND h.frecency <> 0ORDER BY 9 DESC
![Page 18: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/18.jpg)
Other benefits SQL & SQLite:
● Persistent● Transactional● Cross-platform● Widely known and understood● Faster● Fewer bugs● SQL is good at doing the very few things that
TCL does not already do well.
![Page 19: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/19.jpg)
tcl/tk
![Page 20: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/20.jpg)
Aside: How do you classifySQLite in TCL?
● A “small language within a small language”?
● A meta-small language?
![Page 21: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/21.jpg)
% package require sqlite33.6.19% sqlite3 db database.db%
.Na me of the d a ta ba se fi le A n ew on e i s crea ted i f i t d oes
.n ot a l r ea d y exi st
Ne w o b je ct fo rc o n tr o ll i ng the d a ta b a se
![Page 22: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/22.jpg)
db eval { CREATE TABLE users( userid INTEGER, first_name VARCHAR(30), last_name VARCHAR(40) );}
“ ” Use the eva l m ethod to run SQL
Sem i colon sepa ra tes mu l t i ple .SQL sta temen ts
.Fi n a l sem i colon i s opti on a l
user first_name last_name
![Page 23: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/23.jpg)
user first_name last_name
db eval { CREATE TABLE users( userid INTEGER, first_name VARCHAR(30), last_name VARCHAR(40) );}
![Page 24: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/24.jpg)
db eval { CREATE TABLE users( userid INTEGER, first_name VARCHAR(30), last_name VARCHAR(40) );}
, Da ta types a re i gn ored mostly
user first_name last_name
![Page 25: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/25.jpg)
Trad
ition
al S
QL ● Rigid typing
● Types declared on containers● Exceptions if type rules are violated
![Page 26: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/26.jpg)
Trad
ition
al S
QL ● Rigid typing
● Types declared on containers● Exceptions if type rules are violated
● No types - everything is a string● Internal dual representation● Very flexible
![Page 27: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/27.jpg)
Trad
ition
al S
QL ● Rigid typing
● Types declared on containers● Exceptions if type rules are violated
● No types - everything is a string● Internal dual representation● Very flexible
![Page 28: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/28.jpg)
Trad
ition
al S
QL ● Rigid typing
● Types declared on containers● Exceptions if type rules are violated
● Type associated with values● Containers have a “suggested type”● All types accepted by every container
● No types - everything is a string● Internal dual representation● Very flexible
![Page 29: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/29.jpg)
db eval { CREATE TABLE users( userid INTEGER, first_name VARCHAR(30), last_name VARCHAR(40) );}
Va lu es con ver ted to i n teger . i f they ca n be Otherwi se
.stored a s they a re
user first_name last_name
Add i t i on a l i n form a ti on a t :// . . / 3 .http www sql i te org d a ta type htm l
.Va lu es con ver ted to str i n gs Len gth r estr i ct i on s a re i gn ored
![Page 30: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/30.jpg)
db eval { INSERT INTO users VALUES(1, 'D. Richard', 'Hipp')}
Use a n I NSERT sta tem en t to a d d da ta
![Page 31: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/31.jpg)
user first_name last_name
1 D. Richard Hipp
db eval { INSERT INTO users VALUES(1, 'D. Richard', 'Hipp')}
![Page 32: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/32.jpg)
db eval { SELECT user, first_name, last_name FROM users}1 {D. Richard} Hipp
Use a SELECT sta tem en t to extr a ct d a ta fr om the d a ta ba se
![Page 33: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/33.jpg)
db eval { SELECT user, first_name, last_name FROM users}1 {D. Richard} Hipp
Da ta retu rn ed i n a TCL l i st
![Page 34: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/34.jpg)
user first_name last_name
1 D. Richard Hipp
db eval { INSERT INTO users VALUES(2, 'Ginger', 'Wyrick')}
2 Ginger Wyrick
![Page 35: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/35.jpg)
db eval { SELECT * FROM users}1 {D. Richard} Hipp 2 Ginger Wyrick
Add i t i on a l r ows of d a ta ju st ma ke the r etu rn ed l i st lon ger
![Page 36: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/36.jpg)
sqlite3 db database.dbdb eval {SELECT * FROM user} { puts userid=$userid puts “name=$first_name $last_name”}userid=1name=D. Richard Hippuserid=2name=Ginger Wyrick
Scr i pt r un s on ce for ea ch row i n resu l t
set
Column con ten ts store i n TCL va r i a bles
![Page 37: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/37.jpg)
sqlite3 db database.dbdb eval {SELECT * FROM user} { puts userid=$userid puts “name=$first_name $last_name” break}userid=1name=D. Richard Hipp “ ” “ ” brea k a n d con ti n u e work
i n the u sua l wa y
![Page 38: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/38.jpg)
db eval {SELECT * FROM user} breakset userid1set first_nameD. Richardset last_nameHipp
Va r i a bles persi st a fter the la st i ter a t i on of the
loop
![Page 39: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/39.jpg)
user first_name last_name
1 D. Richard Hipp
picture
Ne w Co l u m n Ad d ed
db eval { ALTER TABLE user ADD COLUMN picture;}
![Page 40: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/40.jpg)
set in [open drh.jpg]fconfigure $in -translation binaryset drhphoto [read $in]close $indb eval { UPDATE user SET picture=$drhphoto WHERE user=1}
- ,Note the use of cu r ly br a cesn ot -double quotes
![Page 41: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/41.jpg)
set in [open drh.jpg]fconfigure $in -translation binaryset drhphoto [read $in]close $indb eval { UPDATE user SET picture=$drhphoto WHERE user=1}
No un n ecessa ry copyi n g or quoti n g of la rge
.objects
I mmun e to SQL i n ject i on a tta cks
![Page 42: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/42.jpg)
set in [open drh.jpg]fconfigure $in -translation binaryset drhphoto [read $in]close $indb eval { UPDATE user SET picture=@drhphoto WHERE user=1}
$ @ in stea d of to force the use of the ByteAr ra y
represen ta t i on
![Page 43: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/43.jpg)
db transaction { db eval {...} # other TCL code... db eval {...}}
Sta r t a tr a n sa cti on
COMMI T on success ROLLBACK on a n y er ror
![Page 44: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/44.jpg)
proc sqrtfunc {x} { return [expr {sqrt($x)}]}db function sqrt sqrtfuncdb eval { SELECT sqrt(id) FROM user}1.0 1.41421356237
Defi n e a n ew TCL fun ct i on
Regi ster the fun ct i on wi th SQLi te
Use the TCL fun cti on i n a n SQLi te query
![Page 45: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/45.jpg)
proc sqlitecon::_edit {original_text} { # Code here to implement a GUI editor # for $original_text and return the result.}db function edit ::sqlite::_edit
“ ” Crea te a n ew SQL fun cti on n a med ed i t “:: : : ”im plemen ted by the TCL proc sql i te _ed i t
![Page 46: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/46.jpg)
![Page 47: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/47.jpg)
Get Th i s
Go Here
![Page 48: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/48.jpg)
% package require Tk% source sqlitecon.txt% sqlitecon::create .console {sqlite> } test.db db%
![Page 49: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/49.jpg)
![Page 50: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/50.jpg)
![Page 51: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/51.jpg)
![Page 52: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/52.jpg)
Are you still not convincedthat SQLite is a TCL extension?
![Page 53: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/53.jpg)
SQLite Written Mostly In TCL
![Page 54: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/54.jpg)
TCL must be installed on the developmentsystem in order to build SQLite.
TCL is required to test SQLite
All SQLite documentation is generated by TCL scripts.
![Page 55: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/55.jpg)
select-core { stack {line SELECT {or nil DISTINCT ALL} {loop result-column ,}} {optx FROM join-source} {optx WHERE expr} {optx GROUP BY {loop ordering-term ,} {optx HAVING expr}} }
See h tt p : //w i k i . tc l . tk /21 7 0 8 fo r a d d iti o n a l i n fo rm a ti on
![Page 56: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/56.jpg)
“SQLite would not exist without TCL”
![Page 57: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/57.jpg)
SQLite is “different”
![Page 58: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/58.jpg)
is
“zero administration”
![Page 59: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/59.jpg)
Database Administrators
![Page 60: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/60.jpg)
![Page 61: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/61.jpg)
![Page 62: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/62.jpg)
is to is toas
![Page 63: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/63.jpg)
● SQLite does not compete with Oracle
![Page 64: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/64.jpg)
● SQLite does not compete with Oracle● SQLite competes with fopen()
![Page 65: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/65.jpg)
Portable File Format
● A database is a single ordinary disk file● No special naming conventions or required file
suffixes● Cross-platform: big/little-endian and 32/64-bit● Backwards compatible through 3.0.0● Promise to keep it compatible moving forward● Not tied to any particular programming
language.
![Page 66: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/66.jpg)
![Page 67: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/67.jpg)
ApplicationFile Format
makes a great
Zero-Administration &Portable File Format
means
![Page 68: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/68.jpg)
c,s,v
10011010010111
homegrown
<xml/>
![Page 69: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/69.jpg)
![Page 70: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/70.jpg)
SQLite as file format freebies
● No parsing and generating code to write● Atomic updates● Fast, built-in searching● Access via third-party tools● Simplified upgrade migration● Cross-platform file format● High-level query language
![Page 71: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/71.jpg)
Small Footprint
gcc -Os -DSQLITE_THREADSAFE=0
gcc -O3 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_RTREE=1
293 KiB
845 KiB
Sizes Include TCL language bindingsValues current as of 2009-09-25
![Page 72: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/72.jpg)
Single Source Code File
● The “amalgamation” source code file: sqlite3.c or tclsqlite3.c
● About 68,000 lines of ANSI C code● 3.9 MB● Few dependencies: libc and libtcl● Very simple to add to a larger C program● Very simple to build as a tclsh loadable library
![Page 73: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/73.jpg)
![Page 74: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/74.jpg)
The “generic” folder in theTEA distribution of SQLitecontains exactly one file:
tclsqlite3.c
![Page 75: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/75.jpg)
bash> gcc -shared tclsqlite3.c -o tclsqlite3.sobash> tclsh% load ./tclsqlite3.so% sqlite3 db :memory:% db eval {SELECT sqlite_version()}3.6.19
Building a tclsh loadable library
Note Add -DSQLITE_THREADSAFE=0 for non-threadsafe tclsh
![Page 76: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/76.jpg)
Other Features Of SQLite
● Gigibyte size BLOBs and strings
● Tebibyte size databases
● 100% branch test coverage
● Nested transactions
● Full text search● R-Trees● ATTACH DATABASE● Robust against power
loss, malloc() failures, and I/O errors.
● Referential integrity
![Page 77: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/77.jpg)
Many companies andorganizations use SQLite...
![Page 78: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/78.jpg)
Adobe Photoshop Lightroom
![Page 79: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/79.jpg)
Adobe Reader
![Page 80: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/80.jpg)
Mozilla Firefox
![Page 81: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/81.jpg)
Symbian/Nokia
![Page 82: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/82.jpg)
Google Android
![Page 83: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/83.jpg)
iPhone
![Page 84: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/84.jpg)
iPod & iTunes
![Page 85: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/85.jpg)
iStuff
![Page 86: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/86.jpg)
Blackberry
![Page 87: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/87.jpg)
Palm webOS
![Page 88: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/88.jpg)
Skype
![Page 89: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/89.jpg)
Sony Playstation
![Page 90: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/90.jpg)
... and so forth
![Page 91: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/91.jpg)
Open Source
![Page 92: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/92.jpg)
Have you looked at SQLite lately...
● Faster● CHECK constraints● SAVEPOINT and nested transactions● Enhanced query planner● 100% branch test coverage● Recursive triggers● FOREIGN KEY constraints● Sources managed using Fossil
![Page 93: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/93.jpg)
Closing Thoughts
? Shouldn't you be using SQLiteinstead of [open]?
? Why isn't tclsqlite3.c part of theTCL core?
? Can we get a TCL amalgamation?
![Page 94: The World's Most Popular TCL Extension · The World's Most Popular TCL Extension D. Richard Hipp 16th Annual Tcl/Tk Conference Portland, OR 2009-09-30](https://reader033.vdocuments.mx/reader033/viewer/2022052612/5f0e32567e708231d43e12d5/html5/thumbnails/94.jpg)
tcl/tk