the following code:
#select * from pagosprueb
package require SQL
namespace import -force ::SQL::*
if { [catch {
if {[llength $argv] < 2 } {
puts { usage: tclsh dumpdb.tcl \"sqlquery\" numfields
+numfields is the number of fields u spect,
+sqlquery is the query to fetch, like
"select \* from that where this=that\_other\_thing"
\}
exit
\}
set query \[lindex $argv 0\]
set numfields \[lindex $argv 1\]
set myHandle \[SQLConnect qgpl "administrador" "oscar" 10\]
set rc ""
set fields
"pcnit,pccia,t64,DESCRI,CEMPLE,ANOMTR,A121,CCONCE,JDCONC,CC06,email"
#set query "Select t64 from pagosprueb"
set result ""
set headers ""
# Set Max return rows to 100
# $myHandle SQLSetStmtAttr SQL_ATTR_MAX_ROWS 1000
# Set Query Time out to 10 secons
$myHandle SQLSetStmtAttr SQL_ATTR_QUERY_TIMEOUT 10
set rc \[$myHandle SQLExecDirect $query\]
set head ""
set rows 0
\# Was the query successful?
puts "<?xml version=\"1.0\" ?>\n<package>\n\t<data>"
while \{$rc == 0 || $rc == 1\} \{
set rc \[$myHandle SQLFetch result headers\]
if \{ $rc == 0 || $rc == 1\} \{
set head ""
puts "\t\t<row>"
set n 0
foreach a $result \{
if \{$n >= $numfields\} \{
puts "\t\t\t<cell>$a</cell>"
\} else \{
set head "$head\n\t\t<header>$a</header>"
\}
incr n
\}
puts "\t\t</row>"
incr rows
\}
\}
puts
"\t</data>\n\t<headers>$head\n\t</headers>\n\t<query>$query</query>\n\t<rows>$rows</rows>\n\t<fields>$numfields</fields>\n</package>"
$myHandle SQLDisconnect
} doRequestCatch] } {
puts "SQL_ERROR: $doRequestCatch"
}
# Some possible return values:
#
# SQL_SUCCESS 0
# SQL_SUCCESS_WITH_INFO 1
# SQL_NO_DATA 100
# SQL_ERROR (-1)
# SQL_INVALID_HANDLE (-2)
# SQL_STILL_EXECUTING 2
# SQL_NEED_DATA 99
produces the following output:
<?xml version="1.0" ?>
<package>
<data>
<row>
<cell>830060430</cell>
<cell> </cell>
<cell>11001.0</cell>
<cell>BOGOTA</cell>
<cell>6.0</cell>
<cell>MELO CONTRERAS MARTHA E</cell>
<cell>51550255.0</cell>
<cell>1500.0</cell>
<cell>PROMEDIO (RECARGOS) VACACIONES</cell>
<cell>1610803.00</cell>
<cell>lopezcrl@yahoo.es</cell>
</row>
..... lots of rows deleted for briefness
<row>
<cell>830060430</cell>
<cell>XEROX DE COLOMBIA ----</cell>
<cell>11001.0</cell>
<cell>BOGOTA</cell>
<cell>104.0</cell>
<cell>PINZON VIRVIESCAS DIANA</cell>
<cell>52149211.0</cell>
<cell>7000.0</cell>
<cell>PAGO NETO</cell>
<cell>1977114.00</cell>
<cell>lopezcrl@yahoo.es</cell>
</row>
</data>
<headers>
<header>pcnit</header>
<header>pccia</header>
<header>t64</header>
<header>DESCRI</header>
<header>CEMPLE</header>
<header>ANOMTR</header>
<header>A121</header>
<header>CCONCE</header>
<header>JDCONC</header>
<header>CC06</header>
<header>email</header>
</headers>
<query>select \* from pagosprueb</query>
<rows>414</rows>
<fields>11</fields>
</package>
aders: 0GetColumnHeaders: 0GetColumnHeaders:
0GetColumnHeaders: 0GetColumnHeaders:
0GetColumnHeaders: 0GetColumnHeaders:
lots of getcollumnheaders:0 also omited
im working on a win2000 sp 4 1.7ghz with ODBC 3.0 Tcl
Extension and tcl 8.4.11.0 from activestate
this:
GetColumnHeaders: 0
is printed every time i fetch a new row, since the
output of my program is then fed to another program (an
xml parser)
then the output warning generated by the extension is
unacceptable, it should set errno, or whatever it uses
for error handling instead of tossing output into my
xml file, right?
im shure there is a smiple fix for this....
btw: command line is:
tclsh dumpdb.tcl "select * from pagosprueb" 11 >report.xml
Logged In: YES
user_id=787831
Thanks for the bug.
I look into what's causing this. In the meantime you can code
around this by using SQLFetchAll insead of SQLFetch. Change
this line in your code:
set rc [$myHandle SQLFetch result headers]
To
set rc [$myHandle SQLFetchAll result headers]
Logged In: YES
user_id=787831
Thanks for the bug.
I'll look into what's causing this. In the meantime you can code
around this by using SQLFetchAll insead of SQLFetch. Change
this line in your code:
set rc [$myHandle SQLFetch result headers]
To
set rc [$myHandle SQLFetchAll result headers]
This will populate the entire result set into the result as a list of
lists.
Logged In: YES
user_id=787831
Dear Tcl Developer,
The issue with SQLFetch has been resolved in the TclSQL 1.3
release that can be downloaded from the file releases link:
http://sourceforge.net/project/showfiles.php?
group_id=82145&package_id=161187