sqlscreens uses an intermediate code layer to access the different databases in a consistent fashion. This intermediate layer is called tcsq.
The tcsq calls which are documented here may be useful as a database access layer for non-sqlscreens applications (for any TCL script accessing the supported databases), or in auxiliary routines inside an sqlscreens application (for example, for building lists of values by querying a table).
tcsq uses the same SQLDBTYPE environment variable as the sqlscreens layer to define the database type.
tcsqconnect [host [user [passwd]]]
Returns a server connection handle (hdl in the following). Depending on the database type, it may actually connect to a server, or do nothing (Ex: informix).
tcsquse hdl dbname
Associates the connection handle hdl with database dbname .
tcsqconuse database [host]
Utility function: connect and use.
tcsqopensel hdl stmt
Opens a query operation. stmt is a string holding an SQL SELECT statement.
Returns a select handle (selhdl in the following).
tcsqrew selhdl
Rewinds the query associated with selhdl. This may actually rerun the query (INFORMIX) or be purely local (MYSQL).
tcsqclosel selhdl
Closes a query, and frees the associated resources.
tcsqnext selhdl
Returns the next row for the query, as a list of values, in the order of the columns in the SELECT statement. The last fetch returns an empty list.
tcsqexec hdl stmt
Executes a non-SELECT SQL statement (Ie, INSERT, DELETE, etc...)
tcsqdiscon hdl
Disconnects and frees resources associated with hdl.
tcsqtabinfo hdl
Returns a list of the user tables in the database referenced by hdl.
tcsqcolinfo hdl tbl arnm
Returns information about table tbl into the array the name of which is specified by arnm.
tcsqinsertid hdl
Returns the auto_increment value for the last inserted row.
tcsqquotequote s
Returns a suitably escaped string, for use in sql statements.
tcsqquoteblob s
Same for blobs.
The following shows is a small program to search for a name in a MYSQL 'user' table. It is not supposed to be useful for any purpose but as an example.
#!/usr/local/cdkit/isqltcl package require tcsq set env(SQLDBTYPE) MYSQL set hdl [tcsqconuse mysql localhost] set uname [tcsqquotequote "John O'Connell"] set qry [tcsqopensel $hdl "SELECT host,user FROM user WHERE user LIKE '$uname'"] for {set res [tcsqnext $qry]} {$res != ""} {set res [tcsqnext $qry]} { set host [lindex $res 0] set user [lindex $res 1] puts "Host: $host User: $user" } tcsqclosel $qry tcsqdiscon $hdl exit 0