Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I'm so glad I found this site... Now I can get some sleep, because my problem is solved..."

Geography

Where in the world do Tek-Tips members come from?
rea123 (Programmer)
19 Jul 02 10:03
Hi all,
 
I am writing a (C++) COM+ application, with a view to supporting a wide range of different databases.  I am implementing my persistence code using ODBC.  However, I am having trouble with transaction isolation.  The scenario is something like this.  I have a class, MyClass, containing a method, MyMethod, which should run in a distributed transaction.  The method looks something like this:
 
CMyClass::MyMethod(BSTR key)
{
    struct StateInfo state;
    GetState(key, &state);    // SELECT * FROM StateTable WHERE Key = key
    
    // Perform logic, updating contents of state
 
    SaveState(key, state);    // UPDATE StateTable SET ... WHERE Key = key
}

 
Here "key" is some unique identifier for an object's state.  The trouble is that (due to the object-per-client model), a second object could call MyMethod for the same logical object (same key), between GetState and SaveState, thereby losing the update made by the first call.  Clearly I need to lock the row in question.  What is the best way to do this?  Ideally, I would like to do so in a database independant way.
 
All the best,
 
Bob.
AlessandroR (Programmer)
23 Jul 02 3:10
There no way to lock a table row that is dbms independant, except UPDATE.
I think the only way is:
UPDATE TableName
SET Key = Key
WHERE Key = 'XYZ'

SELECT FROM TableName WHERE Key = 'XYZ';

UPDATE ...

This works in every DBMS, the only constraint you must have is that the method is inside a transaction and not in AUTOCOMMIT mode.
Regards
Alessandro

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close