job:execute and locks
Thursday, 26 February 2026 · 7 messages · last reply 27 Feb 2026
GS
Graydon Saunders26 Feb 2026 04:51 #
Hello --
I'm on the 12.3 413f355 beta and using the BaseX GUI.
So this query runs forever in a way that makes me think I've got a locking problem:
declare namespace v2="https://schema.iccsafe.org/book/schema/1.0";
(: list of query names, in order; order is important here :)
declare variable $queryNameList as xs:string+ := ('load-before-1.xq', 'load-after-2.xq','wordcount-3.xq');
(: job:execute wants URIs. We could use file:resolve-path here but minimalist relative URIs work :)
declare variable $queryURIList as xs:anyURI+ := $queryNameList ! xs:anyURI(.);
(: the map with the file paths :)
declare variable $namesMap as xs:string := '/home/graydon/work/tests/compare_map.xquery';
(: where reports should go :)
declare variable $reportsDir as xs:string := '/home/graydon/work/tests/reports/';
(: try putting path pairs in an external map so we ought not have any db lock issues :)
let $names as map(xs:string,map(xs:string,xs:string)) := file:read-text($namesMap) => xquery:eval()
return
(: bindings to pass values to the queries we're about to run :)
for key $k value $v in $names
let $bindings as map(*) :=
{'reportsDir': $reportsDir, 'sourceName': $v?source, 'resultName': $v?result }
return for $query in $queryURIList
return job:execute($query,$bindings)When I could get the information to set the values in $v?source and $v?result without having to use doc() to look inside files, this query's immediate ancestor worked.
The docs at https://docs.basex.org/main/Job_Functions#job:execute say "It is safe to use the function if the calling query does not lock anything."
Does having opened a document via doc() in another query in the GUI leave that document locked? If so, is there a way to drop those locks?
Am I locking something with this query?
(The "generate a bxs script" version (from the same map!) runs in about 45 seconds, so I think the queries being called via
job:execute work.)
Thanks!
GraydonCG
Christian Grün26 Feb 2026 17:45 #
Hi Graydon,
Quoted text · Graydon Saunders · 1 line
> let $names as map(xs:string,map(xs:string,xs:string)) := file:read-text($namesMap) => xquery:eval()
The
xquery:eval function causes a global lock as the dynamically evaluated code might do all kinds of things. I haven’t explored it further, but maybe you can simply replace it by job:execute() calls.
Best,
ChristianQuoted text · Graydon Saunders · 32 lines
Von: Graydon Saunders via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> Gesendet: Donnerstag, 26. Februar 2026 04:49 An: BaseX <BaseX-Talk at mailman.uni-konstanz.de> Betreff: [basex-talk] job:execute and locks Hello -- I'm on the 12.3 413f355 beta and using the BaseX GUI. So this query runs forever in a way that makes me think I've got a locking problem: declare namespace v2="https://schema.iccsafe.org/book/schema/1.0"; (: list of query names, in order; order is important here :) declare variable $queryNameList as xs:string+ := ('load-before-1.xq', 'load-after-2.xq','wordcount-3.xq'); (: job:execute wants URIs. We could use file:resolve-path here but minimalist relative URIs work :) declare variable $queryURIList as xs:anyURI+ := $queryNameList ! xs:anyURI(.); (: the map with the file paths :) declare variable $namesMap as xs:string := '/home/graydon/work/tests/compare_map.xquery'; (: where reports should go :) declare variable $reportsDir as xs:string := '/home/graydon/work/tests/reports/'; (: try putting path pairs in an external map so we ought not have any db lock issues :) let $names as map(xs:string,map(xs:string,xs:string)) := file:read-text($namesMap) => xquery:eval() return (: bindings to pass values to the queries we're about to run :) for key $k value $v in $names let $bindings as map(*) := {'reportsDir': $reportsDir, 'sourceName': $v?source, 'resultName': $v?result } return for $query in $queryURIList return job:execute($query,$bindings) When I could get the information to set the values in $v?source and $v?result without having to use doc() to look inside files, this query's immediate ancestor worked. The docs at https://docs.basex.org/main/Job_Functions#job:execute say "It is safe to use the function if the calling query does not lock anything." Does having opened a document via doc() in another query in the GUI leave that document locked? If so, is there a way to drop those locks? Am I locking something with this query? (The "generate a bxs script" version (from the same map!) runs in about 45 seconds, so I think the queries being called via job:execute work.) Thanks! Graydon
GS
Graydon Saunders26 Feb 2026 18:41 #
Hi Christian,
Thank you!
I should not think of
xquery:eval() as "parse this harmless XPath map". Hopefully I will remember this! (Is there a good/better/expected way to pass data around as XPath maps?)
A job:eval version works.
Much appreciated,
GraydonQuoted text · Christian Grün · 57 lines
On Thu, Feb 26, 2026, at 11:45, Christian Grün wrote: > Hi Graydon, > > > let $names as map(xs:string,map(xs:string,xs:string)) := file:read-text($namesMap) => xquery:eval() > > The xquery:eval function causes a global lock as the dynamically evaluated code might do all kinds of things. I haven’t explored it further, but maybe you can simply replace it by job:execute() calls. > > Best, > Christian > > > *Von:* Graydon Saunders via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> > *Gesendet:* Donnerstag, 26. Februar 2026 04:49 > *An:* BaseX <BaseX-Talk at mailman.uni-konstanz.de> > *Betreff:* [basex-talk] job:execute and locks > > Hello -- > > I'm on the 12.3 413f355 beta and using the BaseX GUI. > > So this query runs forever in a way that makes me think I've got a locking problem: > > declare namespace v2="https://schema.iccsafe.org/book/schema/1.0"; > > (: list of query names, in order; order is important here :) > declare variable $queryNameList as xs:string+ := ('load-before-1.xq', 'load-after-2.xq','wordcount-3.xq'); > (: job:execute wants URIs. We could use file:resolve-path here but minimalist relative URIs work :) > declare variable $queryURIList as xs:anyURI+ := $queryNameList ! xs:anyURI(.); > > (: the map with the file paths :) > declare variable $namesMap as xs:string := '/home/graydon/work/tests/compare_map.xquery'; > (: where reports should go :) > declare variable $reportsDir as xs:string := '/home/graydon/work/tests/reports/'; > > (: try putting path pairs in an external map so we ought not have any db lock issues :) > let $names as map(xs:string,map(xs:string,xs:string)) := file:read-text($namesMap) => xquery:eval() > > return > (: bindings to pass values to the queries we're about to run :) > for key $k value $v in $names > let $bindings as map(*) := > {'reportsDir': $reportsDir, 'sourceName': $v?source, 'resultName': $v?result } > return for $query in $queryURIList > return job:execute($query,$bindings) > > When I could get the information to set the values in $v?source and $v?result without having to use doc() to look inside files, this query's immediate ancestor worked. > > The docs at https://docs.basex.org/main/Job_Functions#job:execute say "It is safe to use the function if the calling query does not lock anything." > > Does having opened a document via doc() in another query in the GUI leave that document locked? If so, is there a way to drop those locks? > > Am I locking something with this query? > > (The "generate a bxs script" version (from the same map!) runs in about 45 seconds, so I think the queries being called via job:execute work.) > > Thanks! > Graydon
CG
Christian Grün26 Feb 2026 21:07 #
Quoted text · Graydon Saunders · 1 line
> I should not think of xquery:eval() as "parse this harmless XPath map". Hopefully I will remember this! (Is there a good/better/expected way to pass data around as XPath maps?)
I am not sure what you are trying to achieve. Do you have a little example?
GS
Graydon Saunders26 Feb 2026 21:32 #
Sometimes several things share somewhat complex lists; for example, 'falseNumberMap': {
'road-names': {
'regexp': '^A.P.A.',
'label': '#'
},
'utah-something': {
'regexp': '^\p{Zs}*U\.C\.A\.',
'label': '#'
},
'house-bill': {
'regexp': '^\p{Zs}*H\.B\.',
'label': '#'
},
'post-office-box': {
'regexp': '^\p{Zs}*P\.O\.',
'label': '#'
}
}
(The real one is a lot longer; these are regular expressions matching things at the start of a line that a conversion process might otherwise mistake for numbers and think it should treat specially.)
The map lives in a file; it might be maintained by hand. Various queries want to be able to load this map so they can follow a common pattern for identifying numbers. I'm used to using some flavour of eval() function to do this, but if eval() causes a global lock I would rather use something that didn't.
Thanks!
Graydon
Quoted text · Christian Grün · 4 lines
On Thu, Feb 26, 2026, at 15:07, Christian Grün wrote: > > I should not think of xquery:eval() as "parse this harmless XPath map". Hopefully I will remember this! (Is there a good/better/expected way to pass data around as XPath maps?) > > I am not sure what you are trying to achieve. Do you have a little example?
CG
Christian Grün26 Feb 2026 21:43 #
Got it. If you represent your data as JSON, you could use
fn:parse-json. store:put and store:get can be used for arbitrary XDM data (except for function items). All of them won’t create locks.Quoted text · Graydon Saunders · 30 lines
Von: Graydon Saunders <graydonish at fastmail.com> Gesendet: Donnerstag, Februar 26, 2026 9:32:32 PM An: Christian Grün <cg at basex.org>; BaseX <basex-talk at mailman.uni-konstanz.de> Betreff: Re: [basex-talk] job:execute and locks Sometimes several things share somewhat complex lists; for example, 'falseNumberMap': { 'road-names': { 'regexp': '^A.P.A.', 'label': '#' }, 'utah-something': { 'regexp': '^\p{Zs}*U\.C\.A\.', 'label': '#' }, 'house-bill': { 'regexp': '^\p{Zs}*H\.B\.', 'label': '#' }, 'post-office-box': { 'regexp': '^\p{Zs}*P\.O\.', 'label': '#' } } (The real one is a lot longer; these are regular expressions matching things at the start of a line that a conversion process might otherwise mistake for numbers and think it should treat specially.) The map lives in a file; it might be maintained by hand. Various queries want to be able to load this map so they can follow a common pattern for identifying numbers. I'm used to using some flavour of eval() function to do this, but if eval() causes a global lock I would rather use something that didn't. Thanks! Graydon On Thu, Feb 26, 2026, at 15:07, Christian Grün wrote: > I should not think of xquery:eval() as "parse this harmless XPath map". Hopefully I will remember this! (Is there a good/better/expected way to pass data around as XPath maps?) I am not sure what you are trying to achieve. Do you have a little example?
GS
Graydon Saunders27 Feb 2026 14:16 #
Thank you!
It would appear I need to make friends with the store module.
Much appreciated,
Graydon
Quoted text · Christian Grün · 40 lines
On Thu, Feb 26, 2026, at 15:43, Christian Grün wrote: > Got it. If you represent your data as JSON, you could use fn:parse-json. store:put and store:get can be used for arbitrary XDM data (except for function items). All of them won’t create locks. > > > *Von:* Graydon Saunders <graydonish at fastmail.com> > *Gesendet:* Donnerstag, Februar 26, 2026 9:32:32 PM > *An:* Christian Grün <cg at basex.org>; BaseX <basex-talk at mailman.uni-konstanz.de> > *Betreff:* Re: [basex-talk] job:execute and locks > > Sometimes several things share somewhat complex lists; for example, > 'falseNumberMap': { > 'road-names': { > 'regexp': '^A.P.A.', > 'label': '#' > }, > 'utah-something': { > 'regexp': '^\p{Zs}*U\.C\.A\.', > 'label': '#' > }, > 'house-bill': { > 'regexp': '^\p{Zs}*H\.B\.', > 'label': '#' > }, > 'post-office-box': { > 'regexp': '^\p{Zs}*P\.O\.', > 'label': '#' > } > } > (The real one is a lot longer; these are regular expressions matching things at the start of a line that a conversion process might otherwise mistake for numbers and think it should treat specially.) > > The map lives in a file; it might be maintained by hand. Various queries want to be able to load this map so they can follow a common pattern for identifying numbers. I'm used to using some flavour of eval() function to do this, but if eval() causes a global lock I would rather use something that didn't. > > Thanks! > Graydon > > On Thu, Feb 26, 2026, at 15:07, Christian Grün wrote: >> > I should not think of xquery:eval() as "parse this harmless XPath map". Hopefully I will remember this! (Is there a good/better/expected way to pass data around as XPath maps?) >> >> I am not sure what you are trying to achieve. Do you have a little example? >
Written for BaseX 12.2. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery