不允许更新表达式Basex [英] No updating expression allowed Basex

查看:115
本文介绍了不允许更新表达式Basex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是BaseX版本8.6.6,更新数据库时出现错误

I am using BaseX version 8.6.6 i am getting the error while updating database

表达式必须全部更新或返回空序列

expression must all be updating or return empty sequence

下面是代码:

declare  %private %updating function local:ingest-job()
{

let $contentpath := 'D:\2019\bloomsbury-ingest-content\TEI.zip'
let $archive := file:read-binary($contentpath)
               for $entry in archive:entries($archive)[fn:ends-with(., '.xml')]
               let $rootNode := fn:name(fn:parse-xml(archive:extract-text($archive, $entry))/*)
               return
               let $docId := fn:parse-xml(archive:extract-text($archive, $entry))/*/@xml:id/string()[$rootNode='TEI']
               let $cid := fn:replace($docId,'[a-zA-z-]','')
               let $jobID := fn:concat($cid,'-',fn:string(fn:format-dateTime(fn:current-dateTime(), '[Y0001][M01][D01][H01][m01][s01][f01]')))

              let $jobChunk := <job>
                                  <job-info>
                                      <id>{$jobID}</id>
                                      <cid>{$cid}</cid>
                                  </job-info>
                              </job>
                 return
                 (
                  db:add('testdb',$jobChunk,fn:concat('/jobs/',$jobID,'.xml')),
                db:output( <result><status>Success</status><message>Job created</message><jobid>{$jobID}</jobid></result>)
                  )


};

<results>{local:ingest-job()}</results>

当前输出:

<result>
  <status>Success</status>
  <message>Job created</message>
  <jobid>9781784604387-2019102816303069</jobid>
</result>
<result>
  <status>Success</status>
  <message>Job created</message>
  <jobid>9781784604417-2019102816303069</jobid>
</result>

预期输出:

<results>
<result>
  <status>Success</status>
  <message>Job created</message>
  <jobid>9781784604387-2019102816303069</jobid>
</result>
<result>
  <status>Success</status>
  <message>Job created</message>
  <jobid>9781784604417-2019102816303069</jobid>
</result>
</results>

这里出了什么问题?

推荐答案

由于错误消息表明您在此处混合使用更新和非更新表达式.通过使用db:output()可以避免在函数中执行此操作,但是您可以在主要部分中执行此操作:

As the error message indicates you are mixing updating and non-updating expressions here. You avoid doing this within your function by using db:output(), but you do it in the main part:

<results>{local:ingest-job()}</results>

这将构造results元素,并且其中具有更新功能. XQUF规范不允许这样做,并且由于BaseX试图符合标准,因此您不能这样做.

This constructs the results element and within it you have an updating function. The XQUF spec does not allow this and as BaseX tries to be standards compliant you are not allowed to do that.

您可以选择几种避免方法:

You have several options how to avoid that:

  1. 您只能使用转换表达式转换/添加主存储器中的节点.
  2. 您只需调用local:ingest-job()而不是<results>{local:ingest-job()}</results>.这样,您就没有非更新的表达式.但是,那么您将没有周围的results元素.
  3. 您打开 MIXUPDATES
  1. You only transform/add the nodes in main memory using transform expressions.
  2. You simply call local:ingest-job() instead of <results>{local:ingest-job()}</results>. This way you have no non-updating expression. However, then you will have no surrounding results element.
  3. You turn on MIXUPDATES

这些选项也在BaseX Wiki中的中进行了描述.

These options are also described within the BaseX wiki.

这篇关于不允许更新表达式Basex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆