Solved

Log the Sql of TAdoQuery

Posted on 2007-04-02
5
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

615 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