Unless you want your users to be able to play with the data, don't use a
cached update at all. Instead create a TQuery object, load it with SQL
usnig Parameters for every collumn
and prepare it.
then start a transaction
Then inside a try Except loop
fire off as many inserts as you like, loading the tquery parameters and
doing ExecSQL
just before the Except do a commit.
handle any exceptions by doing a rollback, and re raising the exception
Dont forget to unprepare the TQuery, and also to Free the TQuery.
The above method is ver usefull where you want to load a large number of
records such as might happen while walking down another TQuery, or
walking an Ascii File.
If you want the users to play with the data and must use a Cached
Update, then you just treat the TQuery as if it wasn't cached (ie do
edit, inserts posts etc) then last thing before you close the form,
apply updates. You MUST post before applying updates.
You are better off to learn using a TClientDataset than a cached update.
A little more work, but much more rewarding.
If you use the Select back/Insert method you have depicted, then this is
many times slower than the technique I sugest to you, but is OK for
small numbers of inserts.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Paul Lowman
Sent: Friday, 16 April 1999 17:44
To: Multiple recipients of list delphi
Subject: [DUG]: TQuery, TUpdateSQL and Insert
Hi All
Anyone tell me how to use a TQuery with an update component to insert a
new record.
I have managed to do it so far in the following way :
with dmGlobal.qryWindLog do
begin
Close;
SQL.Clear;
SQL.Add('select * from WINDDATA.DB');
SQL.Add('where RTU_ID = 16000');
Open;
Insert;
FieldValues['RTU_ID'] := Self.ID;
FieldValues['LogTime'] := Self.LastPoll;
FieldValues['Direction'] := Self.WindDir;
FieldValues['Average'] := Self.WindSpdAv;
FieldValues['Peak'] := Self.WindSpdGust;
ApplyUpdates;
end;
OK - But I don't think that I should have to execute the TQuery first -
If I set the SQL strings to empty then I throw an exception so whats the
recommended way ?? I put the RTU_ID = 16000 so no records would be
returned but its a kluge ...
I use this same setup (basically but no setting field for delete) to
edit and delete records but use <edit> or <delete> instead of <insert>.
This seems to make sense if modifying an existing record but not for
insert or delete. By the by - I found that if I do an edit on a non
existent record then a new record is inserted - is this right ??
Paul Lowman
software/hardware developer
Lowman Consulting
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz