Page 1 of 1

Params

Posted: Tue 10 Jun 2014 05:36
by Janex
Hi.
Is there some way to use params in insert/update/delete/refresh/lock queries ?
If I write, for example, in delete statement:
WHERE ID = :BLABLA
the param MYPARAM not displayed in params tab an when I execute this SQL,
I get error: "Not found field corresponding parameter BLABLA".

I'm informed to I can write this SQL via UniQuery.UniUpdateSQL.DeleteObject, but
without UniUpdateSQL.DeleteObject ?

WBR
Janex

Re: Params

Posted: Tue 10 Jun 2014 09:03
by AlexP
Hello,

If you want to use your parameters in INSERT/UPDATE/DELETE queries, which names don't match the field names in the main query, you should set values for these parameters in the BeforeUpdateExecut event:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  UniQuery1.SQL.Text := 'SELECT DEPTNO, DNAME, LOC FROM DEPT';
  UniQuery1.SQLUpdate.Text := 'UPDATE DEPT SET DNAME = :DNAME, LOC = :LOC WHERE DEPTNO = :BLABLA';
  UniQuery1.Open;
  UniQuery1.Edit;
  UniQuery1.FieldByName('DNAME').AsString := 'test';
  UniQuery1.FieldByName('LOC').AsString := 'test';
  UniQuery1.Post;
end;

procedure TForm1.UniQuery1BeforeUpdateExecute(Sender: TDataSet;
  StatementTypes: TStatementTypes; Params: TDAParams);
begin
  Params.ParamByName('BLABLA').AsInteger := 10;
end;