update:output() update:cache()
Thursday, 27 December 2018 · 2 messages · last reply 2 Jan 2019
DZ
Dieter Zanzinger27 Dec 2018 14:09 #
I do not exactly understand, for which purpose
update:output() is meant. Does anybody have an example, where one can see, how it works? (There is no example in the docs.)
(I am searching for a way, to run a update-expression on a database and give the altered nodes as result back to the restq-user in one query. The update:output() or update:cache() - expression sounded like they do something similar…
At present, i am helping me with a copy/modify/return-solution and am giving back the altered result, before I actually write back the result-node of the previous to the db. But I am searching for a more intuitive way to get this result).
Sincerly
DieterCG
Christian Grün2 Jan 2019 16:59 #
Dear Dieter,
Quoted text · Dieter Zanzinger · 2 lines
> I do not exactly understand, for which purpose update:output() is meant. > Does anybody have an example, where one can see, how it works? (There is no example in the docs.)
By default, no result can be returned with XQuery Update 1.0 if an update is performed. The
update:output function can be used to circumvent this restriction. You will find two examples if you look at [1,2]. The first one looks as follows:
update:output("Prices have been deleted."),
delete node //price
In the currently opened database, all price elements will be deleted. In addition, the string "Prices have been deleted." will be returned. If you enable the MIXUPDATES option, the update:output function can be omitted.Quoted text · Dieter Zanzinger · 1 line
> At present, i am helping me with a copy/modify/return-solution and am giving back the altered result, before I actually write back the result-node of the previous to the db. But I am searching for a more intuitive way to get this result).
If you want to return the updated database contents, this is one option indeed.
update:output alone won’t help you here, because it will always return the original nodes. This is in conformance with the other XQuery Update expressions, which are all based on the original database contents.Quoted text · Dieter Zanzinger · 1 line
> (I am searching for a way, to run a update-expression on a database and give the altered nodes as result back to the restq-user in one query.
If you use RESTXQ, another alternative is to call a second function via
web:redirect [3], which will return the modified result to a user. If you follow the link, you will find a little example how this can look like. You will find a lot of other usages in our RESTXQ DBA code.Quoted text · Dieter Zanzinger · 1 line
> The update:output() or update:cache() - expression sounded like they do something similar…
The
update:cache function returns all items that will eventually be returned to the user. Please note that there are no serious use cases for this function in productive code (at least I’m not aware of such cases); I have only used them in some of our XQUnit tests.
Hope this helps,
Christian
[1] http://docs.basex.org/wiki/Update_Module#update:output
[2] http://docs.basex.org/wiki/XQuery_Update#Returning_Results [3] http://docs.basex.org/wiki/Web_Module#web:redirectWritten for BaseX 9.1. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery