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.

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: