BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Primay Key Allocation in remote client Master/Slave relation

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Multi-Tier)
View previous topic :: View next topic  
Author Message
Geoff Marshall
Guest





PostPosted: Tue Jan 17, 2006 6:38 pm    Post subject: Primay Key Allocation in remote client Master/Slave relation Reply with quote



What is the vogue method of allocating a primary key to a new slave
entry of a master slave relation (or even a new master primary key) in a
remote client that is working off line?

Geoff Marshall
Back to top
Geoff Marshall
Guest





PostPosted: Tue Jan 17, 2006 11:03 pm    Post subject: Re: Primay Key Allocation in remote client Master/Slave rela Reply with quote



Loe,
Thanks for your comments but I'm not convinced, or I don't understand.
Assigning negative values on the client is straight forward, but the
article is confusing in its use of the Delta table. If this is a true
table (as inferred) then two users could easily be adding values to it
at the same time so the lookup would fail.

i.e.
user A has child -1 which equates to proper key 123456
user B has child -1 which equates to proper key 123457
user A has child -2 which equates to proper key 123458
user B has child -2 which equates to proper key 123459
etc.

User A now updates the master which contains foreign key -1. An
interesting situation?

The article offers an alternative which is to obtain proper keys at
update time on the client. I was concerned with this only because it
means scanning the master to insert the proper key once for each child
record that is assigned a proper key. In my case the amount of data on
the client is likely to be small so I may be able to manage this.


Are there any more eloquent solutions?

Geoff Marshall


Back to top
Leif Eirik Olsen
Guest





PostPosted: Wed Jan 18, 2006 12:58 pm    Post subject: Re: Primay Key Allocation in remote client Master/Slave rela Reply with quote



"Geoff Marshall" <ng (AT) nospam (DOT) co.uk> skrev i melding
news:43ce1a64$1 (AT) newsgroups (DOT) borland.com...
Quote:
What is the vogue method of allocating a primary key to a new slave entry
of a master slave relation (or even a new master primary key) in a remote
client that is working off line?

In a master-detail relation (on the client) I assign negative integers to
the primary key, and to the foreign key in the detail data on the client.

When applied to the server I search/replace negative integer with the
desired values.

http://bdn.borland.com/article/0,1410,20847,00.html

The article shows how to deal with autoinc fields using Midas, but I think
it also answares your question.

hth.

regards,
Leo



Back to top
Bill Todd
Guest





PostPosted: Wed Jan 18, 2006 2:31 pm    Post subject: Re: Primay Key Allocation in remote client Master/Slave rela Reply with quote

Delta and Data are properties of the ClientDataSet. They exist only in
local memory and each ClientDataSet has its own private Delta and Data
that is not shared with anyone or anything.

--
Bill Todd (TeamB)
Back to top
Kostas Terzides
Guest





PostPosted: Wed Jan 18, 2006 6:02 pm    Post subject: Re: Primay Key Allocation in remote client Master/Slave rela Reply with quote

Geoff Marshall wrote:
Quote:

Are there any more eloquent solutions?

Geoff Marshall


Just make sure that master and detail are in a nested dataset structure
(server side linkning). This way the delta is common (it is actually a
deltatree) for both the master and the detail dataset and the updating
is wrapped (automatically) in a transaction.

If this is not the case (or if you have to define multiple dataset
relations in client side and deal with primary and foreign key values),
then you might take a look at 2 components I made that simplify the
updating procedure:
http://cc.borland.com/Item.aspx?id=23068

Kostas.

Back to top
Bill Todd
Guest





PostPosted: Wed Jan 18, 2006 7:07 pm    Post subject: Re: Primay Key Allocation in remote client Master/Slave rela Reply with quote


This is very confusing because you have the terminology backwards in
some cases. In a one-to-many relationship the table on the "one" side
is commonly called the parent or master and the table on the "many"
side is commonly called the child or detail table. Therefore, the table
that contains the foreign key is the child or detail table. In your
description the lookup table is the master and the data table is the
detail table. You need to apply the master (lookup) table changes first
so you can get the foreign key value for the detail (data) table
records before you apply them. It would help to know what database you
are using.

--
Bill Todd (TeamB)
Back to top
Geoff Marshall
Guest





PostPosted: Thu Jan 19, 2006 2:58 am    Post subject: Re: Primay Key Allocation in remote client Master/Slave rela Reply with quote

I'm beginning to think I don't understand this solution because it is a
solution to a different though similar problem. And some of the problem
may be the nomenclature.

I have a Master table which contains four Foreign Keys pointing to four
Lookup tables. Consider just one of these lookup tables. If for
example I add five new records to the Master and in doing so I add three
new records to the lookup table (i.e. several master records point to
the same lookup table). I then want to save these to the server.

I apply updates for the lookup table and the records are assigned
"proper" key values by the server. I am assuming that I set
poPropogateChanges true and the Delta part (the visible part) of the
Client Data Set is updated. (I believe this destroys the relation
between the Master Table and the Lookup Tables).

How do I now apply updates to the Master table?

Geoff Marshall

Back to top
Bill Todd
Guest





PostPosted: Thu Jan 19, 2006 3:04 am    Post subject: Re: Primay Key Allocation in remote client Master/Slave rela Reply with quote

Geoff Marshall wrote:

Quote:
The database is Interbase.

One solution with InterBase is to call

SELECT GEN_ID(SOME_GENERATOR, 1) FROM RDB$DATABASE

to get the new key and assign it to the records before you call
ApplyUpdates.

--
Bill Todd (TeamB)

Back to top
Geoff Marshall
Guest





PostPosted: Thu Jan 19, 2006 3:06 am    Post subject: Re: Primay Key Allocation in remote client Master/Slave rela Reply with quote

Kostas,

From the description it looks as if your components are better suited
to what I need. I'll have a look a them tomorrow.

Thanks Geoff

Back to top
Geoff Marshall
Guest





PostPosted: Thu Jan 19, 2006 5:35 am    Post subject: Re: Primay Key Allocation in remote client Master/Slave rela Reply with quote

Bill,

I'm happy with that definition. So then I have four master tables
sharing one detail table. In this design of course the user selects
which master the detail is going to belong to by selection from the
master data set. If their desired master record does not exist then a
new master will be introduces and the detail attached to it.

The database is Interbase.

Geoff
Back to top
Geoff Marshall
Guest





PostPosted: Thu Jan 19, 2006 1:47 pm    Post subject: Re: Primay Key Allocation in remote client Master/Slave rela Reply with quote

Bill,

Thanks, that is the solution I was going to try later today. I really
only wanted to know if there was a better approach.

Geoff
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Multi-Tier) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.