My apologies if this question should be directed to some other list.
I'm looking for a better way to printout the:
Column Headers,
followed by the table contents -
in comma separated value (csv) format
from a SELECT statement:
So far I have two solutions, neither seems elegant enough.
First solution I add the rowid tag after the * then check to see if
rowid==1 in the output and if so print the headers first
<snip solution 1>
# the following code should print the headers and the
# results from the SELECT command in CSV format
sql eval {
SELECT *, rowid \
FROM Fxyz_max_min limit 10} row {
# if at first row print headers first
if $row(rowid)==1 {puts [join $row(*) "\t"] }
# define an EMPTY list
set b_list {}
foreach col $row(*) {lappend b_list $row($col)}
set b_list [join $b_list "\t"]
#write list
puts $b_list
}
</snip solution 1>
The second solution makes use of a test of count
(not really a counter just gets set to 1 instead of 0)
<snip solution 2>
set count 0
sql eval {
SELECT * \
FROM Fxyz_max_min limit 10} row {
# define an EMPTY list
if $count==0 {puts [join $row(*) "\t"] }
set count 1
set b_list {}
foreach col $row(*) {lappend b_list $row($col)}
set b_list [join $b_list "\t"]
#write list
puts $b_list
}
</snip solution 2>
Each of these needs something added; either the rowid to the output or
a counter test.
is there a better way??
Thanks
P.S. can the TCL sqlite3 statement open the database using command switchs
(ie --cvs -headers)
--
-Rod
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users