UniSQLMonitor Event OnSql - Param Text

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
rrcanalista
Posts: 12
Joined: Mon 06 Feb 2012 20:53

UniSQLMonitor Event OnSql - Param Text

Post by rrcanalista » Mon 06 Feb 2012 21:02

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

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Tue 07 Feb 2012 09:22

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;

Post Reply