Xquery with server commands
Monday, 4 February 2013 · 2 messages
RM
Raymond Meester4 Feb 2013 09:28 #
Consider the following xquery on "db2":
for $doc in db:open('db2')
return $docwith the following code
//start session
static ClientSession session;
session = new ClientSession("localhost", 1984, "admin", "admin");
session.execute(new Check(db1));
//query
ClientQuery query = session.query(xquery);
result = query.execute();
query.close();This code will execute, but with an empty result. This is because within the session only db1 is opened and I am querying db2. When explicit opening (session.execute(new Open(db2)); ) it returns the expected value of course. Do you agree that this can be confusing?
I would expect that the xquery in combination with the above code returns
1) an error that quering db2 while it's not opened in the session
or
2) that "db:open('db2')" in the xquery performs implicitly a session.execute(new Open(db2), so that it automatically switches to db2.
CG
Christian Grün4 Feb 2013 13:44 #
Hi Raymond,
Quoted text · Raymond Meester · 4 lines
> This code will execute, but with an empty result. This is because within the > session only db1 is opened and I am querying db2. When explicit opening > (session.execute(new Open(db2)); ) it returns the expected value of course. > Do you agree that this can be confusing?
I'm not 100% sure how you proceeded. I’ve added another example, which returns "<a/>" as result..
ClientSession session = new ClientSession("localhost", 1984,
"admin", "admin");
session.execute(new CreateDB("db1", "<a/>"));
session.execute(new CreateDB("db2", "<b/>"));
ClientQuery query = session.query("db:open('db1')");
System.out.println(query.execute());
query.close();Does this conform to your expectations?
Quoted text · Raymond Meester · 4 lines
> 1) an error that quering db2 while it's not opened in the session > or > 2) that "db:open('db2')" in the xquery performs implicitly a > session.execute(new Open(db2), so that it automatically switches to db2.
Such a decision could lead to various new questions, because XQuery allows much more databases to be opened in a single query. What would you e.g. expect the following XQuery to do?
for $d in 1 to 5
let $db := db:open($d)
return $db//results..or yet another example:
db:create( "newdb", db:open("olddb") )Best,
Christian
Quoted text · Raymond Meester · 11 lines
> > I would expect that the xquery in combination with the above code returns > > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
Written for BaseX 7.5. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery