uniqness insertion in native xml database

112 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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).