Page 1 of 41
[prev] [next]

Tcl/Tk and SQLite

 

D. Richard Hipp
[email protected]

 

11th Annual Tcl/Tk Conference
New Orleans
2004 October 14


Overview Of SQLite

Page 2 of 41
[prev] [next]

  • A self-contained SQL database engine
  • Written in ANSI C - includes TCL bindings
  • Simple to use and operate
  • Zero-configuration
  • ACID Transactions - even after crashes and power failures
  • Most of SQL-92 + extensions
  • Single file database
  • UTF-8 and/or UTF-16
  • User defined functions
  • User defined collating sequences

  • Small footprint - less than 230KB
  • Well-commented, accessible code
  • Tcl-based test suite provides over 95% code coverage
  • Cross-platform
  • Fast
  • Public Domain
  • 3rd-party bindings to two dozen other languages
  • Website http://www.sqlite.org/

Overview Of SQLite

Page 3 of 41
[prev] [next]

Overview Of SQLite

Page 4 of 41
[prev] [next]

Users Of SQLite

Page 5 of 41
[prev] [next]

  • PHP5
  • Mozilla
  • Xampp
  • Popfile

  • Monotone
  • Movable Type
  • Apple Mac OS X 10.4
  • MTS Professional

  • Phillips MP3 Players
  • Many others that I can't tell you about
  • Countless others that I don't know about

History Of SQLite

Page 6 of 41
[prev] [next]

Why Tcl And SQLite Make A Good Team

Page 7 of 41
[prev] [next]

  • SQLite helps fill the data structure gap in Tcl
  • SQLite and Tcl agree on their data typing philosophy
  • SQLite comes bundled with bindings for Tcl
  • SQLite includes SQL language extensions designed to make it work better with Tcl
  • Unlike other scripting languages, Tcl syntax can be adapted to the needs of SQLite
  • Both SQLite and Tcl are implemented using simple and well-commented C code
  • SQLite depends on Tcl for its regression testing - SQLite would not have been possible without Tcl

  • The fact that both use a feather icon is purely coincidence...

Page 8 of 41
[prev] [next]

 

The SQLite/Tcl Interface


Using SQLite With Tcl - Getting Started

Page 9 of 41
[prev] [next]

Using SQLite with Tcl - Querying

Page 10 of 41
[prev] [next]

Using SQLite with Tcl - Querying

Page 11 of 41
[prev] [next]

Using SQLite with Tcl - Querying

Page 12 of 41
[prev] [next]

Using SQLite with Tcl - Querying

Page 13 of 41
[prev] [next]

Using SQLite with Tcl - Querying

Page 14 of 41
[prev] [next]

Using SQLite with Tcl - Querying

Page 15 of 41
[prev] [next]

Using SQLite with Tcl - Updates

Page 16 of 41
[prev] [next]

Using SQLite with Tcl - Updates

Page 17 of 41
[prev] [next]

Using SQLite with Tcl - User Defined Functions

Page 18 of 41
[prev] [next]

Using SQLite with Tcl - Other Interface Features

Page 19 of 41
[prev] [next]

Page 20 of 41
[prev] [next]

 

Features Of SQLite


SQL Language Understood By SQLite

Page 21 of 41
[prev] [next]

Supported Features

  • INSERT, DELETE, UPDATE, and SELECT
  • Subqueries
  • Tables, indices, triggers, and views
  • BEGIN, ROLLBACK, COMMIT
  • INNER JOIN, LEFT OUTER JOIN, NATURAL JOIN
  • UNION, UNION ALL, INTERSECT, EXCEPT
  • UNIQUE and NOT NULL constraints

Features Not Supported

  • CHECK constraints (parsed but not enforced)
  • Correlated Subqueries
  • Foreign Keys (parsed but not enforced)
  • ALTER TABLE
  • Some details of TRIGGER are omitted
  • RIGHT and FULL OUTER JOIN
  • Writing to VIEWs
  • GRANT and REVOKE

SQLite Datatypes

Page 22 of 41
[prev] [next]

Datatypes (continued)

Page 23 of 41
[prev] [next]

ROWIDs

Page 24 of 41
[prev] [next]

Database Schema Information

Page 25 of 41
[prev] [next]

Querying The Database Schema

Page 26 of 41
[prev] [next]

Working With Multiple Databases

Page 27 of 41
[prev] [next]

Conflict Resolution Algorithms

Page 28 of 41
[prev] [next]

Page 29 of 41
[prev] [next]

 

Appropriate Uses For SQLite In Tcl Programs


SQLite In Traditional SQL Roles

Page 30 of 41
[prev] [next]

Stand-in for an enterprise client/server database engine

Websites


SQLite As Replacement For Ad Hoc Data Files

Page 31 of 41
[prev] [next]

SQLite As Internal Structured Data Format

Page 32 of 41
[prev] [next]

SQLite As Application File Format

Page 33 of 41
[prev] [next]

SQLite As Application File Format - First Approach

Page 34 of 41
[prev] [next]

Features:

Advantages:

Disadvantages:


SQLite As Application File Format - Second Approach

Page 35 of 41
[prev] [next]

Features:

Advantages:

Disadvantages:


SQLite As Application File Format - Third Approach

Page 36 of 41
[prev] [next]

Features:

Advantages:

Disadvantages:


SQLite As Application File Format - Undo/Redo

Page 37 of 41
[prev] [next]

SQLite Database As Program

Page 38 of 41
[prev] [next]

Page 39 of 41
[prev] [next]

 

Summary And Conclusions


Summary And Conclusions

Page 40 of 41
[prev] [next]

Page 41 of 41
[prev] [next]

 

Questions and/or Comments