xo::db::DB-postgresql instproc 1row (public)

 <instance of xo::db::DB-postgresql[i]> 1row [ -dbn dbn ] \
    [ -bind bind ] [ -prepare prepare ] qn sql

Defined in /var/www/openacs/packages/xotcl-core/tcl/05-db-procs.tcl

Run a query that must return exactly one row and set its columns as variables in the caller. Raise an error if there is no row.

Switches:
-dbn (optional)
Database name, or empty for the default.
-bind (optional)
Bind values for the query.
-prepare (optional)
Optional argument types for a prepared statement.
Parameters:
qn (required)
Query name.
sql (required)
SQL statement.
Returns:
1 on success.

Testcases:
xotcl_core_tutorial_3, test_xo_db_object, test_cr_items, test_prepared_statements
Source code:
if {$sql eq ""} {set sql [:get_sql $qn]}
set prepOpt [expr {[info exists prepare] ? [list -prepare $prepare] : ""}]
set answers [uplevel [list [self] exec_0or1row -dbn $dbn {*}$prepOpt -bind $bind $sql]]
if {$answers ne ""} {
  foreach {att val} [ns_set array $answers] { uplevel [list set $att $val] }
  ns_set free $answers
  return 1
}
error "query $sql did not return an answer"
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: