2

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.

Jens Erat
  • 37,523
  • 16
  • 80
  • 96
scass
  • 35
  • 9
  • 1
    How is XSD schema imported into your XQuery or database? I thought that the Sedna is not schema-aware. – ruvim Dec 14 '16 at 14:56
  • I loaded the file as follow: from cmd : " se_term -file load_data.xquery mydatabase" and this file contains: CREATE COLLECTION "mycol"& LOAD "1t.xml" "1" "mycol"& LOAD "2.xml" "2" "mycol"& LOAD "1.xsd" "1schem" "mycol"& LOAD "2.xsd" "2schem" "mycol"& – scass Dec 15 '16 at 07:28
  • 1
    Dear Jens, you are right it is not schema aware and I have to implement unique index using triggers, but I don't know how to do that if you have any idea,would you help me please. till now I am learning how to write xQuery trigger before insert and I have to run this query in Sedna (I use Sedna .net driver), then how I can insert a node and check its sub-node value uniqueness?? – scass Dec 15 '16 at 09:14
  • Could you please [update](https://stackoverflow.com/posts/41141317/edit) your question? – ruvim Dec 16 '16 at 10:24

1 Answers1

2

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

ruvim
  • 7,151
  • 2
  • 27
  • 36