Einzelnen Beitrag anzeigen

Delphi.Narium

Registriert seit: 27. Nov 2017
2.419 Beiträge
 
Delphi 7 Professional
 
#6

AW: SQL Statement mit Parametern mit den eigentlichen Werten anzeigen

  Alt 28. Jun 2020, 17:33
Ist das hier beschriebene nicht einfacher?

http://docwiki.embarcadero.com/Libra...stomQuery.Text

Zitat von FireDAC.Comp.Client.TFDCustomQuery.Text:

Up to Parent: TFDCustomQuery

Delphi

property Text: String read GetText;

C++

__property System::UnicodeString Text = {read=GetText};

Properties
Type Visibility Source Unit Parent
property public
FireDAC.Comp.Client.pas
FireDAC.Comp.Client.hpp
FireDAC.Comp.Client TFDCustomQuery
Description

Points to the actual text of the SQL query passed to the DBMS CLI.

Text is a read-only property that can be examined to determine the actual contents of the SQL statement passed to the DBMS. For parameterized queries, Text contains the SQL statement with parameters replaced by the parameter substitution symbol (? or another symbol) instead of actual parameter values, substituted macro values, and processed escape sequences.

In general, there should be no need to examine the Text property. To access or change the SQL statement for the query, use the SQL property. To examine or modify parameters, use the Params property.

To check what FireDAC sends to the DBMS, consider to use FireDAC monitoring.
Wenn ich das recht verstehe, enthält das Attribut Text von FDQry, also hier konkret FDQry.Text (und nicht FDQry.SQL.Text) den Inhalt der Abfrage, nach dem Auflösen der Parameter im SQL durch die entsprechenden Parameterwerte. Sprich das, was konkret an die Datenbank geschickt wird.

Es dürfte demnach das Gewünschte "von Haus aus" bereits zur Laufzeit im Programm zur Verfügung stehen, ohne irgendwelche weiteren Hilfsmittel.

Quasi sowas:
Delphi-Quellcode:
FDQry.SQL.Text := 'insert into tabelle (id, wert) values (:id, :wert);
FDQry.ParamByName(
'ID').AsInteger := 1;
FDQry.ParamByName(
'Wert').AsString := 'irgend eine Zeichenfolge';
FDQry.Prepare;
if MessageDLG(
'Ist das Statement ' +#13#13 + FDQry.Text + #13 'so korrekt?',mtConfirmation,[mbYes,mbNo],0) = mrYes then FDQry.ExecSQL;
Nur hingedaddelt ohne jegliche Testmöglichkeit
Zumindest suggeriert die Hilfe, dass das in etwa so funktionieren könnte.
  Mit Zitat antworten Zitat