db_multirow_group_last_row_p (public)
db_multirow_group_last_row_p -column column
Defined in packages/acs-tcl/tcl/01-database-procs.tcl
Used inside the code_block to db_multirow to ask whether this row is the last row before the value of 'column' changes, or the last row of the result set.
This is useful when you want to build up a multirow for a master/slave table pair, where you only want one row per row in the master table, but you want to include data from the slave table in a column of the multirow.
Here's an example:
# Initialize the lines variable to hold a list of order line summaries set lines [list] # Start building the multirow. We add the dynamic column 'lines_pretty', which will # contain the pretty summary of the order lines. db_multirow -extend { lines_pretty } orders select_orders_and_lines { select o.order_id, o.customer_name, l.item_name, l.quantity from orders o, order_lines l where l.order_id = o.order_id order by o.order_id, l.item_name } { lappend lines "$quantity $item_name" if { [db_multirow_group_last_row_p -column order_id] } { # Last row of this order, prepare the pretty version of the order lines set lines_pretty [join $lines ", "] # Reset the lines list, so we start from a fresh with the next row set lines [list] } else { # There are yet more order lines to come for this order, # continue until we've collected all the order lines # The 'continue' keyword means this line will not be added to the resulting multirow continue } }
- Switches:
- -column (required)
- The name of the column defining the groups.
- Returns:
- 1 if this is the last row before the column value changes, 0 otherwise.
- Author:
- Lars Pind <lars@collaboraid.biz>
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: upvar 1 __db_multirow__next_row next_row if { ![info exists next_row] } { # If there is no next row, this is the last row return 1 } upvar 1 __db_multirow__local_columns columns upvar 1 $column column_value set pos [lsearch $columns $column] if {$pos == -1} { error "column '$column' not found in columns list '$columns'" } # Otherwise, it's the last row in the group if the next row has a # different value than this row set next_value [lindex $next_row $pos] return [expr {$next_value ne $column_value}]XQL Not present: Generic, PostgreSQL, Oracle