Page 1 of 1

post or apply updates?

Posted: Fri 13 Apr 2007 08:31
by kaffeburk
What is the right way to manually without any visual components write and read from the db? I cant find any exampels anywhere. Should post; be used or applyupdates or are they same thing? And how to write with cashed updates and transactions?

The exampels in the demo dont show how do it, them only let somone who already knows how to do it do it. In what order should these Apply, commit and so be given? Its technicly nice, but dont really show how to do it...

so is this right?

(1) No cashed mode:


with myqry do
begin
Insert;
FieldByName('fname').AsString:='Andy';
Post;
end;

(2) Cashed update (i skip the exeption part)

with myqry do
begin
myconnection.starttransaction;
insert;
FieldByName('fname').AsString:='Andy';
post;
myconnection.commit;
commitupdates;
end;

And thanx for an exelent product, but the dokumentation...

Posted: Fri 13 Apr 2007 10:28
by Antaeus
The first example looks correct. The second does not. Generally working in CachedUpdates mode looks like this:
1) Enable CachedUpdates mode (MyQuery.CachedUpdates := True).
2) Change data (MyQuery.Insert/Append/Post/Delete). Note, the changes are not reflected to database.
3) Post data to database MyQuery.ApplyUpdates. Now all changes made before are in database.

You can perform posting data to database in a transaction using MyConnection.ApplyUpdates instead of MyQuery.ApplyUpdates.

Posted: Sat 14 Apr 2007 07:46
by kaffeburk
Antaeus wrote:The first example looks correct. The second does not. Generally working in CachedUpdates mode looks like this:
1) Enable CachedUpdates mode (MyQuery.CachedUpdates := True).
2) Change data (MyQuery.Insert/Append/Post/Delete). Note, the changes are not reflected to database.
3) Post data to database MyQuery.ApplyUpdates. Now all changes made before are in database.

You can perform posting data to database in a transaction using MyConnection.ApplyUpdates instead of MyQuery.ApplyUpdates.
So:

with myqry do
begin
myconnection.starttransaction;
insert;
FieldByName('fname').AsString:='Andy';
post;
myconnection.ApplyUpdates;
end;

Now it will work?

(thanx for the teoretic stuff - but what i really need is a working example)

Now is it correct?

Posted: Mon 16 Apr 2007 06:13
by kaffeburk
MyConnection1.StartTransaction;
myQry.FieldByName('fname').AsString:='Andy';
MyConnection1.Commit;


I understand that focus for corelabs is existing advanced user. But if u want to increase Your marketshare You should also take a little care of us newbies. Nobody knows hos MYDAC work when they first start off, and if they dont have any collegue who can show them the rops, there is only the documentation and this forum. I searched here a lot, and NOWHERE is any example on how to write an transaction. I can guess and try - and i wont ever know if its right even if it seams to work. I probably spend about 30 hours on this. And then - why somone who can teach me this is 5 second just wont do it seams strange... PLS SOMENE just write this 5-10 rows of code, and perhaps include it in the FAQ.

Posted: Mon 16 Apr 2007 08:08
by Antaeus
kaffeburk wrote:Now it will work?
This example is correct for CachedUpdates mode (myqry.CachedUpdates = True) except the following line:

Code: Select all

myconnection.starttransaction;
You should not start transaction manually. The TMyConnection.ApplyUpdates method opens a transaction, applies updates and commits the transaction itself.

The following code demonstrates how to work with transactions(myqry.CachedUpdates = False):

Code: Select all

  MyConnection.StartTransaction;
  try
    MyQuery1.Insert;
    //assign fields of MyQuery1
    MyQuery1.Post;
    MyQuery2.Insert;
    //assign fields of MyQuery2
    MyQuery2.Post;
    // ...
    MyConnection.Commit;
  except
    MyConnection.Rollback;
    ShowMessage('An error was raised when modifying data or committing transaction. All changes are rolled back');
  end;  

Posted: Tue 17 Apr 2007 11:07
by kaffeburk
Thanx a lot!