template::query::multirow (private)

 template::query::multirow statement_name db result_name sql

Defined in packages/acs-templating/tcl/query-procs.tcl

Process a multirow query. Use an array for each row in the result. Arrays are named name0, name1, name2 etc. The variable name.rowcount is also defined for checking and iteration.

Parameters:
statement_name - Standard db_api statement name used to hook into query dispatcher
db - Database handle
result_name - Tcl variable name to use when setting the result
sql - Query to use when processing this command
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 db_exec db_exec (public) template::query::multirow template::query::multirow template::query::multirow->db_exec

Testcases:
No testcase defined.
Source code:

    upvar opts opts

    set row [db_exec select $db $statement_name $sql 3]

    upvar $opts(uplevel) $result_name:rowcount rowcount $result_name:columns column_list

    # set a local variable as to whether we are caching or not
    if { [info exists opts(cache)] } {
        set is_cached 1
        set cached_result {}
    } else {
        set is_cached 0
    }

    set rowcount 0

    if { [info exists opts(eval)] } {
        # figure out the level at which to reference the row
        set ref_level [expr {$opts(uplevel) - 2}]
    }

    while { [ns_db getrow $db $row] } {

        incr rowcount

        # break if maxrows has been reached
        if { $rowcount > $opts(maxrows) } {
            ns_db flush $db
            upvar $opts(uplevel) ${result_name}:has_more_rows has_more_rows
            set has_more_rows 1
            incr rowcount -1
            break
        }

        # set the results in the calling frame
        upvar $opts(uplevel) ${result_name}:$rowcount result

        set result(rownum) $rowcount

        array set result [ns_set array $row]
        if { $rowcount == 1 } {
            lappend column_list {*}[ns_set keys $row]
        }

        # Execute custom code for each row
        if { [info exists opts(eval)] } {
            uplevel $opts(uplevel) "
                upvar 0 ${result_name}:$rowcount row; $opts(eval)
            "
        }

        if { $is_cached } {
            lappend cached_result [array get result]
        }
    }

    if { $is_cached } {
        set opts(result) $cached_result
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: