Changes

Jump to navigation Jump to search
102 bytes added ,  15:48, 27 February 2020
no edit summary
| '''Examples'''
|Connects to an SQL Server and sets autocommit to {{Code|true}}:
<pre classsyntaxhighlight lang="brush:xquery">
sql:connect('dbc:sqlserver://DBServer', map { 'autocommit': true() })
</presyntaxhighlight>
|}
| '''Summary'''
| This function executes a prepared statement with the specified {{Code|$id}}. The output format is identical to [[#sql:execute|sql:execute]]. The optional parameter {{Code|$params}} is an element {{Code|<sql:parameters/>}} representing the parameters for a prepared statement along with their types and values. The following schema shall be used:<br/ >
<pre classsyntaxhighlight lang="brush:xquery">
element sql:parameters {
element sql:parameter {
}+
}?
</presyntaxhighlight>
With {{Code|$options}}, the following parameter can be set:
* {{Code|timeout}}: query execution will be interrupted after the specified number of seconds.
A simple select statement can be executed as follows:
<pre classsyntaxhighlight lang="brush:xquery">
let $id := sql:connect("jdbc:postgresql://localhost:5432/coffeehouse")
return sql:execute($id, "SELECT * FROM coffees WHERE price < 10")
</presyntaxhighlight>
The result may look like:
<pre classsyntaxhighlight lang="brush:xml">
<sql:row xmlns:sql="http://basex.org/modules/sql">
<sql:column name="cof_name">French_Roast</sql:column>
<sql:column name="total">14</sql:column>
</sql:row>
</presyntaxhighlight>
==Prepared Statements==
A prepared select statement can be executed in the following way:
<pre classsyntaxhighlight lang="brush:xquery">
(: Establish a connection :)
let $conn := sql:connect("jdbc:postgresql://localhost:5432/coffeehouse")
(: Execute prepared statement :)
return sql:execute-prepared($prep, $params)
</presyntaxhighlight>
==SQLite==
The following expression demonstrates how SQLite can be addressed using the [http://bitbucket.org/xerial/sqlite-jdbc Xerial SQLite JDBC driver]:
<pre classsyntaxhighlight lang="brush:xquery">
(: Initialize driver :)
sql:init("org.sqlite.JDBC"),
sql:execute($conn, "select * from person")
)
</presyntaxhighlight>
=Errors=
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu