如何在BaseX中返回结果以及更新操作? [英] How to return results together with update operations in BaseX?

查看:131
本文介绍了如何在BaseX中返回结果以及更新操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认识到,用BaseX客户端执行的(insert/delete)-XQueries总是返回一个空字符串.我觉得这很令人困惑或不直观.

I recognized that (insert/delete)-XQueries executed with the BaseX client always returning an empty string. I find this very confusing or unintuitive.

有没有一种方法可以查找查询是否成功"而无需再次查询数据库(并使用可能存在错误的传递"逻辑,例如如果我删除了一个节点,则必须在该节点中有'oldNodeCount-1'个节点XML")?

Is there a way to find out if the query was "successful" without querying the database again (and using potentially buggy "transitive" logic like "if I deleted a node, there must be 'oldNodeCount-1' nodes in the XML")?

推荐答案

XQuery Update语句不返回任何内容-这就是它们的定义方式.但是您不是唯一不喜欢这些限制的人,并且 BaseX为此添加了两种方法限制:

XQuery Update statements do not return anything -- that's how they are defined. But you're not the only one who does not like those restrictions, and BaseX added two ways around this limitation:

返回结果

默认情况下,无法混合使用不同类型的表达式 在查询结果中.查询的最外面的表达式必须是 更新或非更新表达式的集合.但这有 两种方法:

Returning Results

By default, it is not possible to mix different types of expressions in a query result. The outermost expression of a query must either be a collection of updating or non-updating expressions. But there are two ways out:

  • 特定于BaseX的 update:output() 函数将其桥接差距:它在运行时缓存其参数的结果,并在之后返回它们 所有更新均已处理.以下示例执行 更新并返回成功消息:

  • The BaseX-specific update:output() function bridges this gap: it caches the results of its arguments at runtime and returns them after all updates have been processed. The following example performs an update and returns a success message:

update:output("Update successful."), insert node <c/> into doc('factbook')/mondial

  • 使用 MIXUPDATES 选项,所有更新约束将为关闭.返回的节点在被修改之前将被复制 更新表达式.如果在以下时间内返回项目,则会引发错误 转换表达式.

  • With the MIXUPDATES option, all updating constraints will be turned off. Returned nodes will be copied before they are modified by updating expressions. An error is raised if items are returned within a transform expression.

    如果要修改主内存中的节点,可以使用 transform 表达式.

    If you want to modify nodes in main memory, you can use the transform expression.

    由于您似乎要修改磁盘上的数据 ,因此变换表达式将无济于事.启用MIXUPDATES可使您既更新文档又同时返回某些内容,例如运行类似

    The transform expression will not help you, as you seem to modify the data on disk. Enabling MIXUPDATES allows you to both update the document and return something at the same time, for example running something like

    let $node := <c/>
    return ($node, insert node $node into doc('factbook')/mondial)
    

    MIXUPDATES允许您返回可以进一步处理的内容.结果将在返回之前被复制,如果您运行多个更新操作而没有得到预期的结果,请确保您具有待更新列表.

    MIXUPDATES allows you to return something which can be further processed. Results are copied before being returned, if you run multiple updates operations and do not get the expected results, make sure you got the concept of the pending update list.

    db:output()函数有意破坏其接口协定:它被定义为更新函数(不具有任何输出),但同时将一些信息打印到查询信息中.您无法进一步处理这些结果,但是输出可以帮助您调试一些问题.

    The db:output() function intentionally breaks its interface contract: it is defined to be an updating function (not having any output), but at the same time it prints some information to the query info. You cannot further process these results, but the output can help you debugging some issues.

    两种方式都将使您不能立即获得更新结果,您必须自己添加一些内容-并且请注意,直到挂起的更新列表被显示时,更新才可见应用,即.查询结束后.

    Both ways, you will not be able to have an immediate result from the update, you have to add something on your own -- and be aware updates are not visible until the pending update list is applied, ie. after the query finished.

    显然,这些选项是特定于BaseX的.如果您强烈要求兼容和标准的XQuery,则不能使用这些表达式.

    Obviously, these options are BaseX-specific. If you strongly require compatible and standard XQuery, you cannot use these expressions.

    这篇关于如何在BaseX中返回结果以及更新操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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