Unit 5 wrote:
Thank your very much for your answers! It looks like
sqlite3_prepare() is what I need.
I have gone through the tcl api and did not find any
mappings to it or any command that matched its
functionality. Do you have the reference or the
command name handy?
Unit,
I don't use TCL much so I can't help much more with this, but most of
the sqlite test suite is done with TCL.
I pulled the following from the bind.test file. It shows how
sqlite_prepare is used to test the parameter binding, and how the
sqlite_column_count and sqlite_column_name APIs are used.
HTH
Dennis Cote
proc sqlite_step {stmt N VALS COLS} {
upvar VALS vals
upvar COLS cols
set vals [list]
set cols [list]
set rc [sqlite3_step $stmt]
for {set i 0} {$i < [sqlite3_column_count $stmt]} {incr i} {
lappend cols [sqlite3_column_name $stmt $i]
}
for {set i 0} {$i < [sqlite3_data_count $stmt]} {incr i} {
lappend vals [sqlite3_column_text $stmt $i]
}
return $rc
}
do_test bind-1.1 {
set DB [sqlite3_connection_pointer db]
execsql {CREATE TABLE t1(a,b,c);}
set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(:1,?,:abc)} -1
TAIL]
set TAIL
} {}
do_test bind-1.1.1 {
sqlite3_bind_parameter_count $VM
} 3
do_test bind-1.1.2 {
sqlite3_bind_parameter_name $VM 1
} {:1}
do_test bind-1.1.3 {
sqlite3_bind_parameter_name $VM 2
} {}
do_test bind-1.1.4 {
sqlite3_bind_parameter_name $VM 3
} {:abc}
do_test bind-1.2 {
sqlite_step $VM N VALUES COLNAMES
} {SQLITE_DONE}
do_test bind-1.3 {
execsql {SELECT rowid, * FROM t1}
} {1 {} {} {}}
do_test bind-1.4 {
sqlite3_reset $VM
sqlite_bind $VM 1 {test value 1} normal
sqlite_step $VM N VALUES COLNAMES
} SQLITE_DONE
do_test bind-1.5 {
execsql {SELECT rowid, * FROM t1}
} {1 {} {} {} 2 {test value 1} {} {}}
do_test bind-1.6 {
sqlite3_reset $VM
sqlite_bind $VM 3 {'test value 2'} normal
sqlite_step $VM N VALUES COLNAMES
} SQLITE_DONE
do_test bind-1.7 {
execsql {SELECT rowid, * FROM t1}
} {1 {} {} {} 2 {test value 1} {} {} 3 {test value 1} {} {'test
value 2'}}
do_test bind-1.8 {
sqlite3_reset $VM
set sqlite_static_bind_value 123
sqlite_bind $VM 1 {} static
sqlite_bind $VM 2 {abcdefg} normal
sqlite_bind $VM 3 {} null
execsql {DELETE FROM t1}
sqlite_step $VM N VALUES COLNAMES
execsql {SELECT rowid, * FROM t1}
} {1 123 abcdefg {}}
do_test bind-1.9 {
sqlite3_reset $VM
sqlite_bind $VM 1 {456} normal
sqlite_step $VM N VALUES COLNAMES
execsql {SELECT rowid, * FROM t1}
} {1 123 abcdefg {} 2 456 abcdefg {}}
do_test bind-1.99 {
sqlite3_finalize $VM
} SQLITE_OK