Page 1 of 1

UniSQLMonitor Event OnSql - Param Text

Posted: Mon 06 Feb 2012 21:02
by rrcanalista
Hello, I'm using UniSQLmonitor to get the SQL statement will send to the database.

I get the text like

update "PESSOA" set
"PESS_NOME" = :1
where
"PESS_ID" = :2
:1(String[9],IN)='CUSTOMER1'
:2(Integer,IN)=-1

I'd like to get the SQL compatible to run in the DataBase, like

update "PESSOA" set
"PESS_NOME" = 'CUSTOMER1'
where
"PESS_ID" = -1


is there any way to get the SQL command like this?

Thanks

Posted: Tue 07 Feb 2012 09:22
by AlexP
Hello,

In order to retrieve an SQL with already pasted parameter values, you should write your own parser. The following sample demonstrates one of possible ways to realize such parser:

Code: Select all

procedure TForm1.UniSQLMonitor1SQL(Sender: TObject; Text: String;
  Flag: TDATraceFlag);
var
  i: integer;
  s: string;
begin
  if (Sender is TCustomDADataSet) and  (Text  EmptyStr) then
  begin
    s:= TCustomDADataSet(Sender).FinalSQL;
    for i:= 0 to TCustomDADataSet(Sender).ParamCount -1 do
    begin
      case TCustomDADataSet(Sender).Params.DataType of
          ftInteger, ftFloat: s := StringReplace(s, ':'+TUniQuery(Sender).Params.Name, TUniQuery(Sender).Params.Value, [rfReplaceAll]);
          ftString:s := StringReplace(s, ':'+TUniQuery(Sender).Params.Name, ''''+TUniQuery(Sender).Params.Value+'''', [rfReplaceAll]);
        end;
    end;
    Text := s;
  end;
  showMessage(Text);
end;