Download RELAXML

Transcript
Chapter 4. Design
36
Requirements for Updating
Each included table has a primary key which is fully included in the export.
The values for the primary key are not updated.
To see the need for these requirements one should note that to update the
database from an XML document is different in nature from updating the database by means of SQL. When using SQL, one specifies the tuples to be updated
which means that we know the values to update and the new values. When we,
on the other hand, are updating the database from an XML document we only
know the values after they have been updated. There is no information about
which values have been changed by the user and what these values were before2 . We therefore need a way of uniquely identifying tuples in the database
and in the XML such that we can compare the values and see if updates should
be made to the database. For this we use the primary keys which of course
should not be changed in the XML since we would not be able to identify the
tuples in the database that the data originated from in that case.
It is, however, very easy for the user to update a primary key value in the XML
by accident. It would therefore be convenient to have a uniform way of detecting such illegal updates. But for this the transformations can be used. For
a column that must not be changed, a transformation can add another column
and fill this with a checksum for the value that should not be changed. The inverse transformation should then just verify that the checksum and the value
still correspond to each other, and if not raise an exception. For this purpose,
the class ChecksumTransformation can be used. All the user has to do is
to register which columns checksums should be computed for. Notice that R E LA XML cannot automatically detect for which columns checksums should be
added, since the set of columns that hold data from primary keys may not be
identical for the derived table and the transformed derived table.
4.4.2 Avoiding Inconsistent Updates
When the data in an XML document has been edited by the user, we can risk
that the user has made an inconsistent update. An inconsistent update can happen when a value that originates from one place in the database is added many
times to the XML document. If not all occurrences of the value are left untouched or updated to the same value, we have an inconsistent update. In this
section, we describe how to detect if an inconsistent update has taken place.
When the user is editing the XML, he is indirectly making updates to the transformed derived table. But since the derived table in the general case might be
in 1NF, both the derived table and the transformed derived table can contain
redundant data. This is easily seen in the example below.
Example 4.2
Consider the following two tables where we ignore types.
2 Other techniques like MS SQL Server’s Updategrams use another approach than R ELA XML
and store the mentioned informations in the edited XML [MSDb].