Changes

Jump to navigation Jump to search
165 bytes removed ,  13:31, 2 July 2020
=Conventions=
 
{{Mark|Updated with Version 9.0:}}
All functions and errors in this module are assigned to the <code><nowiki>http://basex.org/modules/sql</nowiki></code> namespace, which is statically bound to the {{Code|sql}} prefix.<br/>
| '''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>
|}
==sql:execute==
 
{{Mark|Updated with Version 9.0:}} Return update count for updating statements. {{Code|$options}} argument added.
{| width='100%'
==sql:execute-prepared==
 
{{Mark|Updated with Version 9.0:}} Return update count for updating statements.
{| width='100%'
| '''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 with the [httphttps://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=
 
{{Mark|Updated with Version 9.0:}}
{| class="wikitable" width="100%"
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu