Subject: FYI: ADO Example with TCOM - DN [1]
Daniel Bush <Dan.Bush@ReferToMsgForAddr.com> - 17 Nov 1999 - comp.lang.tcl
I found this exercise sort of interesting. I downloaded the superb
tcom package from Chin Huang which allows you to use MS Objects from
within tcl. If you are interested in trying to use tcl with ActiveX
Data Objects (ADO), you may be interested in perusing this.
Chin, if you see this - thanks for the great tool tcom. I've learned
some already by reviewing your source.
Dan Bush
Battle Ground.wa.us
If you wish to email me, change .com to .net
Dan.Bush@earthling.com
------------------
package require tcom
proc iQuery {sSql varList} {
#// return varList, list of lists(rows). Row0 has field names.
global g_conn
set iRetCd -1
upvar $varList varAllRows
set rs [::tcom::bind "adodb.recordset"]
set varAllRows ""
if {[catch {$rs Open $sSql $g_conn 3 1} fid]} {
puts stderr "Bad Query, err code $fid"
} else {
set varOneRow ""
for {set i 0} {$i < [[$rs Fields] Count]} {incr i} {
lappend varOneRow [[[$rs Fields] Item $i] Name]
}
lappend varAllRows $varOneRow
set iRetCd 0
while {![$rs EOF]} {
incr iRetCd
set varOneRow ""
for {set i 0} {$i<[[$rs Fields] Count]} {incr i} {
lappend varOneRow [$rs Collect $i]
}
lappend varAllRows $varOneRow
$rs MoveNext
}
$rs Close
}
return $iRetCd
::tcom::release $rs
}
proc bOpenConn {sProvider sServer sDatabase sUid {sPwd ""}} {
#// open a connection
global g_conn
set bRetCd 0
set g_conn [::tcom::bind "adodb.connection"]
set sConn "provider=$sProvider;server=$sServer;database=$sDatabase"
if {[catch {$g_conn Open $sConn $sUid $sPwd} fid] } {
puts stderr "Failed to open, err code $fid"
} else {
set bRetCd 1
}
return $bRetCd
}
proc doTest {} {
#// simple test, open pubs on SQL Server, dump authors to stdout
global g_conn
if {[bOpenConn sqloledb server pubs sa]} {
set sQuery "select * from authors"
set iNumRows [iQuery $sQuery varOutput]
if {$iNumRows>0} {
set varCols [lindex $varOutput 0]
puts "Number of rows: $iNumRows"
for {set i 1} {$i<[llength $varOutput]} {incr i} {
puts "Row $i:"
set varOneRow [lindex $varOutput $i]
for {set j 0} {$j<[llength $varCols]} {incr j} {
puts " [lindex $varCols $j]: [lindex $varOneRow $j]"
}
}
}
$g_conn Close
}
::tcom::release $g_conn
}
doTest
Last modified
1999-11-25
1999-11-25
(195.108.246.50)
Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated
