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...
post or apply updates?
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.
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: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.
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?
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.
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.
This example is correct for CachedUpdates mode (myqry.CachedUpdates = True) except the following line:kaffeburk wrote:Now it will work?
Code: Select all
myconnection.starttransaction;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;