Waitman Gobble, San Jose California Hello, I am experimenting with the "Database as a Program" methodology described by [http://wiki.tcl.tk/78%|%D. Richard Hipp%|%] in the article [http://www.tcl.tk/community/tcl2004/Papers/D.RichardHipp/drh.html%|%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 [http://tcl.apache.org/websh/%|%websh wrapper%|%] via [http://tcl.apache.org/websh/quickref/apache_module_specific_commands.html%|%mod_websh%|%] Here is some sample code: The app will process a request URI like http://example.com/main.ws3/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.ws3 (process request in URI and load corresponding tcl code) === 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 "" $layout $content] web::put $html === layout.html (a template) === boo === Sample output (note, in development ;-) #1 display CGI env info http://creamy.mobi/test-series/testdt/main.ws3/testcmd testcmd.tcl === set request [web::request -names] set combine [join $request ", "] set path [web::request PATH_INFO] set content "

Request Info

${combine}

${path}

" === #2 load and display static HTML file. The static page is specified in the query string (parameter pg). For test purposes adds the page request at the top. NOTE: You have to modify glob line in package.tcl, above, to also package html files in the current directory. http://creamy.mobi/test-series/testdt/main.ws3/static?pg=contact static.tcl (load html) === web::dispatch -postdata "" -cmd "" set page /[web::param pg].html set content "

$page

" append content [db onecolumn {SELECT src FROM hd WHERE path=$page}] === contact.html ===

Contact

Contact us page

(650) 396-7580

=== Notes using websh/mod_websh 1. using mod_websh cwd is set to "/" (and not the directory in which the script is running) 2. when using mod_websh pkg download from site, also in freebsd /usr/ports/www/websh/ does not appear to log errors. download from svn and build seems to fix this problem (?) <>Enter Category Here