Solved

Transactions and CORBA

Posted on 2000-05-18
3
231 Views
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:
'SELECT FIRSTNAME FROM TABLE WHERE ID = 1000'

B gets same record:
'SELECT FIRSTNAME FROM TABLE WHERE ID = 1000'

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
class.
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;
ClientDataSet1.Close;
sql := 'UPDATE TABLE SET FIRSTNAME = ' + '''' +
nimi + '''' + ' WHERE ID = 1000';
ClientDataSet1.CommandText := sql;
ClientDataSet1.Execute;
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.
0
Comment
Question by:tonitop
3 Comments
 
LVL 9

Expert Comment

by:ITugay
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.

----
Igor.
0
 

Accepted Solution

by:
lorenk earned 100 total points
ID: 2848183
ToniTop,
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.

Loren
0
 

Author Comment

by:tonitop
ID: 2848533
Answer accepted
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 100
Working this component WebCopy with proxy, help 3 84
Correct Component for Shopping Cart. 2 105
Multiple image collision 13 74
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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