Hi,
When experimenting with my RBaseX-package (I had hoped to submit it to CRAN today), I use the following pattern: 1 Define a query 2 Create a query-object 3 Bind variables (optional) 4 Execute the query
When used this pattern on the following query, everything functions as expected: declare variable $name external; for $i in 1 to 3 return element { $name } { $i }
The following query is also functioning: paste("declare variable $greet external;", "declare variable $friend external;", "declare variable $into external;", "let $greet := 'Greetings, my '", "let $friend := 'friend'", "for $i in 1 to 3", "let $friend_num := $greet || $friend || $i", "return insert nodes element { $friend } { $friend_num }", "into root", sep = " ")
When I modify "into root" to "into $p" and bind $p to root Bind(query_obj, "$p", "root")
I get the following error:
[XPST0008] Undeclared variable $p
The Bind-function returns with code \00, indicating that it is executed without errors.
Does this mean that there is a bug in my code or am I violating XQuery-syntax?
Ben Engbers
Hi Ben,
If you...
and bind $p to root Bind(query_obj, "$p", "root")
…you’ll need to add another external variable declaration in your query:
"declare variable $p external;" ...
Please note, in addition, that your query won’t be executable as you are trying to assign a dynamic path expression (e.g., 'root') to your query. If you need to build dynamic query strings, you’ll have to modify your original query string and send the result to the server.
Hope this helps, Christian
When used this pattern on the following query, everything functions as expected: declare variable $name external; for $i in 1 to 3 return element { $name } { $i }
The following query is also functioning: paste("declare variable $greet external;", "declare variable $friend external;", "declare variable $into external;", "let $greet := 'Greetings, my '", "let $friend := 'friend'", "for $i in 1 to 3", "let $friend_num := $greet || $friend || $i", "return insert nodes element { $friend } { $friend_num }", "into root", sep = " ")
When I modify "into root" to "into $p" and bind $p to root Bind(query_obj, "$p", "root")
I get the following error:
[XPST0008] Undeclared variable $p
The Bind-function returns with code \00, indicating that it is executed without errors.
Does this mean that there is a bug in my code or am I violating XQuery-syntax?
Ben Engbers
Hi Christian,
Thanks for the explanation.
I am glad to learn that - at least for this moment - I don't have to change my code :-)
Ben
Hi Ben,
If you...
and bind $p to root Bind(query_obj, "$p", "root")
…you’ll need to add another external variable declaration in your query:
"declare variable $p external;" ...
Please note, in addition, that your query won’t be executable as you are trying to assign a dynamic path expression (e.g., 'root') to your query. If you need to build dynamic query strings, you’ll have to modify your original query string and send the result to the server.
Hope this helps, Christian
basex-talk@mailman.uni-konstanz.de