Solved

Log the Sql of TAdoQuery

Posted on 2007-04-02
5
237 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
of course (missed ':'):

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

ziolko.
0
 
LVL 10

Author Comment

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

13 Experts available now in Live!

Get 1:1 Help Now