Version 0 of waitman

Updated 2011-07-17 16:58:45 by waitman

Waitman Gobble, San Jose California

Hello, I am experimenting with the "Database as a Program" methodology described by D. Richard Hipp in the article SQLite and Tcl

At the moment my application consists of a short and simple main.tcl which decides which code segment to load from an sqlite3 database, executes the code and outputs the result.

I'm using the websh wrapper CGI interface. Note: I would prefer to load mod_websh into Apache but it doesn't appear to work with 2.2.x, will investigate eventually ;-)

Here is some sample code:

The app will process a request URI like http://example.com/main.tcl/hello Strategy: Create a directory on the machine to create all the snippet tcl files, then package into SQLite database

package.tcl (package all tcl scripts in current directory into SQLite database)

load /usr/local/lib/sqlite3/libtclsqlite3.so Sqlite3

sqlite3 db task.db

db eval {CREATE TABLE hd(path TEXT,src TEXT)}
set files glob *.tcl
foreach x $files {
        set fp open $x r
        set src read $fp
        close $fp
        set path /$x
        db eval {INSERT INTO hd VALUES ($path,$src)}
}
db close

hello.tcl (hello world example)

set content "Hello, World"

main.tcl (process request in URI and load corresponding tcl code)

#!/bin/sh
# \
exec /usr/local/bin/websh3.6.0b5 "$0" "$@"

set fp open "layout.html" r
set layout read $fp
close $fp

set path web::request PATH_INFO.tcl
load /usr/local/lib/sqlite3/libtclsqlite3.so Sqlite3
sqlite3 db task.db
set process db onecolumn {SELECT src FROM hd WHERE path=$path}
eval $process
db close

set html regsub "<!--Content-->" $layout $content
web::put $html

layout.html (a template)

<!doctype html>
<html>
<head>
<title>boo</title>
</head>

<body>
<!--Content-->
</body>
</html>