==sql:execute==
Once a connection is established, the returned connection handle can be used to execute queries on the database. Our SQL module supports both direct queries and prepared statements.
{{Mark|Updated with Version 7.3.1}}: prepared statements are now executed via [[sql:execute-prepared]]
{|
|-
| width='90' | '''Signatures'''
|{{Func|sql:execute|$connection as xs:integer, $query as xs:string|element()*}}
|-
| '''Summary'''
| This function executes a query or update statement. The parameter {{Code|$id}} specifies either a connection handle. The parameter {{Code|$query}} is a string representing an SQL statement.
|-
| '''Errors'''
|{{Error|BXSQ0001|XQuery Errors#SQL Functions Errors}} an SQL exception occurs, e.g. not existing relation is retrieved.<br/ >
{{Error|BXSQ0002|XQuery Errors#SQL Functions Errors}} a wrong connection handle is passed.<br/ >
|}
==sql:execute-prepared==
{{Mark|Introduced with Version 7.3.1}}: separated from [[sql:execute]]
{|
|-
| width='90' | '''Signatures'''
|{{Func|sql:execute|$connection as xs:integer, $arg params as itemelement(sql:parameters)|element()*}}
|-
| '''Summary'''
| This function executes a query, update or prepared statement. The parameter {{Code|$id}} specifies either a connection handle or a prepared statement handle. The optional parameter {{Code|$argparams}} is either a string representing an SQL statement or an element {{Code|<sql:parameters/>}} representing the parameters for a prepared statement along with their types and values. In case of the latter, the The following schema shall be used:<br/ >
<pre class="brush:xml">
element sql:parameters {
| '''Errors'''
|{{Error|BXSQ0001|XQuery Errors#SQL Functions Errors}} an SQL exception occurs, e.g. not existing relation is retrieved.<br/ >
{{Error|BXSQ0002|XQuery Errors#SQL Functions Errors}} a wrong connection handle or prepared statement handle is passed.<br/ >
{{Error|BXSQ0003|XQuery Errors#SQL Functions Errors}} the number of {{Code|<sql:parameter/>}} elements in {{Code|<sql:parameters/>}} differs from the number of placeholders in the prepared statement.<br/ >
{{Error|BXSQ0004|XQuery Errors#SQL Functions Errors}} the type of a parameter for a prepared statement is not specified.<br/ >