zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #09287
[Merge] lp:~zorba-coders/zorba/bug-867170 into lp:zorba
Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/bug-867170 into lp:zorba.
Requested reviews:
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-867170/+merge/105004
fixed bug 867170$
--
https://code.launchpad.net/~zorba-coders/zorba/bug-867170/+merge/105004
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog 2012-05-05 02:39:12 +0000
+++ ChangeLog 2012-05-07 23:45:25 +0000
@@ -1,5 +1,11 @@
Zorba - The XQuery Processor
+
+version 2.x
+
+ * Fixed bug #867170 (Variables declared in Prolog are Overwritten inside the query)
+
+
version 2.5
New Features:
@@ -40,7 +46,6 @@
* Fixed bug #966706 (key uniqueness of index not enforced during incremental refresh)
* Fixed bug #906494 (default compile with D_FILE_OFFSET_BITS=64)
* Fixed bug #988412 (date:current-dateTime daylight saving)
- * Fixed bug #988417 (block internal modules)
* Fixed bug #912586, #912593 and #912722 (assertion failures with lax validation)
* Fixed bug #921458 (file:read-text-lines() blocking)
* Fixed bug #981405 (do not hoist expr containing try-catch variables out of the associated try-catch expression)
=== modified file 'src/api/staticcontextimpl.cpp'
--- src/api/staticcontextimpl.cpp 2012-05-05 02:39:12 +0000
+++ src/api/staticcontextimpl.cpp 2012-05-07 23:45:25 +0000
@@ -73,6 +73,7 @@
********************************************************************************/
StaticContextImpl::StaticContextImpl(DiagnosticHandler* aDiagnosticHandler)
:
+ theMaxVarId(2),
theDiagnosticHandler(aDiagnosticHandler),
theUserDiagnosticHandler(true),
theCollectionMgr(0)
@@ -97,6 +98,7 @@
DiagnosticHandler* aDiagnosticHandler)
:
theCtx(aCtx),
+ theMaxVarId(2),
theDiagnosticHandler(aDiagnosticHandler),
theUserDiagnosticHandler(true),
theCollectionMgr(0)
@@ -118,6 +120,7 @@
StaticContextImpl::StaticContextImpl(const StaticContextImpl& aStaticContext)
:
StaticContext(),
+ theMaxVarId(2),
theDiagnosticHandler(aStaticContext.theDiagnosticHandler),
theUserDiagnosticHandler(aStaticContext.theUserDiagnosticHandler),
theCollectionMgr(0)
@@ -1023,9 +1026,11 @@
theSctxMap = impl.theCompilerCB->theSctxMap;
}
+
static void
-toInternalPath(const std::vector<String>& aPublicStrings,
- std::vector<zstring>& aInternalStrings)
+toInternalPath(
+ const std::vector<String>& aPublicStrings,
+ std::vector<zstring>& aInternalStrings)
{
for (std::vector<String>::const_iterator lIter = aPublicStrings.begin();
lIter != aPublicStrings.end(); ++lIter)
@@ -1042,9 +1047,11 @@
}
}
+
static void
-toPublicPath(const std::vector<zstring>& aInternalStrings,
- std::vector<String>& aPublicStrings)
+toPublicPath(
+ const std::vector<zstring>& aInternalStrings,
+ std::vector<String>& aPublicStrings)
{
for (std::vector<zstring>::const_iterator lIter = aInternalStrings.begin();
lIter != aInternalStrings.end(); ++lIter)
@@ -1053,6 +1060,7 @@
}
}
+
void
StaticContextImpl::setURIPath(const std::vector<String> &aURIPath)
{
=== modified file 'src/api/staticcontextimpl.h'
--- src/api/staticcontextimpl.h 2012-05-05 02:39:12 +0000
+++ src/api/staticcontextimpl.h 2012-05-07 23:45:25 +0000
@@ -33,16 +33,29 @@
/*******************************************************************************
- theCtx : rchandle to the internal static_context obj that is
- wrapped by "this".
-
- theSctxMap :
-
- theDiagnosticHandler : Pointer to an error handle to handle any errors raised
- by the methods of this class.
- theUserDiagnosticHandler : If true, theDiagnosticHandler is owned by "this", and it
- should be deleted when "this" is destroyed. Otherwise,
- theDiagnosticHandler is not owned by "this".
+ theCtx :
+ --------
+ rchandle to the internal static_context obj that is wrapped by "this".
+
+ theSctxMap :
+ ------------
+
+ theMaxVarId :
+ -------------
+ If loadProlog() is called on "this", the compiler will store in theMaxVarId
+ the max variable id generated by the compilation of the given prolog. This
+ is needed by the "outer" query, where the prolog will be loaded to.
+
+ theDiagnosticHandler :
+ ----------------------
+ Pointer to an error handle to handle any errors raised by the methods of
+ this class.
+
+ theUserDiagnosticHandler :
+ --------------------------
+ If true, theDiagnosticHandler is owned by "this", and it should be deleted
+ when "this" is destroyed. Otherwise, theDiagnosticHandler is not owned by
+ "this".
********************************************************************************/
class StaticContextImpl : public StaticContext
{
@@ -54,6 +67,8 @@
std::map<int, static_context_t> theSctxMap;
+ ulong theMaxVarId;
+
DiagnosticHandler * theDiagnosticHandler;
bool theUserDiagnosticHandler;
@@ -70,25 +85,27 @@
virtual ~StaticContextImpl();
- void loadProlog(const String&, const Zorba_CompilerHints_t &hints);
+ void loadProlog(const String&, const Zorba_CompilerHints_t& hints);
+
+ ulong getMaxVarId() const { return theMaxVarId; }
+
+ void setMaxVarId(ulong v) { if (v > theMaxVarId) theMaxVarId = v; }
StaticContext_t createChildContext() const;
- bool addNamespace( const String& prefix, const String& URI );
-
- String getNamespaceURIByPrefix( const String& prefix ) const;
-
- void
- getNamespaceBindings( NsBindings& aBindings ) const;
-
- bool setDefaultElementAndTypeNamespace( const String& URI );
-
- String getDefaultElementAndTypeNamespace( ) const;
-
- bool setDefaultFunctionNamespace( const String& URI );
-
- virtual String
- getDefaultFunctionNamespace( ) const;
+ bool addNamespace(const String& prefix, const String& URI);
+
+ String getNamespaceURIByPrefix(const String& prefix) const;
+
+ void getNamespaceBindings(NsBindings& aBindings) const;
+
+ bool setDefaultElementAndTypeNamespace(const String& URI);
+
+ String getDefaultElementAndTypeNamespace() const;
+
+ bool setDefaultFunctionNamespace(const String& URI);
+
+ virtual String getDefaultFunctionNamespace() const;
virtual void
addCollation( const String& URI );
=== modified file 'src/api/xqueryimpl.cpp'
--- src/api/xqueryimpl.cpp 2012-05-03 12:31:51 +0000
+++ src/api/xqueryimpl.cpp 2012-05-07 23:45:25 +0000
@@ -435,7 +435,11 @@
std::istringstream lQueryStream(aQuery.c_str());
- doCompile(lQueryStream, aHints);
+ // 0 is reserved as an invalid var id, and 1 is taken by the context item
+ // in the main module.
+ ulong nextVarId = 2;
+
+ doCompile(lQueryStream, aHints, true, nextVarId);
}
QUERY_CATCH
}
@@ -455,7 +459,11 @@
checkNotClosed();
checkNotCompiled();
- doCompile(aQuery, aHints);
+ // 0 is reserved as an invalid var id, and 1 is taken by the context item
+ // in the main module.
+ ulong nextVarId = 2;
+
+ doCompile(aQuery, aHints, true, nextVarId);
}
QUERY_CATCH
}
@@ -485,9 +493,12 @@
theCompilerCB->theSctxMap =
static_cast<StaticContextImpl*>(aStaticContext.get())->theSctxMap;
+ ulong nextVarId =
+ static_cast<StaticContextImpl*>(aStaticContext.get())->getMaxVarId();
+
std::istringstream lQueryStream(aQuery.c_str());
- doCompile(lQueryStream, aHints);
+ doCompile(lQueryStream, aHints, true, nextVarId);
}
QUERY_CATCH
}
@@ -515,7 +526,10 @@
theCompilerCB->theSctxMap =
static_cast<StaticContextImpl*>(aStaticContext.get())->theSctxMap;
- doCompile(aQuery, aHints);
+ ulong nextVarId =
+ static_cast<StaticContextImpl*>(aStaticContext.get())->getMaxVarId();
+
+ doCompile(aQuery, aHints, true, nextVarId);
}
QUERY_CATCH
}
@@ -527,7 +541,8 @@
void XQueryImpl::doCompile(
std::istream& aQuery,
const Zorba_CompilerHints_t& aHints,
- bool fork_sctx)
+ bool fork_sctx,
+ ulong& nextDynamicVarId)
{
if ( ! theStaticContext )
{
@@ -544,7 +559,9 @@
// otherwise, unless this is a load-prolog query, create a child and we have
// ownership over that one
if (fork_sctx)
+ {
theStaticContext = theStaticContext->create_child_context();
+ }
}
zstring url;
@@ -581,10 +598,6 @@
}
#endif
- // 0 is reserved as an invalid var id, and 1 is taken by the context item
- // in the main module.
- ulong nextDynamicVarId = 2;
-
PlanIter_t planRoot = lCompiler.compile(aQuery, theFileName, nextDynamicVarId);
thePlanProxy = new PlanProxy(planRoot);
@@ -616,7 +629,13 @@
theCompilerCB->setLoadPrologQuery();
- doCompile(lQueryStream, aHints, false);
+ StaticContextImpl* sctx = static_cast<StaticContextImpl*>(aStaticContext.get());
+
+ ulong nextVarId = sctx->getMaxVarId();
+
+ doCompile(lQueryStream, aHints, false, nextVarId);
+
+ sctx->setMaxVarId(nextVarId);
}
QUERY_CATCH
}
=== modified file 'src/api/xqueryimpl.h'
--- src/api/xqueryimpl.h 2012-05-03 12:31:51 +0000
+++ src/api/xqueryimpl.h 2012-05-07 23:45:25 +0000
@@ -356,7 +356,8 @@
void doCompile(
std::istream&,
const Zorba_CompilerHints_t& aHints,
- bool fork_sctx = true);
+ bool fork_sctx,
+ ulong& nextVarId);
PlanWrapper_t generateWrapper();
=== modified file 'test/unit/static_context.cpp'
--- test/unit/static_context.cpp 2012-05-03 12:31:51 +0000
+++ test/unit/static_context.cpp 2012-05-07 23:45:25 +0000
@@ -82,9 +82,46 @@
return false;
}
-int static_context( int argc, char *argv[] ) {
- void *const zstore = StoreManager::getStore();
- Zorba *const zorba = Zorba::getInstance( zstore );
+
+bool sctx_test_3(Zorba* zorba)
+{
+ StaticContext_t sctx = zorba->createStaticContext();
+
+ try
+ {
+ Zorba_CompilerHints_t hints;
+ std::stringstream prolog;
+ prolog << "declare variable $prologVariable := <hello>World!</hello>;";
+ sctx->loadProlog(prolog.str(), hints);
+
+ // compile the main query using the populated static context
+ XQuery_t query = zorba->compileQuery("declare variable $queryVar := <queryVar>foo</queryVar>; $prologVariable ", sctx);
+
+ // execute the query and make sure that the result is correct
+ Zorba_SerializerOptions lSerOptions;
+ lSerOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
+ std::stringstream result;
+ query->execute(result, &lSerOptions);
+ std::cout << "Print prolog variable: " << result.str() << std::endl;
+
+ if (result.str() != "<hello>World!</hello>")
+ return false;
+ }
+ catch (XQueryException &e)
+ {
+ std::cerr << e << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+
+
+int static_context( int argc, char *argv[] )
+{
+ void* const zstore = StoreManager::getStore();
+ Zorba* const zorba = Zorba::getInstance( zstore );
if (!sctx_test_1(zorba))
return 1;
@@ -92,6 +129,9 @@
if (!sctx_test_2(zorba))
return 2;
+ if (!sctx_test_3(zorba))
+ return 3;
+
zorba->shutdown();
StoreManager::shutdownStore( zstore );
return 0;
Follow ups