I decided to try creating some command files to simplify administration: https://docs.basex.org/wiki/Commands#String_Syntax I was surprised that this did not work: % cat foo.bsx CREATE DB test ADD TO embedded.xml <root>embedded</root> # run query XQUERY <hits>{ count(//text()) }</hits> CLOSE % basex foo.bsx Stopped at /.../foo.bsx, 1/9: [XPST0003] Unexpected end of query: 'DB test...'. This works fine: % basex <foo.bsx BaseX 9.1 [Standalone] Try 'help' to get more information.
CREATE DB test
Database 'test' created in 196.04 ms.
ADD TO embedded.xml <root>embedded</root>
Resource(s) added in 101.36 ms.
# run query
XQUERY <hits>{ count(//text()) }</hits>
<hits>1</hits> Query executed in 393.09 ms.
CLOSE
Database 'test' was closed. What am I missing? Jonathan
On 28.06.2021 20:54, Jonathan Robie wrote:
I decided to try creating some command files to simplify administration:
https://docs.basex.org/wiki/Commands#String_Syntax <https://docs.basex.org/wiki/Commands#String_Syntax>
I was surprised that this did not work:
% cat foo.bsx
CREATE DB test
ADD TO embedded.xml <root>embedded</root>
# run query
XQUERY <hits>{ count(//text()) }</hits>
CLOSE
% basex foo.bsx
Stopped at /.../foo.bsx, 1/9:
[XPST0003] Unexpected end of query: 'DB test...'.
I think the suffix of the file needs to be ".bxs" to be treated as a command sequence, otherwise it is treated as XQuery code. So you have the wrong file suffix.
DOH! Thanks for the help, I seem to be a little dsylexic today ;-> Now it works, but SET WRITEBACK true doesn't seem to be working: DROP DB oshb-morphology CREATE DB oshb-morphology ADD ./morphhb/wlc SET WRITEBACK true XQUERY ./xquery/merge-proper-nouns-oshb.xq EXPORT ./out This query does an update. If I run the same query in the GUI, it works, but not in this ... um ... bxs file. What do I do to enable updates? Jonathan On Mon, Jun 28, 2021 at 3:57 PM Martin Honnen <martin.honnen@gmx.de> wrote:
On 28.06.2021 20:54, Jonathan Robie wrote:
I decided to try creating some command files to simplify administration:
https://docs.basex.org/wiki/Commands#String_Syntax <https://docs.basex.org/wiki/Commands#String_Syntax>
I was surprised that this did not work:
% cat foo.bsx
CREATE DB test
ADD TO embedded.xml <root>embedded</root>
# run query
XQUERY <hits>{ count(//text()) }</hits>
CLOSE
% basex foo.bsx
Stopped at /.../foo.bsx, 1/9:
[XPST0003] Unexpected end of query: 'DB test...'.
I think the suffix of the file needs to be ".bxs" to be treated as a command sequence, otherwise it is treated as XQuery code. So you have the wrong file suffix.
Hi Jonathan,
... XQUERY ./xquery/merge-proper-nouns-oshb.xq
I don’t have access to the query file you want to evaluate, but I assume your command script should work if you replace XQUERY with the RUN command [1]. You can skip the WRITEBACK option if you perform updates on database. It is only required to update local files [2]: XQUERY file:write(file:base-dir() || 'example.xml', <a/>) SET WRITEBACK true XQUERY insert node <b/> into doc('example.xml')/* XQUERY doc('example.xml') Hope this helps, Christian [1] https://docs.basex.org/wiki/Commands#RUN [2] https://docs.basex.org/wiki/Options#WRITEBACK
Thanks - this fixed my update problem. One more question ... how do I run a query that is in a file and write the results back to a different file? The last line in this script does not produce output: DROP DB oshb-morphology CREATE DB oshb-morphology ADD ./morphhb/wlc SET WRITEBACK true RUN ./xquery/merge-proper-nouns-oshb.xq EXPORT ./out XQUERY ./xquery/mappings.xq It's not a problem with databases that are not open, I open databases explicitly in mappings.xq, e.g. db:open("oshb-morphology") and the same query works fine from the GUI with no databases explicitly opened. Jonathan On Tue, Jun 29, 2021 at 4:48 AM Christian Grün <christian.gruen@gmail.com> wrote:
Hi Jonathan,
... XQUERY ./xquery/merge-proper-nouns-oshb.xq
I don’t have access to the query file you want to evaluate, but I assume your command script should work if you replace XQUERY with the RUN command [1].
You can skip the WRITEBACK option if you perform updates on database. It is only required to update local files [2]:
XQUERY file:write(file:base-dir() || 'example.xml', <a/>) SET WRITEBACK true XQUERY insert node <b/> into doc('example.xml')/* XQUERY doc('example.xml')
Hope this helps, Christian
[1] https://docs.basex.org/wiki/Commands#RUN [2] https://docs.basex.org/wiki/Options#WRITEBACK
Hi Jonathan,
SET WRITEBACK true RUN ./xquery/merge-proper-nouns-oshb.xq
I see you are still using WRITEBACK… Does your query file 'merge-proper-nouns-oshb.xq' access any local files that you are updating?
XQUERY ./xquery/mappings.xq
Once again, you may need to replace XQUERY with RUN. If you use XQUERY, you must supply the query itself after the command.
how do I run a query that is in a file and write the results back to a different file?
You could use the File Module for that, or fn:put. If you want to write the result of a query evaluation to a file, you’ll probably need to do this on command line for all results returned by a script> basex -o result.xml script.bxs Hope this helps, Christian
Great, thanks! Jonathan On Tue, Jun 29, 2021 at 10:22 AM Christian Grün <christian.gruen@gmail.com> wrote:
Hi Jonathan,
SET WRITEBACK true RUN ./xquery/merge-proper-nouns-oshb.xq
I see you are still using WRITEBACK… Does your query file 'merge-proper-nouns-oshb.xq' access any local files that you are updating?
XQUERY ./xquery/mappings.xq
Once again, you may need to replace XQUERY with RUN. If you use XQUERY, you must supply the query itself after the command.
how do I run a query that is in a file and write the results back to a different file?
You could use the File Module for that, or fn:put. If you want to write the result of a query evaluation to a file, you’ll probably need to do this on command line for all results returned by a script>
basex -o result.xml script.bxs
Hope this helps, Christian
participants (4)
-
Christian Grün -
Jonathan Robie -
Martin Honnen -
Martin Honnen