Index: openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/Attic/00-database-procs.tcl,v diff -u -r1.119 -r1.120 --- openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl 7 Feb 2019 11:18:48 -0000 1.119 +++ openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl 7 Feb 2019 12:45:46 -0000 1.120 @@ -1489,16 +1489,24 @@ {-dbn ""} -cache_key {-cache_pool db_cache_pool} + -with_headers:boolean statement_name sql args } { Usage: db_list_of_lists statement-name sql [ -bind bind_set_id | -bind bind_value_list ] + @param with_headers when specified, first line of returned list of + lists will always be the list of column names as reported by the + database. Useful when you want to dynamically assign variables to + values returned in the list of lists. + @return a Tcl list, each element of which is a list of all column values in a row of the result of the SQL querysql. If - sql doesn't return any rows, returns an empty list. + sql doesn't return any rows, returns an empty list, + unless with_headers flag was specified and in this case the only + element in the list will be the list of headers. It checks if the element is I18N and replaces it, thereby reducing the need to do this with every single package @@ -1517,11 +1525,19 @@ set code { db_with_handle -dbn $dbn db { set selection [db_exec select $db $full_statement_name $sql] + set selection_size [ns_set size $selection] set result [list] + if {$with_headers_p} { + set headers [list] + for { set i 0 } { $i < $selection_size } { incr i } { + lappend headers [ns_set key $selection $i] + } + lappend result $headers + } while { [db_getrow $db $selection] } { set this_result [list] - for { set i 0 } { $i < [ns_set size $selection] } { incr i } { - lappend this_result [ns_set value $selection $i] + for { set i 0 } { $i < $selection_size } { incr i } { + lappend this_result [ns_set value $selection $i] } lappend result $this_result }