> The use of String Constructor does not avoid the global read lock Good to know, thanks. It now does [1], provided that the constructor consists of a single static strings.
[1] http://files.basex.org/releases/latest/ > <job id="job13" type="ScheduledXQuery" state="cached" user="admin" > duration="PT0.007S" reads="(global)" > writes="(none)">count(collection(``[BEP]``))</job> > > On 20 September 2017 at 23:28, Christian Grün <christian.gr...@gmail.com> > wrote: >> >> > bxcode:inline-variables($xqcode-uri) as xs:string >> > @returns xquery code that is the source code from $xqcode-uri but with >> > inlining "constant" variables and operations applied >> > >> > This could be used as a preprocessor. >> > Is this something that could be created from the bits and pieces in the >> > current BaseX Java code? >> >> This reminds me of the discussion with Omar [1]: There is currently no >> way to generate a correct string representation for compiled code. In >> the GUI Info View, we output a string representation of the optimized >> query. In simple cases, this string is a valid and equivalent to the >> original query string, but it’s fairly easy to generate invalid >> results. >> >> If it’s an option for you to generate code in XQuery, something like >> the following could be done: >> >> _ bxcode.xqm _______ >> >> module namespace bxcode = 'bxcode'; >> declare function bxcode:bind-external-variables( >> $uri as xs:string, >> $vars as map(xs:string, xs:string) >> ) as xs:string { >> let $xqcode := unparsed-text($uri) >> return fold-left( >> map:keys($vars), $xqcode, function($string, $name) { >> let $value := replace($vars($name), ']``', '`{"]``"}`', 'q') >> return $string >> => replace('declare variable $' || $name || ' external;', '', 'q') >> => replace('$' || $name, '``[' || $value || ']``', 'q') >> } >> ) >> }; >> >> _ example.xq _______ >> >> declare variable $db external; >> count(collection($db)) >> >> _ run-bxcode.xq _______ >> >> import module namespace bxcode = 'bxcode' at 'bxcode.xqm'; >> bxcode:bind-external-variables('query.xq', map { 'db': 'BEP' }) >> >> _ output _______ >> >> count(collection(``[BEP]``)) >> >> Cheers, >> Christian >> >> [1] >> https://www.mail-archive.com/basex-talk@mailman.uni-konstanz.de/msg09863.html > >