Rebind the variables

Thursday, 23 June 2011 · 3 messages
O
Oda23 Jun 2011 16:55 #
Hi, I want to rebind the variables, but got the result that wasn't expected. How can I get the expected result without creating new processor instance? (When I use proc.query() and don't declare $var2 then got the expected result. But I have to declare $var2.)
----------
String query =
	"declare variable $var1 as xs:string external; " +
	"declare variable $var2 as xs:string := 'BBB'; " +
	"($var1, $var2)";
QueryProcessor proc = new QueryProcessor(query, new Context());

// "AAA BBB"
proc.bind("var1", "AAA");
System.out.println(proc.execute());

//duplicate definition error of $var2
//proc.query(query);

// "AAA BBB" not "CCC BBB"
proc.bind("var1", "CCC");
System.out.println(proc.execute());
proc.close(); ---------- Thanks, Oda.
CG
Christian Grün23 Jun 2011 17:08 #
Hi Oda, query execution in BaseX includes various optimization steps, which might change the original quey plan. This can include the pre-evaluation of variable bindings, which will disallow repeated bindings. I'd recommend to create a new processor instance, which is fast enough in most scenarios we've encountered. Hope this helps, Christian ___________________________ Christian Grün, BaseX Uni KN, Box 188 78457 Konstanz, Germany http://www.basex.org
Quoted text · Oda · 37 lines
On Thu, Jun 23, 2011 at 4:55 PM, Oda <0170003 at gmail.com> wrote: > Hi, > > I want to rebind the variables, but got the result that wasn't expected. > How can I get the expected result without creating new processor instance? > (When I use proc.query() and don't declare $var2 then > got the expected result. But I have to declare $var2.) > > ---------- > String query = > "declare variable $var1 as xs:string external; " + > "declare variable $var2 as xs:string := 'BBB'; " + > "($var1, $var2)"; > QueryProcessor proc = new QueryProcessor(query, new Context()); > > // "AAA BBB" > proc.bind("var1", "AAA"); > System.out.println(proc.execute()); > > //duplicate definition error of $var2 > //proc.query(query); > > // "AAA BBB" not "CCC BBB" > proc.bind("var1", "CCC"); > System.out.println(proc.execute()); > > proc.close(); > ---------- > > Thanks, > > Oda. > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
O
Oda23 Jun 2011 18:36 #
Christian, thanks for your reply. I create a new processor instance. Oda. 2011/6/24 Christian Grün <christian.gruen at gmail.com>:
Quoted text · Christian Grün · 16 lines
> Hi Oda, > > query execution in BaseX includes various optimization steps, which > might change the original quey plan. This can include the > pre-evaluation of variable bindings, which will disallow repeated > bindings. I'd recommend to create a new processor instance, which is > fast enough in most scenarios we've encountered. > > Hope this helps, > Christian > ___________________________ > > Christian Grün, BaseX > Uni KN, Box 188 > 78457 Konstanz, Germany > http://www.basex.org

⚡Generated with XQuery