db_foreach (public)
db_foreach [ -dbn dbn ] [ -subst subst ] statement_name sql \ [ args... ]
Defined in packages/acs-tcl/tcl/01-database-procs.tcl
Usage:
db_foreach statement-name sql [ -bind bind_set_id | -bind bind_value_list ] [ -column_array array_name | -column_set set_name ] code_block [ if_no_rows if_no_rows_block ]Performs the SQL query sql, executing code_block once for each row with variables set to column values (or a set or array populated if -column_array or column_set is specified). If the query returns no rows, executes if_no_rows_block (if provided). In place of 'if_no_rows' also the 'else' keyword can be used.
Example:
db_foreach greeble_query "select foo, bar from greeble" { ns_write "<li>foo=$foo; bar=$bar\n" } if_no_rows { # This block is optional. ns_write "<li>No greebles!\n" }
- Switches:
- -dbn (optional)
- The database name to use. If empty_string, uses the default database.
- -subst (optional, defaults to
"all"
)- Parameters:
- statement_name (required)
- sql (required)
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- db__db_foreach, db__transaction_bug_3440