本机 xml 数据库中的唯一性插入 [英] uniqness insertion in native xml database

查看:24
本文介绍了本机 xml 数据库中的唯一性插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个基于 XML 的项目.我使用 Sedna 数据库来存储我的集合(其中包含 XML 文件及其 XSD 架构文件).

我在这些方案中定义了主键/唯一键,但到目前为止我可以将重复值(通过 XQuery 更新插入命令)插入到主键字段中.

解决方案

为了保证唯一性约束,您应该在正确的路径上创建 BEFORE INSERT FOR EACH NODE 触发器.在触发器操作中,$NEW 传递变量可用于获取新键并检查它是否已存在于文档中(参见 示例 在手册中).要引发错误,可以使用 fn:error 函数.>

请注意以下有关触发器的注意事项:

  1. 禁止在触发动作的语句中使用 prolog"——Sedna 程序员指南,XQuery 触发器.

  2. 另请参阅bug 51(虽然已经关闭).

I am developing a project based on XML. I use the Sedna database to store my collection (which contains XML files, and their XSD schema files).

I define the primary/unique keys in those schemes, but till now I can insert duplicate values (via XQuery update insert command) into primary key field.

解决方案

To guarantee uniqueness constraint you should create BEFORE INSERT FOR EACH NODE trigger on proper path. In the trigger action the $NEW transitive variable can be used to fetch the new key and check if it already exists in the document (see examples in the manual). To raise error fn:error function can be used.

Take the following note regarding triggers:

  1. "It is prohibited to use prolog in statements of the trigger action" — Sedna Programmer's Guide, XQuery Triggers.

  2. See also bug 51 (although, already closed).

这篇关于本机 xml 数据库中的唯一性插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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