Index: openacs-4/packages/acs-templating/tcl/util-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/util-procs.tcl,v diff -u -N -r1.20 -r1.20.2.1 --- openacs-4/packages/acs-templating/tcl/util-procs.tcl 31 Jan 2005 21:03:19 -0000 1.20 +++ openacs-4/packages/acs-templating/tcl/util-procs.tcl 14 Aug 2005 19:59:17 -0000 1.20.2.1 @@ -731,19 +731,26 @@ return $ret } -ad_proc -public template::util::tcl_to_sql_list { lst } { - Convert a TCL list to a SQL list, for use with the "in" statement - why doesn't this use ns_dbquotevalue? +ad_proc -public template::util::tcl_to_sql_list { tcllist } { + Converts a TCL list to a list of values to insert in db_* SQL statements. For use with the SQL "in" statement } { + upvar __bind_array bind_array - if { [llength $lst] > 0 } { - set sql "'" - append sql [join $lst "', '"] - append sql "'" - return $sql - } else { - return "" - } + set sql_segment "" + set list_pairs [list] + set ii 0 + if { [llength $tcllist] > 0 } { + foreach {list_item} $tcllist { + incr ii + lappend list_pairs $ii $list_item + lappend sql_segment ":__bind_array($ii)" + } + array set bind_array $list_pairs + return [join $sql_segment ,] + } else { + array set bind_array "" + return "" + } } Index: openacs-4/packages/acs-templating/tcl/test/parse-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/test/parse-test-procs.tcl,v diff -u -N -r1.2 -r1.2.2.1 --- openacs-4/packages/acs-templating/tcl/test/parse-test-procs.tcl 13 Jan 2005 13:56:01 -0000 1.2 +++ openacs-4/packages/acs-templating/tcl/test/parse-test-procs.tcl 14 Aug 2005 19:59:17 -0000 1.2.2.1 @@ -49,4 +49,17 @@ } -} \ No newline at end of file +} + +aa_register_case -cats {api smoke} tcl_to_sql_list { + Tests the tcl_to_sql_list proc. + + @author Torben Brosten +} { + aa_equals "parses list of 0 items" [template::util::tcl_to_sql_list [list]] "" + aa_equals "parses list of 1 item" [template::util::tcl_to_sql_list [list a]] ":__bind_array(1)" + aa_equals "checking values of parsed list of 1 item" $__bind_array(1) "a" + aa_equals "parses list of 2 or more" [template::util::tcl_to_sql_list [list a b c]] ":__bind_array(1),:__bind_array(2),:__bind_array(3)" + aa_equals "checking last value of parsed list of 2 or more items" $__bind_array(3) "c" + +}