plsql_utility::format_pieces (private)

 plsql_utility::format_pieces [ -indent indent ] \
    [ -num_spaces num_spaces ] [ -delim delim ] \
    [ -line_term line_term ] pieces

Defined in packages/acs-subsite/tcl/plsql-utility-procs.tcl

Proc to format a list of elements. This is used to generate nice error/debugging messages when we are executing things like pl/sql. Pieces is a list of lists where each element is a key value pair.

Example:

plsql_utility::format_pieces -indent 3 -delim " => "  [list [list object_type group] [list group_id -2] [list group_name "Reg users"]]
returns:
object_type    => group,
   group_id       => -2,
   group_name     => Reg users

Switches:
-indent (optional, defaults to "6")
-num_spaces (optional, defaults to "3")
-delim (optional)
-line_term (optional, defaults to ",")
Parameters:
pieces (required)
a list of lists where each element is a key/value pair
Author:
Michael Bryzek <mbryzek@arsdigita.com>
Created:
11/2000

Partial Call Graph (max 5 caller/called nodes):
%3 plpgsql_utility::generate_attribute_parameters plpgsql_utility::generate_attribute_parameters (public) plsql_utility::format_pieces plsql_utility::format_pieces plpgsql_utility::generate_attribute_parameters->plsql_utility::format_pieces plsql_utility::generate_attribute_parameter_call plsql_utility::generate_attribute_parameter_call (public) plsql_utility::generate_attribute_parameter_call->plsql_utility::format_pieces plsql_utility::generate_attribute_parameters plsql_utility::generate_attribute_parameters (public) plsql_utility::generate_attribute_parameters->plsql_utility::format_pieces

Testcases:
No testcase defined.
Source code:
        # Find max length of first column
        set max_length -1
        foreach pair $pieces {
            if { [string length [lindex $pair 0]] > $max_length } {
                set max_length [string length [lindex $pair 0]]
            }
        }
        if { $max_length == -1 } {
            # no elements... return
            return ""
        }
        set indent_text ""
        for { set i 0 } { $i < $indent } { incr i } {
            append indent_text " "
        }

        # Generate text
        set text ""
        set col_width [expr {$max_length + $num_spaces}]
        foreach pair $pieces {
            lassign $pair left right
            while { [string length $left] < $col_width } {
                append left " "
            }
            if { $text ne "" } {
                append text "$line_term\n$indent_text"
            }
            append text "${left}${delim}${right}"
        }
        return $text
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: