Hello,
I’m currently writing a small RESTXQ application that receives POSTed XML and then stores it into the database.
It works well but I want to make it more robust so I’m adding more error handling code.
One scenario I want to cover is where the database to be written to exists but is open in another process for some reason.
In my function I do something like this:
try { db:replace(“DATABASE_NAME”,”PATH/TO/FILE”,<Element/>) } catch * { db:output(<insert code here>) }
I expect that this code should complete without error - knowing of course that the database won’t be updated.
Instead I always get a bxerr:BXDB0007 error thrown and I can’t find any way to catch it. (It’s also not listed as a possible error in the documentation, although is against db:create)
Is this something subtle to do with the pending updates list?
I’m sure I’m missing something obvious but I can’t see it.
Thank you for any help and direction,
James
Hi James,
try { db:replace(“DATABASE_NAME”,”PATH/TO/FILE”,<Element/>) } catch * { db:output(<insert code here>) }
Unfortunately, due to the semantics of XQuery Update, there is no chance to make this work, because all updating functions will first be moved to the pending update list [1] and processed after the query itself has been evaluated.
Instead, you should probably try to avoid having any other BaseX instances creating or accessing databases at the same time. If this can be ensured, BXDB0007 should never be raised.
Instead I always get a bxerr:BXDB0007 error thrown and I can’t find any way to catch it. (It’s also not listed as a possible error in the documentation, although is against db:create)
It's listed in the documentation of db:create [2]; maybe you tried to find it in the general error code list?
Hope this helps, Christian
[1] http://docs.basex.org/wiki/XQuery_Update#Pending_Update_List [2] http://docs.basex.org/wiki/Database_Module#db:create
Thank you Christian
Unfortunately, due to the semantics of XQuery Update, there is no chance to make this work, because all updating functions will first be moved to the pending update list [1] and processed after the query itself has been evaluated.
So my suspicion of the cause was correct - I’m getting better at this XQuery stuff.
Instead, you should probably try to avoid having any other BaseX instances creating or accessing databases at the same time. If this can be ensured, BXDB0007 should never be raised.
And, it my ideal world this would of course be true, sadly I’ve already encountered this error following a DB corruption after running out of disk space. And it’s not just that error I’d like to trap - I’d like to be able to report back to me if a request has failed for any reason.
Is it possible to do something by using rest:forward or http:send-request? I see that rest:forward is suggested for use in situations where you have multiple XQuery updates in a row.
Many thanks, James
Is it possible to do something by using rest:forward or http:send-request? I see that rest:forward is suggested for use in situations where you have multiple XQuery updates in a row.
If a query fails, and if you cannot catch it in XQuery, you can define error-code elements in your web.xml configuration file [1]:
<error-page> <error-code>500</error-code> <location>/fatal</location> </error-page>
Maybe this helps? Christian
If a query fails, and if you cannot catch it in XQuery, you can define error-code elements in your web.xml configuration file [1]:
I think in this case that will do very nicely. Thank you!
James
basex-talk@mailman.uni-konstanz.de