Parsed SQL with Replaced Params and Macros

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
dschuch
Posts: 75
Joined: Thu 05 Feb 2009 15:29
Location: Dresden

Parsed SQL with Replaced Params and Macros

Post by dschuch » Tue 28 Aug 2012 08:15

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';

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

Re: Parsed SQL with Replaced Params and Macros

Post by AlexP » Tue 28 Aug 2012 09:02

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;

Post Reply