db_0or1row (public)

 db_0or1row [ -dbn dbn ] [ -cache_key cache_key ] \
    [ -cache_pool cache_pool ] [ -subst subst ] statement_name sql \
    [ -bind bind ] [ -column_array column_array ] \
    [ -column_set column_set ]

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

Performs the SQL query sql. If a row is returned, sets variables to column values (or a set or array populated if -column_array or column_set is specified) and returns 1. If no rows are returned, returns 0.

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
(defaults to "db_cache_pool") (optional)
Override the default db_cache_pool
-subst
(defaults to "all") (optional)
Perform Tcl substitution in xql-files. Possible values: all, none, vars, commands
-bind
(optional)
bind variables, passed either as an ns_set id, or via bind value list
-column_array
(optional)
array to be populated with values
-column_set
(optional)
ns_set to be populated with values
Parameters:
statement_name
sql
Returns:
1 if variables are set, 0 if no rows are returned. If more than one row is returned, throws an error.

Partial Call Graph (max 5 caller/called nodes):
%3 test_db__0or1row db__0or1row (test acs-tcl) db_0or1row db_0or1row test_db__0or1row->db_0or1row test_db__1row db__1row (test acs-tcl) test_db__1row->db_0or1row test_db__caching db__caching (test acs-tcl) test_db__caching->db_0or1row db_exec db_exec (public) db_0or1row->db_exec db_qd_get_fullname db_qd_get_fullname (public) db_0or1row->db_qd_get_fullname db_with_handle db_with_handle (public) db_0or1row->db_with_handle acs::test::require_package_instance acs::test::require_package_instance (public) acs::test::require_package_instance->db_0or1row acs_admin::check_expired_certificates acs_admin::check_expired_certificates (private) acs_admin::check_expired_certificates->db_0or1row acs_mail_lite::get_address_array acs_mail_lite::get_address_array (private) acs_mail_lite::get_address_array->db_0or1row acs_mail_lite::imap_conn_set acs_mail_lite::imap_conn_set (private) acs_mail_lite::imap_conn_set->db_0or1row acs_mail_lite::inbound_cache_hit_p acs_mail_lite::inbound_cache_hit_p (private) acs_mail_lite::inbound_cache_hit_p->db_0or1row

Testcases:
db__caching, db__0or1row, db__1row
Source code:
    # Query Dispatcher (OpenACS - ben)
    set full_statement_name [db_qd_get_fullname $statement_name]

    if { [info exists column_array] && [info exists column_set] } {
        return -code error "Can't specify both column_array and column_set"
    }

    if { [info exists column_array] } {
        upvar 1 $column_array array_val
        unset -nocomplain array_val
    }

    if { [info exists column_set] } {
        upvar 1 $column_set selection
    }

    if { [info exists cache_key] } {
        set values [ns_cache eval $cache_pool $cache_key {
            db_with_handle -dbn $dbn db {
                set selection [db_exec -subst $subst 0or1row $db $full_statement_name $sql]
            }

            set values [list]

            if { $selection ne "" } {
                set values [ns_set array $selection]
            }

            set values
        }]

        if { $values eq "" } {
            set selection ""
        } else {
            set selection [ns_set create s {*}$values]
        }
    } else {
        db_with_handle -dbn $dbn db {
            set selection [db_exec -subst $subst 0or1row $db $full_statement_name $sql]
        }
    }

    if { $selection eq "" } {
        return 0
    }

    if { [info exists column_array] } {
        array set array_val [ns_set array $selection]
    } elseif { ![info exists column_set] } {
        foreach {key value} [ns_set array $selection] {
            uplevel 1 [list set $key $value]
        }
    }

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