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. Options is a (possibly empty) list of Option:Value pairs, specifying DBMS-specific options for the cursor.
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.
MySQL specific:
Options is used to specify the type of cursor used. Currently this only applies to cursors for SQL queries. The options are:
The default buffering is on the client side, because this is the default of the MySQL C API, and in addition, it imposes certain restrictions on how the result tuples can be retrieved. However, as the whole result set is retreived, this can impose significant memory overheads if there are many tuples in the result set. On the other hand, there is no restrictions on how many active client buffered cursor is allowed per session at the same time, but only one active server buffered cursor is allowed at any one time -- a query result must be exhausted or the cursor explicitly closed before another query can be issued for that session.
check_overdraft_limit(Session, Account) :- L = ["select count(id) from accounts \ where id = ",Account," and balance < overdraft"], concat_string(L,SQL), % the buffering:server option is MySQL specific session_sql_query(Session,c(0),SQL,[buffering:server],OverdraftCheck), cursor_next_tuple(OverdraftCheck,c(Count)), Count = 0.