If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Transactions and BDE a nightmare!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-12-05, 10:21
JvnSparky JvnSparky is offline
Registered User
 
Join Date: Feb 2005
Posts: 1
Unhappy Transactions and BDE a nightmare!

Hi

Here is the code I have currently. It is just a test program where I attempt to get the most basic transaction working:

Query1.CachedUpdates := True;
Database1.StartTransaction;
{ the test table has a code (pk), client_id, description, amount fields }
try
{ take 100 rand from bob }
tmp := 'insert into trans.db values (501, 100, "give2yoda", -100)';
Query1.SQL.Clear;
Query1.SQL.Add(tmp);
Query1.ExecSQL;

{ sometimes I kill the application at this point - for testing }
MessageDlg('Ok, kill me now if you want...', mtInformation, [mbOk], 0);
{ .... }

{ now give to yoda }
tmp := 'insert into trans.db values (502, 500, "frombob", 100)';
Query1.SQL.Clear;
Query1.SQL.Add(tmp);
Query1.ExecSQL;

if Query1.UpdatesPending then
begin { this block never gets executed, why????? }
MessageDlg('Updates pending', mtInformation, [mbOk], 0);
Query1.ApplyUpdates;
Database1.Commit;
Query1.CommitUpdates;
end
else
MessageDlg('NO updated pending', mtInformation, [mbOk], 0);
except
Database1.Rollback;
end;

As I understand, the "Query1.CachedUpdates" is suppose to keep the inserts
in a buffer, until " Query1.ApplyUpdates" actually writes it and
"Database1.Commit" commits the changes. For some unkown reason, however, I
keep on getting the message "No updates pending...". Furthermore, if I kill
the application at the point indicated in the program, the one transaction
is actually present in the table, and according to me, it shouldn't be
there. Isn't it suppose to be all or nothing??

Please help!!

Regards
Reply With Quote
  #2 (permalink)  
Old 02-22-05, 03:18
firasarramli firasarramli is offline
Registered User
 
Join Date: Oct 2003
Location: Jordan
Posts: 28
Smile

Hi

Try to do like this

Query1.CachedUpdates := True;
Database1.StartTransaction;
.
.
.
.
if Query1.UpdatesPending then
Try
Query1.CommitUpdates;
Except
End

Try
Database1.Commit;
Except
Database1.Rollback;
end;
__________________
Firas arramli
Systems Analyst
Reply With Quote
  #3 (permalink)  
Old 02-23-05, 10:52
afx2029 afx2029 is offline
Registered User
 
Join Date: Oct 2003
Posts: 84
Cached updates are for when you actually use a query like
SELECT * FROM Whatever;

Assign a TUpdateSQL object to the TQuery's UpdateObject property, set CachedUpdates to TRUE, and open your dataset.

Perform all your modifications using TQuery.Edit, TQuery.Insert, TQuery.Append....and set all the relevant field values. This is where CachedUpdates does its magic, if you call the Post method, the changes aren't applied to the underlying DB. At this point (after making at least one modification and calling Post (or moving to another record, which automatically cals Post), UpdatesPending will be TRUE.

After you're done making changes you can call
ApplyUpdates (which makes the changes to the underlying database) and
CommitUpdates (which empties the cached of modifications, this empties out all the changes that were successfuly applied).

IF you want to implement your DML statement inside a TQuery, you don't need cached updates.

Read up on Cachedupdates in Delphi help files.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On