This interface is not complete. I'm planning on improving it as time goes on. Suggestions or requests for features (both appreciated) should be directed to cmsedore@maxwell.syr.edu.
These functions are accessible after loading the odbc extension:
load odbc.dll odbc
ODBC_Connect odbcSource username password
ODBC_Connect connects you to an ODBC data source (defined in the ODBC control panel) with the specified username and password and returns an ODBC handle to use with the other ODBC functions. The username and password should be specified as an empty string ("" or {}) if they are not applicable to the data source.
ODBC_DriverConnect connectString
ODBC_DriverConnect takes a connection string as a parameter, and returns an ODBC handle. The connect string is driver specific, please consult your driver documentation for details.
ODBC_SQLExec odbcHandle sqlString ?recordLimit?
ODBC_SQLExec executes the SQL string against the database server and returns the results, if any. The results are returned as lists-the first list contains the column names of the columns return, the rest of the lists contain the column values.The record limit will limit the number of records returned. Note that this does not stop the database from doing the entire query, it just limits the number of records that are retrieved from the results.
An example:
ODBC_SQLExec $dbhandle "select name, id from sysobjects"
would return:
{{name} {id}} {{v_name_address} {123456}} {{v_name_ssn} {234567}}
ODBC_SQLExecWEval odbcHandle sqlString tclCode ?recordLimit?
ODBC_SQLExecWEval runs the query, then appends each row value to the end of the tclCode parameter and evals it. An example fragment:
proc myprinter {name birthday sex} {
puts "$name $birthday $sex"
}
ODBC_SQLExecWEval $odbc "select name,birthday,sex from dbTable1" myprinter 5
Might print:
Jane Doe 3/5/66 F John Smith 3/5/22 M Zeke Tralz 7/8/43 M Bertha Quentz 9/9/52 F Herman Dertel 1/2/34 M
ODBC_CloseHandle odbcHandle
ODBC_CloseHandle should be used to close handles from ODBC_Connect and ODBC_DriverConnect when they are no longer needed.
ODBC_SQLColumns odbcHandle tableName
ODBC_SQLTables odbcHandle databaseName|*
These two functions only work if the ODBC driver you use appropriately supports them, returning a list of all the columns for the table with their properties, and the tables in the specified database, or all available tables if "*" is specified.