sql:update

Executes a SQL UPDATE statement, returning no result.

update($connection as javatype:java.sql.Connection, $table as xs:string, $predicate as xs:string, $changes as map(*)) ➔ item()?

Arguments

 

$connection

javatype:java.sql.Connection

A JDBC database connection established using sql:connect

 

$table

xs:string

The database table from which rows are to be updated

 

$predicate

xs:string

A SQL predicate identifying the rows to be updated

 

$changes

map(*)

A map holding new values for the updated rows

Result

item()?

Namespace

http://saxon.sf.net/sql

Saxon availability

Implemented since Saxon 9.9. Requires Saxon-PE or Saxon-EE. Available for Java only.

Notes on the Saxon implementation

Introduced in Saxon 9.9. Designed to supersede the extension instruction sql:update. The saxon-sql-10.#.jar file, distributed alongside the main JAR file, must be added to the classpath when these SQL extension functions are used.

Details

The function executes a SQL UPDATE statement, and returns no result.

The $table argument names the database table to be updated, and the $predicate argument is a SQL predicate that selects which rows are to be updated. For each of these rows, new values for selected columns are taken from the $changes map.

The entries in the $changes map are (name, value) pairs, where the name is a column name in the table being updated, and the value is the new value for the column. The value should be an appropriate data type for the column (for example, xs:string for a VARCHAR column, xs:decimal for a DECIMAL column, etc).

Although the declared return type is item()?, the function always returns an empty sequence. The declared return type is designed to prevent the optimizer making unwarranted assumptions.

Because this function is executed for its side-effects, it is recommended to invoke it using the saxon:do extension instruction.

Example:

<saxon:do action="sql:update($connection, 'book', 'stock = 0', map{'out-of-print': true()}"/>