Page 1 of 1

Parsed SQL with Replaced Params and Macros

Posted: Tue 28 Aug 2012 08:15
by dschuch
Hy, im looking for how to get the fully Parsed - FinalSQL with replaced Params.

FinalSql still has the non-Replaced Params.

Code: Select all

SELECT * FROM table WHERE x=:param.
:param='X';
I want to get it like this:

Code: Select all

SELECT * FROM table WHERE x='X';

Re: Parsed SQL with Replaced Params and Macros

Posted: Tue 28 Aug 2012 09:02
by AlexP
Hello,

To retrieve "clean" SQL, you should handle parameters in the cycle yourself and change their names in the SQL with values, for example:

Code: Select all

function GetFinalSQL(DataSet: TCustomDADataSet): string;
var
  i: integer;
begin
  result := '';
  if not Assigned(DataSet) then exit;
  Result:= DataSet.FinalSQL;
  for i := 0 to DataSet.ParamCount -1 do
    if DataSet.Params.IsNull then
      Result:= StringReplace(Result,':'+DataSet.Params.Name, 'Null', [rfReplaceAll])
    else
      Result:= StringReplace(Result,':'+DataSet.Params.Name, DataSet.Params.Value, [rfReplaceAll])
end;