
cursor_next_tuple(++Cursor, -ResultTuple)

   Retrieve the next result tuple from the SQL query in ResultTuple

Arguments
   Cursor              A cursor handle
   ResultTuple         Returned result tuple

Type
   library(dbi)

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.

 cursor_next_tuple/2 is not resatisfiable, so to return successive tuples
 on backtracking, use repeat/0 to re-execute cursor_next_tuple/2:

  match_tuple(Cursor, Tuple) :-
        repeat,
        ( cursor_next_tuple(Cursor, Tuple0) ->
             Tuple0 = Tuple
        ;
             !, fail
        ).



Fail Conditions
   No more results are available for the SQL query

Resatisfiable
   no

Exceptions
     5 --- Cursor is not a valid cursor handle
     5 --- 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_bad_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.



