Thanks David and Geert, I might have made a confusion as to why I wanted to do both insert and read. Also Geerts question sparked me to have another go at looking at the documentation and to great benefit.
My goal was to have a function to call a sparql endpoint for a specific question. To ease the load on the endpoint I wanted to store the rdf in Markolgic to cache it. Now I ended up doing pretty much the same but using an in-memory-store. So code ended up like. declare function wdCon:getKeyDataforQid($QId as xs:string, $lang as xs:string?) as node()* { //Variables etc // let $data := sem:query-results-serialize(sem:sparql($sparqlML))//spql:results/spql:result/spql:binding[@name = "label"]/spql:literal/text() return if ($data) then $data else let $sparqlWD := " PREFIX wd: <http://www.wikidata.org/entity/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> describe ?label WHERE { " || $QId || " rdfs:label ?label FILTER (langMatches( lang(?label), '" || $qlang || "' ) ) }" let $wDataRdf := wdCon:queryWithSparql($sparqlWD) let $wDSemTrip := sem:rdf-parse($wDataRdf,("rdfxml", "graph=http://www.wikidata.org")) let $_rdf_insert := sem:rdf-insert($wDSemTrip,(),$conf:defaultPermissions ) let $semStore := sem:in-memory-store($wDSemTrip) return sem:query-results-serialize(sem:sparql($sparqlML,(),(),$semStore) )//spql:results/spql:result/spql:binding[@name = "label"]/spql:literal/text() }; Regards and thanks Erik Från: general-boun...@developer.marklogic.com [mailto:general-boun...@developer.marklogic.com] För Geert Josten Skickat: den 25 januari 2018 06:50 Till: MarkLogic Developer Discussion <general@developer.marklogic.com> Ämne: Re: [MarkLogic Dev General] question about transactions The outer query runs in query mode, so runs against the timestamp of initial invocation, causing it to never see the result of sem:rdf-insert. You'd have to put the sem:sparql in an xdmp:eval with different-transaction as well. I also wonder though: what are you trying to do, why trying to squeeze insert and read in one request? Cheers, Geert From: <general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>> on behalf of David Ennis <david.en...@marklogic.com<mailto:david.en...@marklogic.com>> Reply-To: MarkLogic Developer Discussion <general@developer.marklogic.com<mailto:general@developer.marklogic.com>> Date: Wednesday, January 24, 2018 at 7:34 PM To: MarkLogic Developer Discussion <general@developer.marklogic.com<mailto:general@developer.marklogic.com>> Subject: Re: [MarkLogic Dev General] question about transactions 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. Regards, David Ennis -- From: <general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>> on behalf of Erik Zander <erik.zan...@studentlitteratur.se<mailto:erik.zan...@studentlitteratur.se>> Reply-To: MarkLogic Developer Discussion <general@developer.marklogic.com<mailto:general@developer.marklogic.com>> Date: Wednesday, January 24, 2018 at 5:35 PM To: MarkLogic Developer Discussion <general@developer.marklogic.com<mailto:general@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 Regards Erik 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#<http://www.w3.org/1999/02/22-rdf-syntax-ns>"; let $wDataRdf:= <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#<http://www.w3.org/1999/02/22-rdf-syntax-ns>" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#<http://www.w3.org/2000/01/rdf-schema>" xmlns:wikibase="http://wikiba.se/ontology#<http://wikiba.se/ontology>" xmlns:wd="http://www.wikidata.org/entity/" > <rdf:Descriptionrdf:about="http://www.wikidata.org/entity/Q925hhq"> <rdfs:labelxml:lang="sv">mup</rdfs:label> </rdf:Description> </rdf:RDF> 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")))<http://www.wikidata.org%22)))>' ,(xs:QName("wDataRdf"),$wDataRdf) ) return sem:sparql(' PREFIX wd: <http://www.wikidata.org/entity/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#<http://www.w3.org/2000/01/rdf-schema>> SELECT ?label WHERE { wd:Q925hhq rdfs:label ?label FILTER (langMatches( lang(?label), "SV" ) ) }' )
_______________________________________________ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general