Transactions and CORBA

Posted on 2000-05-18
Last Modified: 2010-04-04
I have corba server which is connected to a database and
I use that database trough the client program.
I can make queries, updates etc. but now I have the
classic update problem.

A gets record:

B gets same record:

After this B updates and the A updates.
B's update is lost. Of course B shouldn't
be able to update, because A got the
record first.

How do I solve this problems in Delphi?
I didn't get any errors when made the
SQL query with A and then update with B

I'm using following strategy:

E.g. Get list of users
1. Call method GetUsers(userlist: TList), which is method of my DBHandler
2. Create SQL query and execute it.
3. Loop trough resul, create TUser objecst
and add them to the userlist.
4. Show the users in some component e.g.
in TListview component.

I tried to use TDataClientSet.ApplyUpdates(0);
and CancelUpdates, but I only get "Unexpeceted
Error" with following code:

name := 'foo';
CorbaConnection1.Connected := True;
sql := 'UPDATE TABLE SET FIRSTNAME = ' + '''' +
nimi + '''' + ' WHERE ID = 1000';
ClientDataSet1.CommandText := sql;
ClientDataSet1.CancelUpdates //unexcepted error here

Execute goes ok, so there is nothing wrong in the SQL.

It seems that I can use CancelUpdates/ApplyUpdates
only if I'm using some database with DBGrid.
Now the Execute command makes all the changes
in the database right away.

I'm using Solid Server as a database server.
Question by:tonitop

Expert Comment

ID: 2820824
hi tonitop,

Yes it's classical update problem. You need to prevent another users to get record for editing if one of them already get it. You need to have additional field to keep information about locks. It may be integer field, let its name be IDL. Normally it contain "0".

1. try mark record as locked
"update thetable set IDL=:id_user where ID=1000 and IDL=0"
nothing happen if another user "lock" it because of IDL<>0 in this case

2. get for editing
"select * from thetable where IDL=:id_user and ID=1000"
if query returns empty result then another user get record for editing

3. if previous action is success then make your changes and "unlock" record
"update thetable set IDL=0 where ID=1000"

It's usual way to mark record as locked in not locks supprted database.


Accepted Solution

lorenk earned 100 total points
ID: 2848183
The answer is a little more complex than what you might think.  First off, I would suggest NOT using the ClientDataSet objects.  These ar ejust not meant for these types of transactions.  I have created many 3-tier apps and never used them.  The appropriate way to do this is to keep the locking within the CORBA object itself.  This of course means that ALL apps that touch the database NEED to go through the CORBA object.  This makes sense though.  So, you keep a log of what apps have which records open and make sure that only the one with the "lock" makes the change stick.   This way, you can also update all clients IMMEDIATELY when the "locked" client makes a change.  And then a different client can get the "lock."

The log I am referring to in my apps is usually a TLIST of objects which contain the ID of the client and the ID of the record they are accessing.

This is the best way to do locking IMHO.  I never like to rely on the DB to do it.


Author Comment

ID: 2848533
Answer accepted

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Internet Explorer View Settings Question 15 116
TServerSocket - file via sendbuf or Text via sendtext ? 1 65
Multiple image collision 13 80
can't find the executable in Simulator 1 100
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question