Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tclodbc and SELECT

Status
Not open for further replies.

johnsonp

Programmer
Oct 30, 2002
5
GB
This might seem like a stupid question but how do you read in the results of a SQL query when using tclodbc2.3? I've got code to perform other operations like DROP, CREATE, INSERT and UPDATE but I can't find any examples which show me how to read a recordset, i.e. the results of a SELECT. I'm using Win2k tcl8.3 ODBC into SQL Server 2000 DB.
Regards,
Phil Johnson
 
Dear JohnsonP,

sorry I don't have an answer (can be done in MSVBasic using the ActiveX Data Object) but I have a question:

how do you use TCL ODBC?

I have a situation where I need to integrate to a foriegn Oracle database and am stuck with either very expensive options or less than desireable ones, and really don't want to create an integration using VB.

Therefore, this could be a solution.

thanks
John Lopez
Enterprise PDM & Integration Consulting
Development for MatrixOne PDM Systems
johnlopez2000@hotmail.com
 
To use ODBC from within a Tcl script add the folowing line:

package require tclodbc

then connect to ODBC using:

database db $dsn

You will have to configure the ODBC DSN manually, to point to your database, assuming the Oracle driver is there!


Hope this helps.

----

I solved my problem shortly after I posted the message. Most of the 'write' examples I got from the \Tcl8.3\lib\tclodbc2.3\samples folder. A typical 'write' statement is shown below, any output SQL statement is placed between the double quotes:

$db "CREATE TABLE tblRodDropData (
TripID int,
ObjectId varCHAR (40),
RSC varchar(40),
LogIndex int,
Date varCHAR (12),
Time varCHAR (12),
Hundreths int,
Value int
)"



Reading data turned out to be quite simple by using statements like the following, which drops all user tables whose name starts with 'tbl':

proc drop_tables { db } {
foreach i [db "SELECT Name from sysobjects WHERE name like 'tbl%' and type = 'U'"] {
$db "DROP table $i"
.lb insert 0 "Dropped table $i"
}
}


Regards,
Phil Johnson
Senior Software Engineer, Capula Limited
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top