Re: Non-skipping IDs with Master-Detail



Hi,

Michelle Brennan wrote:

>
>
> That is why I want to begin a transaction only when the user
> saves the order, at the last moment:

i have to agree with Brian here. I don't know how your order form is
built, but personally i think it's OK if you give the user the
possibility to cancel an order only while he/she is still typing in the
values. I would never allow the user to interrupt a transaction unless
i'm sure it won't create me any problem. You know Murphy...<g>

An alternative approach could be to add a boolean-type column like
CANCELLED and set it to true if the user cancels the order while the
database is saving it. This way, you wouldn't need to control it, the
user could see orders that were cancelled while processing(thus having
more info in case some in-house, not app-related procedure failed)

Said this, let's see if i can help you

>
> *** OnButtonSaveClick
>
> connection.BeginTrans;
>
> try
> datasetOrderID.Value := GetNextKey();
> datasetOrder.Post
> datasetItems.Post
> except
> connection.RollbackTrans;
> raise;
> end;
>
> datasetOrder.UpdateBatch();
> datasetItems.UpdateBatch();
>
> connection.CommitTrans;
>
> But as I stated, the problem here is that the master key is
> only set when the user saves the order, right before
> UpdateBatch. This causes problems with master-detail link
> because the master key is unknown to the detail table.
>
> But, if I call GetNextKey() before, for example OnNewRecord,
> the key skips when user aborts the order.
>

might be wrong, as SQL Server is a RDDBMS i haven't worked with but,
did you try following work-around?

you could create a procedure named SetNextKey, which should be used
*only* in case a user aborts an order while it is being stored. This
procedure would store somehow the value you preassigned.

OTOH, GetNextKey should be changed so that it checks if the next key
should be generated as normal or recovered from wherever SetNextKey
stored the last value.


I hope this helps you. Still, i would really think about my first
suggestion and what Brian posted
--
Best regards :)

Guillem Vicens
Dep. Informática Green Service S.A.
www.clubgreenoasis.com
--
in order to contact me remove the -nospam

.


Quantcast