This is not a formal test suite, but a tinkering ground.
Run it through "fossil test-th-render THIS_FILE".
<th1>
proc bar {} {
puts "json ?= [hasfeature json]\n"
puts "tcl ?= [hasfeature tcl]\n"
puts "ssl ?= [hasfeature ssl]\n"
puts [lindex {a b c} 1] "\n"
proc foo {a {b steve}} {
puts "a = ${a}\n"
puts "b = ${b}\n"
}
foo hi world
foo hi {string list}
# foo
puts a b c foo \n
}
bar
foo leaky
proc xyz {} {
return 42
}
set a [xyz]
puts "a=${a}" ! \n
set stmt [query prepare {SELECT login, cap FROM user}]
set colCount [query col count $stmt]
puts "query column count: ${colCount}\n"
puts "stmt id=${stmt}\n"
proc noop {} {}
proc incr {name {step 1}} {
upvar $name x
set x [expr $x+$step]
}
set sep " "
set i 0
set colNames(0) 0
for {set i 0} {$i < $colCount} {incr i} {
set colNames($i) [query col name $stmt $i]
puts "colNames($i)=" $colNames($i) "\n"
}
for {set row 0} {0 < [query step $stmt]} {incr row} {
for {set i 0} {$i < $colCount} {incr i} {
if {$i > 0} {
puts $sep
} else {
puts "#$row: $sep"
}
puts $colNames($i) = [query col string $stmt $i]
}
puts "\n"
}
unset row
query finalize $stmt
proc query_step_each {{stmt} {callback}} {
set colNames(0) 0
set colCount [query col count $stmt]
for {set i 0} {$i < $colCount} {incr i} {
set colNames($i) [query col name $stmt $i]
}
upvar cb $callback
for {set row 0} {0 < [query step $stmt]} {incr row} {
#puts "Calling callback: $stmt $colCount colNames\n"
$callback $stmt $colCount
}
}
set sql {SELECT uid, login FROM user WHERE uid!=?}
#set sql {SELECT uid, login FROM user WHERE login=?}
#set sql {SELECT tagid, value, null FROM tagxref WHERE value IS ? LIMIT 3}
set stmt [query prepare $sql]
puts "stmt ID=" $stmt "\n"
query bind int $stmt 1 3
#set stmt [query prepare $sql]
#query bind string $stmt 1 stephan
#set stmt [query prepare $sql]
#query bind null $stmt 1
set rc 0
puts "USER LIST:\n"
catch {
proc my_each {stmt colCount} {
upvar 2 sep sep
puts [query col int $stmt 0] " (type=" [query col type $stmt 0] ")" $sep
puts [query col double $stmt 0] $sep
puts [query col string $stmt 1] " (type=" [query col type $stmt 1] ")" $sep
puts "isnull 0 ?= " [query col is_null $stmt 0] $sep
puts "isnull 2 ?= " [query col is_null $stmt 2]
# for {set i 0} {$i < $colCount} {incr i} {
# if {$i > 0} { puts $sep }
# }
puts "\n"
# error "hi!"
}
query step_each $stmt my_each
# query step_each $stmt {
# proc each {stmt cc} { puts hi "\n" }
# }
} rc
query finalize $stmt
puts rc = $rc "\n"
set consts [list SQLITE_BLOB SQLITE_DONE SQLITE_ERROR SQLITE_FLOAT SQLITE_INTEGER SQLITE_NULL SQLITE_OK SQLITE_ROW SQLITE_TEXT]
#set consts $SQLITE_CONSTANTS
puts consts = $consts "\n"
for {set i 0} {$i < [llength $consts]} {incr i} {
set x [lindex $consts $i]
puts \$$x = [expr \$$x] "\n"
}
set ARGC [argv len]
puts ARGC = $ARGC "\n"
for {set i 0} {$i < $ARGC} {incr i} {
puts "argv at $i = " [argv at $i] \n
}
set magicDefault hi
set optA [argv getstr AA a $magicDefault]
puts "argv getstr AA = " $optA \n
set optA [argv getbool BB b 0]
puts "argv getbool BB = " $optA \n
set exception 0
catch {
argv getint noSuchOptionAndNoDefault
} exception
puts exception = $exception "\n"
enable_output 1
proc multiStmt {} {
set max 5
set i 0
set s(0) 0
for {set i 0} {$i < $max} {incr i} {
set s($i) [query prepare "SELECT $i"]
puts "s($i) = $s($i)\n"
}
for {set i 0} {$i < $max} {incr i} {
query step $s($i)
}
for {set i 0} {$i < $max} {incr i} {
puts "closing stmt $s($i)\n"
query finalize $s($i)
}
puts "Preparing again\n"
for {set i 0} {$i < $max} {incr i} {
set s($i) [query prepare "SELECT $i"]
puts "s($i) = $s($i)\n"
}
for {set i 0} {$i < $max} {incr i} {
query step $s($i)
}
puts "Closing again\n"
for {set i 0} {$i < $max} {incr i} {
puts "closing stmt $s($i)\n"
query finalize $s($i)
}
}
multiStmt
enable_output 1
puts "If you got this far, you win!\n"
</th1>