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

cursor_next_tuple(++Cursor, -ResultTuple)

Retrieve the next result tuple from the SQL query in ResultTuple
Cursor
A cursor handle
ResultTuple
Returned result tuple

Description

Retrieve the next result tuple from the SQL query represented by Cursor, and unify it with ResultTuple. Cursor is a cursor previously created with session_sql_query/4 or session_sql_prepare_query/5. ResultTuple is a structure with the same name and arity as defined by the tuple template when the cursor was created. The predicate converts the result to the type specified in the template, except that NULL values are returned as variables.

If the SQL query have not yet been executed, and it contains no parameters, then the SQL query will first be executed before retrieving the result.

cursor_next_tuple/2 will fail when all the results tuples for the query have been returned. If it is then called again for the same SQL query, this cancels the cursor, and raise the cursor cancelled error.

Fail Conditions

No more results are available for the SQL query

Exceptions

(5) type error
Cursor is not a valid cursor handle
(5) type error
Unable to convert tuple result to ECLiPSe type
(dbi_error)
Error from DBMS while executing SQL associated with Cursor.
(dbi_error)
Error from DBMS while fetching result
(dbi_not_query)
The SQL associated with Cursor is not a query and so cannot return results.
(dbi_buffer_over)
Result value(s) too big for the buffer
(dbi_cancelled)
The cursor have been cancelled.

Examples

  check_overdraft_limit(Session, Account) :-
      L = ["select count(id) from accounts \
          where     id = ",Account," and balance < overdraft"],
      concat_string(L,SQL),
      session_sql_query(Session,c(0),SQL,OverdraftCheck),
      cursor_next_tuple(OverdraftCheck,c(Count)),
      Count = 0.