Example on Updates

  • Erdal Karaca

    Erdal Karaca - 2009-06-08

    What is wrong with this query (I am new to xquery):

    let $result := <root/>
    return (
        insert <child1/> into $result/root


    That file is read as a string, then executed using the xqj api, but mxquery complains:
    ch.ethz.mxquery.exceptions.StaticException: StepExpr expected!

    How do I use the update facility by the xqj api?

    • Peter M. Fischer


      there are a couple of issues:

      1) XQJ and updates: XQJ predates the Update Facility and does not specify how updates should be handled other than "proprietary extensions might exist"
      2) XQJ and language level support in MXQuery: We did not add the language level choice feature present in the command line and MXQuery Java API to the XQJ implementaton.

      As a result of 1) and 2), using the Update Facility via XQJ is currently not possible for MXQuery 0.6.0. We are working on adding the relevant code for the next release. If you are willing to compile/modify MXQuery, we could point you to the relevant places to provide a quick fix. Otherwise I recommend switching to the MXQuery Java API (at least until the next release)

      3) Your query has a bug: It combines an updating expression (the let) with a simple expression (the $result). This is not possible in the Update Facility, only with the Scripting Facility. Please have a look at the examples at http://mxquery.org/?page_id=31, they might help


    • Erdal Karaca

      Erdal Karaca - 2009-06-10


      This workaround works for me:

      package ch.ethz.mxquery.xqj;

      import javax.xml.xquery.XQExpression;
      import ch.ethz.mxquery.contextConfig.CompilerOptions;

      public class MXQueryBridge {
          public static void injectUpdateability( XQExpression expr, boolean update,
          boolean scripting ) {
              MXQueryXQExpression mexpr = (MXQueryXQExpression) expr;
              CompilerOptions co = mexpr.co;
              co.setSchemaAwareness( true );
              co.setUpdate( update );
              co.setScripting( scripting );
              mexpr.runtime.getEngineContext().getStores().setUseUpdateStores( update
                  || scripting );

      Once updating/scripting is available in xqj mode, I will just switch back to pure xqj...

    • Peter M. Fischer

      I agree that this change exposes and sets the compiler options for one path (the other would be PreparedExpressions, one has to adapt MXQueryXQConnection). So queries can be compiled with any desired language level.

      What it does not do, however, is to apply the pending update list (PUL) produced by the updating query. So even when an updating query is run, the updates are never applied to the internal representation/store or even made permanent by updating/rewriting a file. We are working on the related changes, but the fix is a bit more complicated than 10 or 20 lines :)

      What does work are copy/modify queries, since the PUL is applied inside the query, and are "regular" result is produced.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks