Thanks Christian, 

The second query below worked beautifully.

I am trying to get db:path of the dynamic query. Code:

declare variable $n as xs:string external;
declare option output:item-separator "
";

let $aPath :=
for $db in db:list()
let $query :=
  "declare variable $db external; " ||
  "db:open($db)" || $n
return xquery:eval($query,
  map { 'db': $db, 'query': $n })


for $elem in $aPath
return db:path($elem)

and am getting below exception, when called:

mansi@work:BigData mansiadmin$ basex -b\$n='<query>' get_paths.xq 
Improper use? Potential bug? Your feedback is welcome:
Contact: basex-talk@mailman.uni-konstanz.de
Version: BaseX 7.9
Java: Oracle Corporation, 1.7.0_45
OS: Mac OS X, x86_64
Stack Trace: 
java.lang.NullPointerException
at org.basex.query.value.item.Str.get(Str.java:49)
at org.basex.query.func.FNDb.path(FNDb.java:489)
at org.basex.query.func.FNDb.item(FNDb.java:128)
at org.basex.query.expr.ParseExpr.iter(ParseExpr.java:45)
at org.basex.query.func.FNDb.iter(FNDb.java:92)
at org.basex.query.gflwor.GFLWOR$2.next(GFLWOR.java:78)
at org.basex.query.MainModule$1.next(MainModule.java:98)
at org.basex.core.cmd.AQuery.query(AQuery.java:91)
at org.basex.core.cmd.XQuery.run(XQuery.java:22)
at org.basex.core.Command.run(Command.java:329)
at org.basex.core.Command.execute(Command.java:94)
at org.basex.server.LocalSession.execute(LocalSession.java:121)
at org.basex.server.Session.execute(Session.java:37)
at org.basex.core.CLI.execute(CLI.java:106)
at org.basex.BaseX.<init>(BaseX.java:123)
at org.basex.BaseX.main(BaseX.java:42)


On Thu, Oct 30, 2014 at 5:54 AM, Christian Grün <christian.gruen@gmail.com> wrote:
Hi Mansi,

you have been close! It could work with the following query (I haven't
tried it out, though):

_ get_query_result.xq ____________________

declare variable $n external;
declare option output:item-separator "&#xa;";

let $aList :=
  for $name in db:list()
  let $db := db:open($name)
  return xquery:eval($n, map { '': $db })

return distinct-values($aList)
______________________________________

In this code, I'm opening the database in the main loop, and I then
bind it to the empty string. This way, the database will be the
context of the query to be evaluated query, and you won't have to deal
with bugs that arise from the concatenation of "db:open" and the query
string.

> 1. Can we assign dynamic values as a value to a map's key ?
> 2. Can I map have more than one key, in query:eval ?

This is both possible. As you see in the following query, you'll again
have to declare the variables that you want to bind. I agree this
causes a lot of code, so we may simplify it again in a future version
of BaseX:
______________________________________

let $n := "/a/b/c"
for $db in db:list()
let $query :=
  "declare variable $db external; " ||
  "db:open($db)" || $n
return xquery:eval($query,
  map { 'db': $db, 'query': $n })
______________________________________

Best,
Christian



--
- Mansi