db_list_of_lists (public)

 db_list_of_lists [ -dbn dbn ] [ -cache_key cache_key ] \
    [ -cache_pool cache_pool ] [ -with_headers ] [ -subst subst ] \
    [ -columns_var columns_var ] statement_name sql [ -bind bind ]

Defined in packages/acs-tcl/tcl/01-database-procs.tcl

Switches:
-dbn (optional)
The database name to use. If empty_string, uses the default database.
-cache_key (optional)
Cache the result using given value as the key. Default is to not cache.
-cache_pool (optional, defaults to "db_cache_pool")
Override the default db_cache_pool
-with_headers (optional, boolean)
when specified, first line of returned list of lists will always be the list of column names as reported by the database. Useful when you want to dynamically assign variables to values returned in the list of lists.
-subst (optional, defaults to "all")
Perform Tcl substitution in xql-files. Possible values: all, none, vars, commands
-columns_var (optional)
-bind (optional)
bind variables, passed either as an ns_set id, or via bind value list
Parameters:
statement_name (required)
name of the SQL query.
sql (required)
SQL query to be executed.
Returns:
a Tcl list, each element of which is a list of all column values in a row of the result of the SQL querysql. If sql doesn't return any rows, returns an empty list, unless with_headers flag was specified and in this case the only element in the list will be the list of headers. It checks if the element is I18N and replaces it, thereby reducing the need to do this with every single package

Partial Call Graph (max 5 caller/called nodes):
%3 test_auth_authority_api auth_authority_api (test acs-authentication) db_list_of_lists db_list_of_lists test_auth_authority_api->db_list_of_lists test_db__caching db__caching (test acs-tcl) test_db__caching->db_list_of_lists test_db__list_variants db__list_variants (test acs-tcl) test_db__list_variants->db_list_of_lists test_parameter__check_procs parameter__check_procs (test acs-tcl) test_parameter__check_procs->db_list_of_lists acs::icanuse acs::icanuse (public) db_list_of_lists->acs::icanuse db_exec db_exec (public) db_list_of_lists->db_exec db_getrow db_getrow (private) db_list_of_lists->db_getrow db_qd_get_fullname db_qd_get_fullname (public) db_list_of_lists->db_qd_get_fullname db_with_handle db_with_handle (public) db_list_of_lists->db_with_handle acs_mail_lite::inbound_queue_pull_one acs_mail_lite::inbound_queue_pull_one (private) acs_mail_lite::inbound_queue_pull_one->db_list_of_lists acs_mail_lite::unique_id_parse acs_mail_lite::unique_id_parse (private) acs_mail_lite::unique_id_parse->db_list_of_lists acs_sc::impl::get_options acs_sc::impl::get_options (public) acs_sc::impl::get_options->db_list_of_lists ad_get_node_id_from_host_node_map ad_get_node_id_from_host_node_map (private) ad_get_node_id_from_host_node_map->db_list_of_lists apm::get_package_descendent_options apm::get_package_descendent_options (public) apm::get_package_descendent_options->db_list_of_lists

Testcases:
auth_authority_api, parameter__check_procs, db__caching, db__list_variants
Source code:
    set full_statement_name [db_qd_get_fullname $statement_name]

    db_with_handle -dbn $dbn db {

        set code {
            set result {}
            set selection [db_exec -subst $subst select $db $full_statement_name $sql]
            #ns_log notice "ll2: $sql -> $selection"
            #ns_log notice "ll2: $sql -> [ns_set array $selection]"

            if {$with_headers_p || $columns_var ne ""} {
                if {$columns_var ne ""} {
                    upvar 1 $columns_var headers
                }
                if {[acs::icanuse "ns_set keys"]} {
                    set headers [ns_set keys $selection]
                } else {
                    set headers [dict keys [ns_set array $selection]]
                }
                if {$with_headers_p} {
                    set result [list $headers]
                }
            }

            if {[acs::icanuse "ns_set values"]} {
                while { [db_getrow $db $selection] } {
                    lappend result [ns_set values $selection]
                }
            } else {
                while { [db_getrow $db $selection] } {
                    lappend result [dict values [ns_set array $selection]]
                }
            }
            set result
        }

        if { [info exists cache_key] } {
            return [ns_cache eval $cache_pool $cache_key $code]
        } else {
            return [eval $code]
        }
    }

    return $result
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: