db:replace and error bxerr:BXDB0007 (opened by another process)

Friday, 15 May 2015 · 5 messages · last reply 21 May 2015
JB
James Ball15 May 2015 18:55 #
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
CG
Christian Grün16 May 2015 12:16 #
Hi James,
Quoted text · James Ball · 5 lines
> 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.
Quoted text · James Ball · 1 line
> 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
JB
James Ball20 May 2015 18:51 #
Thank you Christian
Quoted text · Christian Grün · 4 lines
> 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.
Quoted text · Christian Grün · 3 lines
> 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
CG
Christian Grün21 May 2015 12:23 #
Quoted text · James Ball · 1 line
> 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 [1] http://docs.basex.org/wiki/RESTXQ#HTTP_Errors
JB
James Ball21 May 2015 18:48 #
Quoted text · Christian Grün · 4 lines
> 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]: > > [1] http://docs.basex.org/wiki/RESTXQ#HTTP_Errors
I think in this case that will do very nicely. Thank you! James

⚡Generated with XQuery