Thursday, August 5, 2010

Tcl and Databases

Tcl and Oracle - Oratcl

package require Oratcl
set lda [oralogon user/pass@dbname -async]
set sth [oraopen $lda]
if {[oramsg $sth rc] == 0} {
    puts "Successfully connected"
} else {
    puts "Unable to connect to the database."
}
oralogoff $lda

Tcl and Microsoft SQL - tclodbc

packagae require tclodbc
database db test $user $pwd
set v [db "select * from employee"]
db disconnect

Tcl and Mysql - mysqltcl

package require mysqltcl
set m [mysqlconnect -user root -db mysql -password foobar]
mysqluse $m mysql
foreach res [mysqlsel $m {select host from user} -flatlist] {
    puts $res
}
mysqlclose $m

SQLite

The SQLite library is designed to be very easy to use from a Tcl or Tcl/Tk script. SQLite began as a Tcl extension and the primary test suite for SQLite is written in TCL. SQLite can be used with any programming language, but its connections to TCL run deep.

This document gives an overview of the Tcl programming interface for SQLite.

sqlite3 db1 ./testdb

db1 eval {CREATE TABLE t1(a int, b text)}

No comments: