nstcl  >  Documentation  >  nstcl-database  >  db_multirow

Tcl Powered!



db_multirow — Create a multirow templating datasource from an SQL query


package require nstcl-database ?1.0?
package require nstcl ?1.0?

::nstcl::db_multirow ?-local ?-append? ?-extend extendVariables? varName statementName SQL ?code? ?if_no_rows? ?elseCode?


This command is used to create a multirow templating datasource from an SQL query. The name of the datasource created is varName. See the database_api documentation for information on statement_name.

If a code block is given, it is evaluated for each result row from the database. Any modifications to the variables selected from the database are stored in the datasource, unless the Tcl command continue is called (in which case the row is effectively skipped).

If the database returns no rows for the SQL, and the optional if_no_rows clause is present, then the elseCode is evaluated.


This switch is included for source code compatability with OpenACS and has no effect one way or the other. This switch did not exist in the ACS.
This switch may be used to append to an existing multirow datasource, rather than overwriting it, allowing you to build up the datasource with successive queries. It is an error, however, to use this switch with a query which returns a different set of columns from the database.
-extend extendVariables
This switch takes a list of additional variables to add to the multirow datasource which are not returned by the database. Instead, your code block should perform some calculation and set the Tcl variables of the same name, which will then be stored in the multirow datasource. This is an alternative (pioneered in OpenACS) to forcing the database to return an extra variable by using the "select null as foo" idiom.


adp, database_api, multirow


templating, nstcl, database