xo::db::DB-postgresql instproc foreach (public)
<instance of xo::db::DB-postgresql> foreach [ -dbn dbn ] \ [ -bind bind ] [ -prepare prepare ] qn sql body
Defined in /var/www/openacs/packages/xotcl-core/tcl/05-db-procs.tcl
Run a query and execute the body in the caller for each row, with the column values available as local variables.
- Switches:
- -dbn (optional)
- Database name, or empty for the default.
- -bind (optional)
- Bind values for the query.
- -prepare (optional)
- Optional argument types for a prepared statement.
- Parameters:
- qn (required)
- Query name.
- sql (required)
- SQL statement.
- body (required)
- Tcl script to run for each row.
- Testcases:
- test_prepared_statements, test_db_out_of_pools
Source code: set prepare [expr {[info exists prepare] ? [list -prepare $prepare] : ""}] set rows [uplevel 1 [list ::xo::dc list_of_lists -with_headers true -dbn $dbn -bind $bind {*}$prepare $qn $sql]] set headers [lindex $rows 0] foreach row [lrange $rows 1 end] { foreach att $headers value $row { uplevel 1 [list set $att $value] } try { uplevel 1 $body } on error {errMsg} { error $errMsg $::errorInfo $::errorCode } on return {} { error "Cannot return from inside a ::xo::dc foreach loop" } on break {} { break } on continue {} { # Just ignore and continue looping. } }XQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)