db_string (public)

 db_string [ -dbn dbn ] [ -cache_key cache_key ] \
    [ -cache_pool cache_pool ] [ -subst subst ] statement_name sql \
    [ -default default ] [ -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
-subst (optional, defaults to "all")
Perform Tcl substitution in xql-files. Possible values: all, none, vars, commands
-default (optional)
Return value in case the SQL query returns no value
-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:
the first column of the result of the SQL query sql. If the query doesn't return a row, returns default or raises an error if no default is provided.

Partial Call Graph (max 5 caller/called nodes):
%3 test_db__caching db__caching (test acs-tcl) db_string db_string test_db__caching->db_string test_db__string db__string (test acs-tcl) test_db__string->db_string test_db__transaction db__transaction (test acs-tcl) test_db__transaction->db_string test_db__transaction_bug_3440 db__transaction_bug_3440 (test acs-tcl) test_db__transaction_bug_3440->db_string test_nullchar nullchar (test acs-tcl) test_nullchar->db_string db_exec db_exec (public) db_string->db_exec db_qd_get_fullname db_qd_get_fullname (public) db_string->db_qd_get_fullname db_with_handle db_with_handle (public) db_string->db_with_handle acs_lookup_magic_object_no_cache acs_lookup_magic_object_no_cache (private) acs_lookup_magic_object_no_cache->db_string acs_object::object_p acs_object::object_p (public) acs_object::object_p->db_string acs_object::package_id_not_cached acs_object::package_id_not_cached (private) acs_object::package_id_not_cached->db_string acs_object_name acs_object_name (public) acs_object_name->db_string acs_object_type acs_object_type (public) acs_object_type->db_string

Testcases:
db__caching, db__transaction, db__transaction_bug_3440, nullchar, db__string
Source code:
    # Query Dispatcher (OpenACS - ben)
    set full_name [db_qd_get_fullname $statement_name]

    set code {
        db_with_handle -dbn $dbn db {
            set selection [db_exec -subst $subst 0or1row $db $full_name $sql]
        }
        if { $selection eq ""} {
            if { [info exists default] } {
                return $default
            }
            error "Selection did not return a value, and no default was provided"
        }
        return [ns_set value $selection 0]
    }

    if { [info exists cache_key] } {
        return [ns_cache eval $cache_pool $cache_key $code]
    } else {
        return [eval $code]
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: