[ library(dbi) | The ECLiPSe Libraries | Reference Manual | Alphabetic Index ]

# cursor_N_execute(++Cursor, -Executed, +TupleList, -RestTupleList)

Executes the parametrised prepared SQL statement represented by Cursor, once for each tuple in TupleList.

Cursor
  A cursor handle
Executed
  Number of times the SQL statement was executed.
TupleList
  A difference list (together with RestTupleList) of tuples of parameter values matching the template for this cursor
RestTupleList
  Tail of tuple difference list

## Description

Executes the parameterised prepared SQL statement represented by Cursor, previously prepared by session_sql_prepare/4 or session_sql_prepare_query/5. The predicate executes a number of tuples from TupleList, taking the tuples in order from the start of the list, leaving the unprocessed tuples in RestTupleList. The number of tuple processed is unified with Executed. Any results produced when executing a tuple is discarded when the next tuple is processed.

The number of tuples processed per call is determined by the library. This freedom allows the predicate to process a multiple number of tuples in the most efficient way for the DBMS.

Each 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.

MySQL specific note: MySQL does not support the execution of multiple tuples in one go, so for MySQL, this predicate is essentially equivalent to executing cursor_next_execute/1 multiple times.

### 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_error)
  Error from DBMS while executing SQL associated with Cursor.
(dbi_bad_template)
  ParamTemplate not specified when Cursor was created

## Examples

      transfer_(Session, Amount, FromAccount, ToAccount) :-
          SQL = "update accounts set balance = balance + ?                                                where id = ?",
          Deduct is - Amount,
          session_sql_prepare(Session,incbal(1.0,12),SQL,2,Update),
          Updates = [incbal(Deduct,FromAccount),incbal(Amount,ToAccount)],
          % execute both updates with one call to cursor_N_execute/4
          cursor_N_execute(Update,2,Updates,[]).

## See Also

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