Tcl Database Connectivity is a presentation given at Tcl2008 given by Kevin Kenny. This page contains a set of notes on the presentation. Subsequently, TDBC became the standard database interface specification and implementation for Tcl.
SQL has become ubiquitous. Tcl is already a glue language. Potentially great for federated applications. It's a "check box" feature supported by other languages. Portal access to SQL databases widely requested.
Nearly everything else was tailored to a specific database.
Requirements: Homogeneous interface--all databases look the same. O-O looks to be the easiest way to get there. "Duck typing" for extensiblity--specify only the methods that a database object must support. (But provide base classes for implementors).
Bound parameters are important to avoid SQL injection attacks.
TDBC does not specify how to connect to a database; a driver does that. Statements all may have bound parameters, introduced by the colon character. Why the odd syntax (not dollar), dynamic applications may want double substitution:
db prepare "select * from $table where $column = :value"
(table and column are substituted early; value is substituted late).
What can you do with statements? You can set paramater types (some SQL APIs need this).
... several slides with code snippets ...
External iterators are problematic: Resource management (result sets and statements must be closed). If an error is thrown many layers need to be caught with catch. Internal iterators, create statements, result sets as needed. Clean up on any kind of exit (TCL_OK, TCL_ERROR, anything else).
What TDBC doesn't do:
Why? Mostly to make it easier to write drivers. Some of the above "features" are only supported by some databases. Targeting personal needs and lowest common denominator.
Current status: Fossil repository at http://tdbc.tcl.tk . Will be merged into the Tcl mainline by 8.6b1. Base classes complete. Sample driver in C (tdbc::odbc bridge) complete (except for a couple of minor issues). Sample driver in Tcl (tdbc::sqlite3) also complete. Test suite. Need docs beyond the TIP (#308).
Gauging preferred driver interest:
What does it take to do a driver? Three classes:
Tcl driver for SQLite3 is ~300 lines of Tcl (including lots of comments). C driver for ODBC is ~2500 lines of C, but ODBC is byzantine.
What's next? Start building real apps! Would like someone to build a database administration tool (desktop like TOAD or Web-based like PHPMyAdmin). Query builders/visualizers. Tcl on Train Tracks? Use your imagination!