[MarkLogic Dev General] question about transactions

David Ennis David.Ennis at marklogic.com
Wed Jan 24 10:34:27 PST 2018

Please look up the options for xdmp:eval and note the following options explained there:
- transaction-mode
- isolation

Then change your eval to have the following options:
- transaction-mode=update-auto-commit
- isolation = different transaction

Then move the sem:sparql statement below the eval in your main code.

What are you doing here?

You are telling the insert to run as a separate transaction and auto-commit. This makes the triples available immediately after the eval is done. Therefore, you should run the select in the main code and not the isolated transaction.

Careful with the use of different transactions via eval and invoke. The wrong combination can get you into a deadlock.

David Ennis


From: <general-bounces at developer.marklogic.com> on behalf of Erik Zander <Erik.Zander at studentlitteratur.se>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com>
Date: Wednesday, January 24, 2018 at 5:35 PM
To: MarkLogic Developer Discussion <general at developer.marklogic.com>
Subject: [MarkLogic Dev General] question about transactions

Hi All,

I have a question about I think transactions.

I want to insert some rdf and then query the database, and I want to do this in a function so I can call the function and depending on if I have the data in Marklogic or not get the data as rdf and insert it.

But my problem is that the following code only returns result second time I call it.
I’m thankful for pointers here
Code below

xquery version "1.0-ml" encoding "utf-8";

import module namespace sem = "http://marklogic.com/semantics"
      at "/MarkLogic/semantics.xqy";
declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";

let $wDataRdf :=

    <rdf:Description rdf:about="http://www.wikidata.org/entity/Q925hhq">
        <rdfs:label xml:lang="sv">mup</rdfs:label>

let $insert :=  xdmp:eval(
            import module namespace sem = "http://marklogic.com/semantics"
      at "/MarkLogic/semantics.xqy";
            declare variable $wDataRdf as node() external;
            sem:rdf-insert(sem:rdf-parse($wDataRdf,("rdfxml", "graph=http://www.wikidata.org")))'
            ,(xs:QName("wDataRdf"), $wDataRdf)
return sem:sparql('
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
   wd:Q925hhq  rdfs:label ?label
   FILTER (langMatches( lang(?label), "SV" ) )

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20180124/46f936a3/attachment-0001.html 

More information about the General mailing list