A database transaction in MarkLogic Server is only committed when the query 
execution is complete.  Phrased another way, an update transaction will see a 
view of the database that does not reflect any updates made by that transaction.

By using a semicolon, you're putting multiple transactions in a single module 
file.  This is a very handy feature, but, due to the overhead involved in 
opening multiple transactions and complexities of managing side effects, it's 
generally best to avoid using semicolons unless necessary.  In this example, 
using a semicolon would provide a window for the document to change from the 
update value.  If another query was executed at the same time updating /demo010 
to <b>data2</b>, the value returned by the semicolon form would be determined 
by whichever query won the race.

I'd suggest doing something like:

let $new := <a>data</a>
return (xdmp:document-insert("/demo010", $new), $new)

This approach works because $new will only actually be returned if the insert 
is successful; otherwise, the query will return an error.

James

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of G. Ken Holman
Sent: Saturday, December 05, 2009 10:08 AM
To: [email protected]
Subject: Re: [MarkLogic Dev General] Not able to retrive content from uri

Hi again, Soumadri!

At 2009-12-05 18:49 +0530, Chowdhury, Soumadri wrote:
>I have written two consecutive FLOWR expressions like the following,
>
>let $a1 := "" return (xdmp:document-insert("/demo010",<a>data</a>)),
>let $a2 := "" return (fn:doc("/demo010"))
>
>The problem is the 2nd line returns an empty sequence, instead of 
>the content of the uri "/demo010"
>
>How to resolve this problem? Any idea?

I learned the answer recently:  it has to do with database 
transactions.  Certain database transactions are not committed to the 
database until the query is complete.

As a test I formally declared the module to be using the Mark Logic 
version of the language:

xquery version "1.0-ml";
let $a1 := "" return (xdmp:document-insert("/demo010",<a>data</a>)),
let $a2 := "" return (fn:doc("/demo010"))

... which didn't work as yours didn't work and then changed it to:

xquery version "1.0-ml";
let $a1 := "" return (xdmp:document-insert("/demo010",<a>data</a>));
let $a2 := "" return (fn:doc("/demo010"))

... which worked fine.  Note the change of the comma to a semi-colon 
at the end of the first assignment.

This is using the Mark Logic extension to XQuery of ending a query 
with a semi-colon which allows one to put multiple queries in a 
single document.  The first query ends at the semi-colon and the 
database does its business of committing all of the changes.  The 
second query is then acting on a complete database with your more 
recent addition and finds it.

Since we are now dealing with complete queries instead of portions of 
a FLWOR expression, your test can be rewritten as follows:

xquery version "1.0-ml";
xdmp:document-insert("/demo010",<a>data</a>);
fn:doc("/demo010")

I haven't yet learned *when* queries need to be flushed/committed to 
the database, and I hope someone on the list can give general 
guidelines ... but this is how I recently resolved a related Mark 
Logic database issue.

Perhaps is there a formal request one can make in a query to commit 
any uncommitted transactions?

I hope this helps.

. . . . . . . . . . . . Ken

--
XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19
Vote for your XML training:   http://www.CraneSoftwrights.com/q/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:[email protected]
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/q/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to