Recent

Author Topic: [SOLVED] What does TSQLConnection send to the database?  (Read 670 times)

Slawek

  • New Member
  • *
  • Posts: 43
[SOLVED] What does TSQLConnection send to the database?
« on: June 06, 2023, 07:31:39 pm »
Hi,

A long time ago I used some simple way to see what the final command sent by TSQLConnection to the database looks like (MySQL/MariaDB). But I can't find it.
Does anyone know how to see it?
Now I've tried using a sniffer but so far I'm having trouble with it.
« Last Edit: June 06, 2023, 11:55:02 pm by Slawek »

paweld

  • Hero Member
  • *****
  • Posts: 1268
Re: What does TSQLConnection send to the database?
« Reply #1 on: June 06, 2023, 07:53:55 pm »
Code: Pascal  [Select][+][-]
  1. uses
  2.   eventlog;
  3.  
  4. var
  5.   EventLog1: TEventLog;
  6.   s: String = ' if exists (select 1 from sys.objects where name=''sdfglkoi'') ' + LineEnding + ' drop table sdfglkoi ';
  7.  
  8. procedure TForm1.FormCreate(Sender: TObject);
  9. begin
  10.   EventLog1 := TEventLog.Create(nil);
  11.   EventLog1.LogType := ltFile;
  12.   EventLog1.FileName := 'd:\lazsql.log';
  13.   EventLog1.Active := True;
  14.   conn.LogEvents := [detExecute];
  15.   conn.ExecuteDirect(s);
  16. end;
  17.  
  18. procedure TForm1.FormDestroy(Sender: TObject);
  19. begin
  20.   EventLog1.Free;
  21. end;
  22.  
  23. procedure TForm1.connLog(Sender: TSQLConnection; EventType: TDBEventType; const Msg: String);
  24. begin
  25.   if EventType = detExecute then
  26.     EventLog1.Debug('Execute: ' + Msg);
  27. end;                            
Best regards / Pozdrawiam
paweld

dsiders

  • Hero Member
  • *****
  • Posts: 1282
Re: What does TSQLConnection send to the database?
« Reply #2 on: June 06, 2023, 07:54:59 pm »
Hi,

A long time ago I used some simple way to see what the final command sent by TSQLConnection to the database looks like (MySQL/MariaDB). But I can't find it.
Does anyone know how to see it?
Now I've tried using a sniffer but so far I'm having trouble with it.

The connection has a LogEvents property and an OnLog event handler. Check the FPC demo programs in: packages/fcl-db/examples/logsqldemo.pas
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

Slawek

  • New Member
  • *
  • Posts: 43
Re: What does TSQLConnection send to the database?
« Reply #3 on: June 06, 2023, 11:53:55 pm »
This is what I need. Many thanks paweld and dsiders!  :)

 

TinyPortal © 2005-2018