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

session_sql_query(++Session, +ResultTemplate, ++SQLQuery, -Cursor)

Executes a SQL query on the database server.
Session
A session handle
ResultTemplate
Template defining the types of results tuple (structure)
SQLQuery
A SQL statement query (string)
Cursor
Returned cursor handle

Description

Executes a SQL query on the database server. The predicate returns in Cursor the cursor handle for this SQL query, and the results can then be retrieved using cursor_*_tuple family of predicates.

The SQL query returns result in tuples of N elements each. Each tuple is mapped to a Prolog structure of arity N. ResultTemplate is a structure of arity N specifying the types of the return data for ECLiPSe. See the general description of this library or the manual for a description of the template specification.

The SQL query must be valid for the DBMS to execute. It can contain NULL characters, i.e. it can contain binary data.

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

Exceptions

(5) type error
Session is not a valid session handle, or SQLQuery not a string, or ResultTemplate not a structure
(dbi_error)
Error from DBMS while executing SQLQuery.
(dbi_bad_template)
ResultTemplate has the wrong arity

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.

See Also

session_sql_query / 5, cursor_next_tuple / 2, cursor_all_tuples / 2, cursor_N_tuples / 4, session_sql_prepare_query / 5, cursor_close / 1