Loading TOC...

sem.sparqlUpdate

sem.sparqlUpdate(
   $sparql as String,
   [$bindings as Object?],
   [$options as String[]],
   [$store as sem.store[]],
   [$default-permissions as Object[]]
) as null

Summary

Executes a SPARQL Update operation against the database.

Graph Update - addition and removal of triples from some graphs within the Graph Store.

Graph Management - creating and deletion of graphs within the Graph Store, as well as convenient shortcuts for graph update operations often used during graph management (to add, move, and copy graphs).

This function is a built-in.

Parameters
$sparql The SPARQL Update to be executed.
$bindings A map containing initial values for variables from the query, or the empty sequence if no query variables are to be initially bound. This is a way to parameterize the query.
$options Options as a sequence of string values. Available options are:
"base=IRI"
The initial base IRI for the query.
"default-graph=IRI*"
Add the named graph or graphs specified by the IRI to the default graph for the query.
"named-graph=IRI*"
Add the named graph or graphs specified by the IRI to the list of named graphs available in the query.
"parse-check"
Parse the query, but don't perform static checks or execute it.
"prepare"
Parse and optimize the query, caching the result. No execution is performed.
"optimize=N"
Sets the optimization level to use. Levels of 0 (off), 1, and 2 are recognized, with 1 as the default.
"directory=URI"
Sets The database directory path of triples document. Default location is /triplestore.
"triples-document-size=xs:nonNegativeInteger"
The number of triples in a triples document. Default is 100.
"existing-graph"
Update fails if the specified destination graph does not already exist.
"isolation=ISOLATION_LEVEL"
ISOLATION_LEVEL can be different-transaction or same-statement. Default is different-transaction, which will not change the transaction mode of the calling transaction. If isolation is same-statement, the calling transaction should be run in update mode and the $sparql cannot contain multiple statements.
"transaction-id=TXN_ID"
TXN_ID is the transaction ID which the SPARQL program is in. Setting transaction-id implies isolation to be different-transaction. Transaction-id cannot coexist with isolation same-statement.
$store A sem:store constructor to use as the source of the triples for SPARQL Update. If multiple sem:store constructors are supplied, the triples from all the sources are merged and queried together. The default for sem:store is the current database's triple index. The locking option specified in sem:store will be used by sem:sparql-update.

If a sem:store value is not supplied, then the default sem:store for the statement will be used. This is the same as calling sem:store() with all arguments omitted, which will access the current database's triple index, using the default rulesets configured for that database. The default for locking is read-write.

Note: You cannot use an in-memory store with SPARQL Update.

$default-permissions Security permission objects corresponding to the permissions for the graph during graph creation. If not supplied, the current user's default permissions are applied. The default value used for this parameter can be obtained by calling xdmp.defaultPermissions(). A RDF graph that is created by a non-admin user (that is, by any user who does not have the admin role) must have at least one update permission, otherwise the creation will throw an XDMP-MUSTHAVEUPDATE exception. The parameter is ignored if the operation does not involve graph creation.

Required Privileges

Requires the sparql-update-user role, or the following privileges:

http://marklogic.com/xdmp/privileges/sem-sparql-update

http://marklogic.com/xdmp/privileges/any-uri

http://marklogic.com/xdmp/privileges/unprotected-collections

Usage Notes

The options parse-check and prepare cannot be used at the same time.

Example

declareUpdate();
var sem = require("/MarkLogic/semantics.xqy");

// Insert a triple into default graph and three triples into graph <BOOKS>. 
sem.sparqlUpdate('\n\
PREFIX dc: <http://marklogic.com/dc/elements/1.1/>\n\
INSERT DATA\n\
{\n\
   <http://example/book0> dc:title "A default book"\n\
  GRAPH <BOOKS> {<http://example/book1> dc:title "A new book" }\n\
  GRAPH <BOOKS> {<http://example/book2> dc:title "A second book" }\n\
  GRAPH <BOOKS> {<http://example/book3> dc:title "A third book" }\n\
}\n\
');

Example

// Update any book title which is "A new book" to be "Insert MarkLogic Server".

declareUpdate();
sem.sparqlUpdate('\n\
PREFIX dc: <http://marklogic.com/dc/elements/1.1/>\n\
WITH <BOOKS>\n\
DELETE {?b dc:title "A new book" }\n\
INSERT {?b dc:title "Inside MarkLogic Server" }\n\
WHERE {\n\
  ?b dc:title "A new book" .\n\
}\n\
');

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy