eval evil?
Friday, 13 April 2012 · 5 messages · last reply 29 Apr 2012
AB
Andy Bunce13 Apr 2012 14:54 #
Musing on the the usefulness of actions that update the database and return something, specifically in a web server with Xforms context, and the absence of XQuery scripting. I have been playing around with things like the following:
let $s:=util:eval('
let $x:=copy $c:=db:open("listman","1.xml")
modify (replace value of node $c/updated with current-dateTime())
return $c
return db:replace("listman","1.xml",$x)
')
return db:open("listman","1.xml")This works, but is it likely to stop working in the future? Is there a better way?
/Andy
CG
Christian Grün19 Apr 2012 17:37 #
Dear Andy,
sorry for the frightening delay! We haven't been inactive, however: you have warmed up a frequently discussed limitation of XQuery Update, and after a longer discussion, we found a solution that complies to the semantics of the XQuery Update spec., but still gives you a solution to return results from an updating query.
The solution is a new function db:output() [1], which caches its argument at runtime and returns the result after all update operations have been processed. If a node is passed on as argument, it is copied in main memory to avoid that it will be modified or deleted in a pending update operation. The db:output() function itself is marked "updating", which means that it can only be used in combination with other updating operations.
Beside that, we have now defined all functions that return no value as "vacuous", which means they can now be used along with other updating operations. This way, you can e.g. perform update operations and call
file:append(...) to write information to a log file in a single query.
I have just updated our snapshots; feedback is welcome.
Christian
[1] http://docs.basex.org/wiki/Database_Module#db:output
[2] http://docs.basex.org/wiki/Releases#Stable_SnapshotsQuoted text · Andy Bunce · 24 lines
On Fri, Apr 13, 2012 at 2:54 PM, Andy Bunce <bunce.andy at gmail.com> wrote: > Musing on the the usefulness of actions that update the database and return > something, specifically in a web server with Xforms context, and the absence > of XQuery scripting. I have been playing around with things like the > following: > > let $s:=util:eval(' > let $x:=copy $c:=db:open("listman","1.xml") > modify (replace value of node $c/updated with current-dateTime()) > return $c > return db:replace("listman","1.xml",$x) > ') > return db:open("listman","1.xml") > > This works, but is it likely to stop working in the future? Is there a > better way? > > /Andy > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
AB
Andy Bunce23 Apr 2012 18:56 #
Hi Christian,
This looks like a clean and sufficient solution to the problem. I will try it out and let you know how it goes.
Thanks.
/Andy
On Thu, Apr 19, 2012 at 4:37 PM, Christian Grün
<christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 55 lines
> Dear Andy, > > sorry for the frightening delay! We haven't been inactive, however: > you have warmed up a frequently discussed limitation of XQuery Update, > and after a longer discussion, we found a solution that complies to > the semantics of the XQuery Update spec., but still gives you a > solution to return results from an updating query. > > The solution is a new function db:output() [1], which caches its > argument at runtime and returns the result after all update operations > have been processed. If a node is passed on as argument, it is copied > in main memory to avoid that it will be modified or deleted in a > pending update operation. The db:output() function itself is marked > "updating", which means that it can only be used in combination with > other updating operations. > > Beside that, we have now defined all functions that return no value as > "vacuous", which means they can now be used along with other updating > operations. This way, you can e.g. perform update operations and call > file:append(...) to write information to a log file in a single query. > > I have just updated our snapshots; feedback is welcome. > Christian > > [1] http://docs.basex.org/wiki/Database_Module#db:output > [2] http://docs.basex.org/wiki/Releases#Stable_Snapshots > ___________________________ > > On Fri, Apr 13, 2012 at 2:54 PM, Andy Bunce <bunce.andy at gmail.com> wrote: > > Musing on the the usefulness of actions that update the database and > return > > something, specifically in a web server with Xforms context, and the > absence > > of XQuery scripting. I have been playing around with things like the > > following: > > > > let $s:=util:eval(' > > let $x:=copy $c:=db:open("listman","1.xml") > > modify (replace value of node $c/updated with current-dateTime()) > > return $c > > return db:replace("listman","1.xml",$x) > > ') > > return db:open("listman","1.xml") > > > > This works, but is it likely to stop working in the future? Is there a > > better way? > > > > /Andy > > > > _______________________________________________ > > BaseX-Talk mailing list > > BaseX-Talk at mailman.uni-konstanz.de > > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > > >
AB
Andy Bunce29 Apr 2012 12:51 #
Hi Christian,
db:output() is working for me. I have put together a little blog piece about it
http://cubeb.blogspot.co.uk/2012/04/listman.html
/Andy
Quoted text · Andy Bunce · 69 lines
On Mon, Apr 23, 2012 at 5:56 PM, Andy Bunce <bunce.andy at gmail.com> wrote: > Hi Christian, > > This looks like a clean and sufficient solution to the problem. > I will try it out and let you know how it goes. > Thanks. > /Andy > > > On Thu, Apr 19, 2012 at 4:37 PM, Christian Grün <christian.gruen at gmail.com > > wrote: > >> Dear Andy, >> >> sorry for the frightening delay! We haven't been inactive, however: >> you have warmed up a frequently discussed limitation of XQuery Update, >> and after a longer discussion, we found a solution that complies to >> the semantics of the XQuery Update spec., but still gives you a >> solution to return results from an updating query. >> >> The solution is a new function db:output() [1], which caches its >> argument at runtime and returns the result after all update operations >> have been processed. If a node is passed on as argument, it is copied >> in main memory to avoid that it will be modified or deleted in a >> pending update operation. The db:output() function itself is marked >> "updating", which means that it can only be used in combination with >> other updating operations. >> >> Beside that, we have now defined all functions that return no value as >> "vacuous", which means they can now be used along with other updating >> operations. This way, you can e.g. perform update operations and call >> file:append(...) to write information to a log file in a single query. >> >> I have just updated our snapshots; feedback is welcome. >> Christian >> >> [1] http://docs.basex.org/wiki/Database_Module#db:output >> [2] http://docs.basex.org/wiki/Releases#Stable_Snapshots >> ___________________________ >> >> On Fri, Apr 13, 2012 at 2:54 PM, Andy Bunce <bunce.andy at gmail.com> wrote: >> > Musing on the the usefulness of actions that update the database and >> return >> > something, specifically in a web server with Xforms context, and the >> absence >> > of XQuery scripting. I have been playing around with things like the >> > following: >> > >> > let $s:=util:eval(' >> > let $x:=copy $c:=db:open("listman","1.xml") >> > modify (replace value of node $c/updated with current-dateTime()) >> > return $c >> > return db:replace("listman","1.xml",$x) >> > ') >> > return db:open("listman","1.xml") >> > >> > This works, but is it likely to stop working in the future? Is there a >> > better way? >> > >> > /Andy >> > >> > _______________________________________________ >> > BaseX-Talk mailing list >> > BaseX-Talk at mailman.uni-konstanz.de >> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> > >> > >
CG
Christian Grün29 Apr 2012 14:22 #
Andy,
thanks for the blog entry; nice to a have a first feedback on this new feature, which we are already using excessively on our own..
Christian
Quoted text · Andy Bunce · 80 lines
On Sun, Apr 29, 2012 at 12:51 PM, Andy Bunce <bunce.andy at gmail.com> wrote: > Hi Christian, > > db:output() is working for me. I have put together a little blog piece about > it > http://cubeb.blogspot.co.uk/2012/04/listman.html > > /Andy > > > On Mon, Apr 23, 2012 at 5:56 PM, Andy Bunce <bunce.andy at gmail.com> wrote: >> >> Hi Christian, >> >> This looks like a clean and sufficient solution to the problem. >> I will try it out and let you know how it goes. >> Thanks. >> /Andy >> >> >> On Thu, Apr 19, 2012 at 4:37 PM, Christian Grün >> <christian.gruen at gmail.com> wrote: >>> >>> Dear Andy, >>> >>> sorry for the frightening delay! We haven't been inactive, however: >>> you have warmed up a frequently discussed limitation of XQuery Update, >>> and after a longer discussion, we found a solution that complies to >>> the semantics of the XQuery Update spec., but still gives you a >>> solution to return results from an updating query. >>> >>> The solution is a new function db:output() [1], which caches its >>> argument at runtime and returns the result after all update operations >>> have been processed. If a node is passed on as argument, it is copied >>> in main memory to avoid that it will be modified or deleted in a >>> pending update operation. The db:output() function itself is marked >>> "updating", which means that it can only be used in combination with >>> other updating operations. >>> >>> Beside that, we have now defined all functions that return no value as >>> "vacuous", which means they can now be used along with other updating >>> operations. This way, you can e.g. perform update operations and call >>> file:append(...) to write information to a log file in a single query. >>> >>> I have just updated our snapshots; feedback is welcome. >>> Christian >>> >>> [1] http://docs.basex.org/wiki/Database_Module#db:output >>> [2] http://docs.basex.org/wiki/Releases#Stable_Snapshots >>> ___________________________ >>> >>> On Fri, Apr 13, 2012 at 2:54 PM, Andy Bunce <bunce.andy at gmail.com> wrote: >>> > Musing on the the usefulness of actions that update the database and >>> > return >>> > something, specifically in a web server with Xforms context, and the >>> > absence >>> > of XQuery scripting. I have been playing around with things like the >>> > following: >>> > >>> > let $s:=util:eval(' >>> > let $x:=copy $c:=db:open("listman","1.xml") >>> > modify (replace value of node $c/updated with current-dateTime()) >>> > return $c >>> > return db:replace("listman","1.xml",$x) >>> > ') >>> > return db:open("listman","1.xml") >>> > >>> > This works, but is it likely to stop working in the future? Is there a >>> > better way? >>> > >>> > /Andy >>> > >>> > _______________________________________________ >>> > BaseX-Talk mailing list >>> > BaseX-Talk at mailman.uni-konstanz.de >>> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>> > >> >> >
Written for BaseX 7.2. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery