Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Example on Updates

2009-06-08
2013-06-05
  • Erdal Karaca
    Erdal Karaca
    2009-06-08

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

    --------------test.xq--------------------
    let $result := <root/>
    return (
        insert <child1/> into $result/root
    )

    $result
    --------------test.xq--------------------

    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?

     
    • Hello,

      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

      Regards,
      Peter

       
    • Erdal Karaca
      Erdal Karaca
      2009-06-10

      Thanks...

      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...

       
    • 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.