[ library(dbi) | Reference Manual | Alphabetic Index ]

# cursor_next_execute(++Cursor, +Tuple)

Executes the parametrised prepared SQL statement represented by Cursor.

Cursor
  A cursor handle
Tuple
  A tuple of parameter values matching the template for this cursor (structure)

## Description

Executes the parameterised prepared SQL statement represented by Cursor, previously prepared by session_sql_prepare/4 or session_sql_prepare_query/5. The parameter values for this execution is supplied by Tuple.

Tuple is a structure whose name and arity match the parameter template when Cursor was prepared, and the arguments give the values for the parameters for this execution, and must be compatible with the type specified by the template, except that an argument can be an uninstantiated variable, to denote a NULL value for the corresponding parameter.

If the SQL statement is a query, then it should be prepared as a query using session_sql_prepare_query/5, and results can be obtained from the query by the cursor_*_tuple family of predicates. A dbi_bad_template error would be raised if the query was prepared with session_sql_prepared/4, because no result tuple template was specified.

This predicate is called with default options for the cursor, i.e. it is equivalent to calling cursor_next_execute/3 with an empty Options list.

### Exceptions

(5) type error
  Cursor is not a valid cursor handle
(5) type error
  Type mismatch between parameter template specification for Cursor and actual tuple data
(dbi_buffer_over)
  Parameter value(s) too big for the buffer
(dbi_error)
  Error from DBMS while executing SQL associated with Cursor.
(dbi_bad_template)
  ParamTemplate not specified when Cursor was created
(dbi_bad_cursor)
  The Cursor is not in a state to execute a query (e.g. it was cancelled)

## Examples

      % note '?' in SQL in the syntax MySQL uses for placeholders. This may be
      % different in other DBMS
      transfer_(Session, Amount, FromAccount, ToAccount) :-
          SQL = "update accounts set balance = balance + ? \
                                                   where id = ?",
          Deduct is - Amount,
          % incbal(1.0,12) is the parameter template
          session_sql_prepare(Session,incbal(1.0,12),SQL,Update),
          cursor_next_execute(Update,incbal(Deduct,FromAccount)),
          cursor_next_execute(Update,incbal(Amount,ToAccount)).

## See Also

cursor_next_execute / 3, cursor_all_execute / 2, cursor_N_execute / 4, session_sql_prepare / 4, session_sql_prepare_query / 5