Solved

Log the Sql of TAdoQuery

Posted on 2007-04-02
5
238 Views
Last Modified: 2010-04-05
Hi there :-)

I got a TAdoQuery and I want to log the sql statement's that it process's.
However I also work with paramaters, like
SELECT * FROM this WHERE that=:S1

So is there a way to get the fully formed sql statement? And not just
SELECT * FROM this WHERE that=:S1
0
Comment
Question by:wildzero
  • 3
  • 2
5 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 18838932
if you want to log your sql statements simplest way is any time you
call ADOQuery.SQL.Add(sql_stat) add sql_stat also to some stringlist
then you can save your stringlist to file or dump to clipboard or anythink you want.
saving params might be possible (not tested) in this way
ADOQuery.SQL.Add(sql_stat)
mystringlist.add(ADOQuery.SQL.Text)
but there's little trick for example if param is blob you might have problems
with saving param value.

ziolko.
0
 
LVL 10

Author Comment

by:wildzero
ID: 18839085
Probly have to write my own function then to get the params.....

saving the
SELECT * FROM this WHERE that=:S1
isn't a problem - thats easy to log.
But when I do log it, I want the params included....

0
 
LVL 21

Accepted Solution

by:
ziolko earned 125 total points
ID: 18839153
you can loop thru Params collection read values, convert them to string and then use StringReplace() on sql command

not tested sample:
procedure TForm1.Button1Click(Sender: TObject);
var prm: string;
    sql: string;
    sql_noparams: string;
begin
  ADOQuery1.SQL.Add(sql);
  sql_noparams := sql;
  for cnt := 0 to ADOQuery1.Parameters.Count - 1 do begin
    prm := VarToStr(ADOQuery1.Parameters[cnt].Value);
    sql_noparams := StringReplace(sql_noparams, ADOQuery1.Parameters[cnt].Name, prm, [rfReplaceAll, rfIgnoreCase]);
  end;
end;


ziolko.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 18839191
of course (missed ':'):

sql_noparams := StringReplace(sql_noparams, ':' + ADOQuery1.Parameters[cnt].Name, prm, [rfReplaceAll, rfIgnoreCase]);

ziolko.
0
 
LVL 10

Author Comment

by:wildzero
ID: 18839740
Yea that might be the way to do it...
Will stick that in and see how it runs.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IExtractImage Delphi 14 202
ddeman not working in activex 3 93
Mydac connection data base issue 3 139
delphi parse string to params 3 99
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now