|<code><b>sql:init</b>($class as xs:string) as empty-sequence()</code>
|-
| valign='top' | '''Summary'''
|This function initializes a JDBC driver specified via <code>$class</code>. This step might be superfluous if the SQL database is not embedded.<br/ >
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#SQL Functions Errors|FOSQ0007]]</b> is raised if the specified driver class is not found.
|}
|<code><b>sql:connect</b>($url as xs:string) as xs:integer</code><br/ ><code><b>sql:connect</b>($url as xs:string, $user as xs:string, $password as xs:string) as xs:integer</code><br/ ><code><b>sql:connect</b>($url as xs:string, $user as xs:string, $password as xs:string, $options as item()) as xs:integer</code><br/ >
|-
| valign='top' | '''Summary'''
|This function establishes a connection to a relational database. As a result a connection handle is returned. The parameter <code>$url</code> is the URL of the database and shall be of the form: <code>jdbc:<driver name>:[//<server>[/<database>]</code>. If the parameters <code>$user</code> and <code>$password</code> are specified, they are used as credentials for connecting to the database. The parameter <code>$options</code> can be used to set connection options, e.g. auto-commit mode. It can be specified as:
* <code>element(sql:options):</code> <code><sql:options/></code> must be used as root element, and the options are specified as child nodes, with the element name representing the key and the text node representing the value:<br /
* [[Map Module|map structure]]: all options can be directly represented as key/value pairs:<br /><code>map { "autocommit" := "true", ... </code>}<br/>
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#SQL Functions Errors|FOSQ0001]]</b> is raised if an SQL exception occurs, e.g. missing JDBC driver or not existing relation.
|}
|<code><b>sql:execute</b>($connection as xs:integer, $item as item()) as element()*</code>
|-
| valign='top' | '''Summary'''
| This function executes a query, update or prepared statement. The parameter <code>$id</code> specifies either a connection handle or a prepared statement handle. The parameter <code>$item</code> is either a string representing an SQL statement or an element <code><sql:parameters/></code> representing the parameters for a prepared statement along with their types and values. In case of the latter, the following schema shall be used:<br/ >
<pre class="brush:xml">
</pre>
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#SQL Functions Errors|FOSQ0001]]</b> is raised if an SQL exception occurs, e.g. not existing relation is retrieved.<br/ >
<b>[[XQuery Errors#SQL Functions Errors|FOSQ0002]]</b> is raised if a wrong connection handle or prepared statement handle is passed.<br/ >
|<code><b>sql:prepare</b>($connection as xs:integer, $statement as xs:string) as xs:integer</code>
|-
| valign='top' | '''Summary'''
|This function prepares a statement and returns a handle to it. The parameter <code>$connection</code> indicates the connection handle to be used. The parameter <code>$statement</code> is a string representing an SQL statement with one or more '?' placeholders. If the value of a field has to be set to <code>NULL</code>, then the attribute <code>null</code> of the element <code><sql:parameter/></code> has to be <code>true</code>.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#SQL Functions Errors|FOSQ0001]]</b> is raised if an SQL exception occurs.<br/ >
<b>[[XQuery Errors#SQL Functions Errors|FOSQ0002]]</b> is raised if a wrong connection handle is passed.<br/ >
|<code><b>sql:commit</b>($connection as xs:integer) as empty-sequence()</code>
|-
| valign='top' | '''Summary'''
| This function commits the changes made to a relational database. <code>$connection</code> specifies the connection handle.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#SQL Functions Errors|FOSQ0001]]</b> is raised if an SQL exception occurs.<br/ >
<b>[[XQuery Errors#SQL Functions Errors|FOSQ0002]]</b> is raised if a wrong connection handle is passed.<br/ >
|<code><b>sql:rollback</b>($connection as xs:integer) as empty-sequence()</code>
|-
| valign='top' | '''Summary'''
| This function rolls back the changes made to a relational database. <code>$connection</code> specifies the connection handle.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#SQL Functions Errors|FOSQ0001]]</b> is raised if an SQL exception occurs.<br/ >
<b>[[XQuery Errors#SQL Functions Errors|FOSQ0002]]</b> is raised if a wrong connection handle is passed.<br/ >
|<code><b>sql:close</b>($connection as xs:integer) as empty-sequence()</code>
|-
| valign='top' | '''Summary'''
| This function closes a connection to a relational database. <code>$connection</code> specifies the connection handle.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#SQL Functions Errors|FOSQ0001]]</b> is raised if an SQL exception occurs.<br/ >
<b>[[XQuery Errors#SQL Functions Errors|FOSQ0002]]</b> is raised if a wrong connection handle is passed.<br/ >