Project

Profile

Help

Variable $myVariable has not been fixed up

Added by Anonymous almost 17 years ago

Legacy ID: #4395656 Legacy Poster: Guilhem31 (guilhem31)

Hi, I would like to change a variable value after compiling a query with a static context. But when i compile again the query, i have the following stack trace : java.lang.IllegalStateException: Variable $myVariable has not been fixed up at net.sf.saxon.expr.VariableReference.typeCheck(VariableReference.java:95) at net.sf.saxon.query.XQueryExpression.<init>(XQueryExpression.java:58) at net.sf.saxon.query.QueryParser.makeXQueryExpression(QueryParser.java:108) at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:472) at fr.guilhem.test.TestSetParam.doTest(TestSetParam.java:57) at fr.guilhem.test.TestSetParam.main(TestSetParam.java:26) Can a variable value be change without creating a new static/dynamic context and whitout declaring again all specific name space if any ? Here is my test : package fr.guilhem.test; import java.util.Iterator; import java.util.List; import net.sf.saxon.Configuration; import net.sf.saxon.expr.VariableDeclaration; import net.sf.saxon.om.NamePool; import net.sf.saxon.query.DynamicQueryContext; import net.sf.saxon.query.GlobalVariableDefinition; import net.sf.saxon.query.StaticQueryContext; import net.sf.saxon.query.XQueryExpression; import net.sf.saxon.value.SequenceType; public class TestSetParam { private StaticQueryContext iStatContext; private DynamicQueryContext iDynContext; public static void main(String[] args) { TestSetParam aTestSetParameter = new TestSetParam(); try { aTestSetParameter.doTest(); } catch (Exception e) { e.printStackTrace(); } } private void doTest() throws Exception { final Configuration iSaxonConfiguration = new Configuration(); iSaxonConfiguration.setHostLanguage(Configuration.XQUERY); iSaxonConfiguration.setTiming(true); iStatContext = new StaticQueryContext(iSaxonConfiguration); iDynContext = new DynamicQueryContext(iSaxonConfiguration); XQueryExpression iQuery; setParameter("myVariable", "01"); iQuery = iStatContext.compileQuery("$myVariable"); iQuery.explain(iSaxonConfiguration); displayResults(iQuery); setParameter("myVariable", "02"); iQuery = iStatContext.compileQuery("$myVariable"); iQuery.explain(iSaxonConfiguration); displayResults(iQuery); } private void displayResults(XQueryExpression aQuery) throws Exception { final Duration iDuration = new Duration(); List iResults = aQuery.evaluate(iDynContext); System.out.println("Results are:"); for (Object iObject : iResults) { System.out.println("-> " + iObject + "\n"); } } /** * Creation of a parameter for the request processor. * * @param aParamName * String Name of parameter. * @param aValue * Object Value to affect to parameter. * @throws Exception * an exception occuring during query execution */ private void setParameter(final String aParamName, final Object aValue) throws Exception { // Verification of the existing variable. boolean iExists = false; final Iterator<VariableDeclaration> iIterator = iStatContext .getModuleVariables(); VariableDeclaration iVariableDeclaration; while (iIterator.hasNext() && !iExists) { iVariableDeclaration = iIterator.next(); if (iVariableDeclaration.getVariableName().equals(aParamName)) { iExists = true; } } // If variable has not been declared, create it. if (!iExists) { final GlobalVariableDefinition iGlobalVariableDefinition = new GlobalVariableDefinition(); final short iUricode = 0; iGlobalVariableDefinition.setVariableName(aParamName); iGlobalVariableDefinition.setIsParameter(true); iGlobalVariableDefinition .setRequiredType(SequenceType.ANY_SEQUENCE); iGlobalVariableDefinition.setNameCode(NamePool.getDefaultNamePool() .allocate("", iUricode, aParamName)); iStatContext.declareVariable(iGlobalVariableDefinition); } // Initialisation iDynContext.setParameter(aParamName, aValue); } } Here is the complet trace : ============ Compiled Expression ============ $myVariable ============================================= Results are: -> 01 java.lang.IllegalStateException: Variable $myVariable has not been fixed up at net.sf.saxon.expr.VariableReference.typeCheck(VariableReference.java:95) at net.sf.saxon.query.XQueryExpression.<init>(XQueryExpression.java:58) at net.sf.saxon.query.QueryParser.makeXQueryExpression(QueryParser.java:108) at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:472) at fr.guilhem.test.TestSetParam.doTest(TestSetParam.java:57) at fr.guilhem.test.TestSetParam.main(TestSetParam.java:26) Thank you.


Replies (3)

Please register to reply

RE: Variable $myVariable has not been fixed u - Added by Anonymous almost 17 years ago

Legacy ID: #4395706 Legacy Poster: Michael Kay (mhkay)

There's one known bug concerning reusability of the StaticQueryContext: http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1730717&amp;group_id=29872&amp;atid=397617 This is fixed in 8.9.0.4, so please check whether the problem still exists with that build. It's possible though that this is a different problem in the same area. Michael Kay http://www.saxonica.com/

RE: Variable $myVariable has not been fixed u - Added by Anonymous almost 17 years ago

Legacy ID: #4395832 Legacy Poster: Guilhem31 (guilhem31)

Hi Michael, I have just downloaded and tested with the 8.9.0.4 release, but i have the same problem.

RE: Variable $myVariable has not been fixed u - Added by Anonymous almost 17 years ago

Legacy ID: #4395857 Legacy Poster: Michael Kay (mhkay)

It seems you have hit what is actually a documented restriction: the Javadoc for method declareVariable() on StaticQueryContext states: Note that the same VariableDeclation object cannot be used with more than one query. This is because the VariableDeclaration is modified internally to hold a list of references to all the places where the variable is used. In fact, because of this unsatisfactory restriction, the method declareVariable() will disappear in the next release. You can use it for the moment provided that you don't attempt to reuse the StaticQueryContext for multiple queries. However, I would recommend that all external variables should be declared in the query prolog, rather than from the Java API. Sorry about the inconvenience. Michael Kay Saxonica

    (1-3/3)

    Please register to reply