This .xq works the first time when returning db:create. However, once the DB are created, if I run it again, files are note replaced. Instead, I get java.lang.ArrayIndexOutOfBoundsException. I can send the DB in private if necessary for debugging. The result is not exactly an index, it's just flattening a few levels of indirection to make future queries faster.
I was testing this on 9.2.3.
Also a side question, is there a way to rewrite this query so not all DBs are locked? I get lock: global. I would like to lock only DBs that start with 'index-prompt-' I tried hard coding the prefix in the db:create and db:replace fonctions but that didn't help. Since I will have this running on a loop (cannot catch updated on src DB), I don't want to lock the whole system each time this query is running. It does take a good 12 seconds to run.
(: USAGE: for $prompt in db:attribute('index-prompt-en-us', 'setup_as_new', 'name')/.. return $prompt => prof:time() :) let $langs := for $lang in db:list()[string-length(.) = 5][substring(., 3, 1) = '-'] return $lang return for $lang in $langs let $index-db := 'index-prompt-' || $lang let $prompt-file-name := 'prompts-' || $lang || '.xml' let $index := <index>{ for $string-group in db:open('global-content')//*[name()='string-group'] let $prompt-this-lang := $string-group/child::*[@xml:lang=$lang][normalize-space(.)!=''] let $prompt-base := if (exists($prompt-this-lang)) then $prompt-this-lang else $string-group/child::*[@xml:lang='en-us'] let $p2 := db:attribute('global-content', $string-group/data(@key), 'key')/..[name()='prompt'][ancestor::*[last()]/name()='prompt-refs'][@package=$string-group/data(@package)][@pkg-version=$string-group/data(@pkg-version)] let $prompts := ( for $prompt-match in $p2 return copy $copy := $prompt-base modify ( for $attr in $prompt-match/@*[name()!='package' and name()!='pkg-version' and name()!='key'] return insert node $attr into $copy ) return $copy ) return $prompts }</index>
return if (db:exists($index-db)) then db:replace($index-db, $prompt-file-name, $index) else db:create($index-db, $index, $prompt-file-name , map { 'updindex': true() })
Hi France,
Instead, I get java.lang.ArrayIndexOutOfBoundsException.
Could you send us the full stack trace?
I was testing this on 9.2.3.
Can the problem be reproduced with 9.3.1?
Also a side question, is there a way to rewrite this query so not all DBs
are locked? I get lock: global. I would like to lock only DBs that start with 'index-prompt-'
Currently no (unless you explicitly open all those databases in your query). See [1] for more information.
Best, Christian
[1] http://docs.basex.org/wiki/Transaction_Management#XQuery
9.3.1 seems to resolve the issue.
On Sun, Dec 22, 2019 at 4:12 PM Christian Grün christian.gruen@gmail.com wrote:
Hi France,
Instead, I get java.lang.ArrayIndexOutOfBoundsException.
Could you send us the full stack trace?
I was testing this on 9.2.3.
Can the problem be reproduced with 9.3.1?
Also a side question, is there a way to rewrite this query so not all DBs
are locked? I get lock: global. I would like to lock only DBs that start with 'index-prompt-'
Currently no (unless you explicitly open all those databases in your query). See [1] for more information.
Best, Christian
[1] http://docs.basex.org/wiki/Transaction_Management#XQuery
basex-talk@mailman.uni-konstanz.de