Changes

Jump to navigation Jump to search
29 bytes added ,  13:20, 5 September 2011
m
no edit summary
==Connections==
A connection to a relational database can be established using the function <code>sql:connect()</code>. As a result a connection handle is returned. The possible signatures are:
<code><b>sql:connect</b>($url as xs:string) as xs:int</code><br/>
<code><b>sql:connect</b>($url as xs:string, $auto-commit as xs:boolean, $user as xs:string, $password as xs:string) as xs:int</code>
The parameter <code>$url </code> is the URL of the database and shall be of the form: <code>odbc:<driver name>:[//<server>[/<database>]</code>. The parameter <code>$auto-commit</code> is used to indicate if the auto-commit mode shall be activated or not. Its default value is true. If the parameters <code>$user</code> and <code>$password</code> are specified, they are used as credentials for connecting to the database.
==Executing Queries==
<code><b>sql:execute</b>($connection as xs:int, $statement as xs:string) as element()*</code>
The parameter <code>$connection</code> specifies the connection handle to be used and the parameter <code>$statement</code> - the statement to be executed. If a query statement is executed, the result set is returned as a sequence of <code><sql:tuple/></code> elements, each one representing a tuple. In case of an update statement an empty sequence is returned. For example, a simple select statement can be executed on the following way:
<pre class="brush:xml">
<code><b>sql:prepare</b>($connection as xs:int, $statement as xs:string) as xs:int</code>
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. The prepared statement can then be execute executed using the following signature of the <code>sql:execute</code> function:
<code><b>sql:execute</b>($prepared-statement as xs:int, $parameters as xs:element) as element()*</code>
administrator, Bureaucrats, editor, reviewer
41

edits

Navigation menu