Prepares a SQL query for execution. The query is not actually executed, and a cursor_next_execute/2 needs to be called to execute the SQL query, giving values to any parameters. Then the cursor_*_tuple family of predicates can be used to obtain the results. This facility is only available if the DBMS supports prepared statements, and the SQL query has to be written in the prepared statement syntax of the DBMS. The predicate returns the cursor handle representing this prepared query in Cursor, which can then be used in subsequent library predicates.
A prepared SQL statement is parsed by the DBMS, so that it could be executed more efficiently. It can also be parameterised, where the parameters represent values to be filled in when the statement is executed. The statement can be executed multiple times with different parameters. The types of the parameters is specified by ParamTemplate, which is a Prolog structure of arity M (where M is the number of parameters for the statement), or the nil atom  if there are no parameters. See the general description of this library or the manual for a description of the template specification.
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.
Note that some DBMS restricts which SQL statements can be prepared. If an SQL statement cannot be prepared, it can still be executed using session_sql/3.
MySQL specific note: not all SQL statements can be prepared by MySQL. Refer to the MySQL manual for details.
make_check_overdraft_limit(Session, Cursor) :- % note '?' in SQL in the syntax MySQL uses for placeholders. This may be % different in other DBMS SQL = "select count(id) from accounts where ID = ? \ and balance < overdraft", session_sql_prepare_query(Session,a(0),c(0),SQL,1,Cursor).