[
Lists Home |
Date Index |
Thread Index
]
Your database may support a way (or allow you to implement a way) to ask it
for one or several keys before inserting the documents, rather than using
auto-incrementing keys provided by the DB itself. Oracle, for example, has
a concept of a sequence from which you can ask for the next N items. You
can use these as keys (possibly concatenated with some fixed string) on some
table, by associating a sequence with each table for which keys are needed.
You could implement this yourself by having a table of
maximum-key-value-so-far per table:
TableName MaxKey
------------------------
Foo 99
Bar 1766
...
and you execute a transaction something like
select MaxKey from keytable where TableName='Foo'
update keytable set MaxKey=MaxKey+100 where TableName='Foo'
Now you have 100 keys to use starting from whatever was returned from the
select. They are guaranteed not to conflict with keys obtained this way in
any other transaction.
Jeff
----- Original Message -----
From: "Markus Seibold" <Markus.Seibold@gmx.net>
To: <xml-dev@lists.xml.org>
Sent: Thursday, February 12, 2004 11:29 AM
Subject: [xml-dev] database primary keys in XML Schema
> Hello everybody,
>
> I am developing a XML Schema which should function as an interface to a
> relational database.
> I have problems with how to design the primary keys in XML Schema.
>
> 1.) When I insert data via XML instance documents the first time, I cannot
> specify a primary key in my XML instance document because the database
> automatically creates an auto-increment key. Correct?
>
> 2.) What if I, for example, want to insert a city in a geography database
> (the database has a Country and a City table; 1:n relationship). When
inserting
> a city, how can I specify to which country the city belongs? I needed to
> know the database primary key for the country, wouldn't I and add this key
as an
> attribute to the city in my instance document?
> What other solutions do exist?
>
> This issue cost me alot of time so far and I would really appreciate any
> help!
>
> Thanks a lot, Markus
>
>
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
>
> The list archives are at http://lists.xml.org/archives/xml-dev/
>
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>
>
>
|