specifying cached updates properties at runtime



Hello,

I'm having difficulties specifying cached updates properties at run
time (using cached updates because of the Delphi edition I have). When
looking at SQL monitor, I see the SQL coming through okay but I think
the problem comes from the parameters -- because something might be
missing on the Delphi end the database doesn't know what the ":TYPE" in
"update t_test set TYPE = :TYPE" is.

At any rate, here's the code I have so far:

procedure TForm1.refreshButtonClick(Sender: TObject);
begin
with Query1 do
begin
Close;
UnPrepare;
SQL.Clear;
DatabaseName := 'dbtest';
SQL.Add('SELECT TYPE, STATUS, NAME FROM T_TEST ORDER BY NAME');
Prepare;
Open;
end;

UpdateSQL1.ModifySQL.AddStrings(Query1.SQL);
UpdateSQL1.InsertSQL.AddStrings(Query1.SQL);
UpdateSQL1.DeleteSQL.AddStrings(Query1.SQL);

UpdateSQL1.ModifySQL.Strings[0] :=
('update t_test'
+ ' set'
+ ' TYPE = :TYPE,'
+ ' STATUS = :STATUS'
+ ' where'
+ ' NAME = :OLD_NAME');

UpdateSQL1.InsertSQL.Strings[0] :=
('insert into t_test'
+ ' (TYPE, STATUS, NAME)'
+ ' values'
+ ' (:TYPE, :STATUS, :NAME)');

UpdateSQL1.DeleteSQL.Strings[0] :=
('delete from t_test'
+ ' where'
+ ' TYPE = :OLD_TYPE');
end;

procedure TForm1.okButtonClick(Sender: TObject);
begin
Database1.Commit;
Database1.StartTransaction;
end;

procedure TForm1.applyButtonClick(Sender: TObject);
begin
Query1.ApplyUpdates;
end;

procedure TForm1.cancelButtonClick(Sender: TObject);
begin
Database1.Rollback;
Database1.StartTransaction;
end;

The form has a DB Grid on it. When I make a change inside the grid and
press the Apply button, (the SQL appears to be properly formatted via
the monitor) I get a generic DB error.

Is it possible to do what I'm trying to do -- set cached updates
properties at run time? If so, suggestions as to where I'm going wrong
are greatly appreciated.

Thanks!

.


Quantcast