0

There is some kind of pre-processment of the SQL text on FireDAC queries that truncates their string literals containing ! characters.

It's very easy to replicate:

Place a TFDConnection, a TFDQuery connected to the connection, a TDatasource connected to the query and a TDBEdit connected to the datasource.

After setting my server configuration on the TFDConnection, if I try this SQL on the TFDQuery : Select 'Hel!o World' as column, I would only see He on the TDBEdit instead of Hel!o World.

It's a problem of FireDAC because the same query runs fine directly on SQL Server Management Studio.

Is there a way to fix o disable this pre-processment of FireDAC ?.

It's Delphi 10.4 and SQL Server 2017 accessed by SQL Server Native Client (I have also tried the same query on Delphi 10.3 and returns the same error).

Thank you.

Marc Guillot
  • 6,090
  • 1
  • 15
  • 42
  • 2
    Did you see https://stackoverflow.com/questions/59812774/delphi-firedac-scripts-and-exclamation-mark ? – Andreas Rejbrand Sep 21 '20 at 16:44
  • @AndreasRejbrand . No, I hadn't seen that answer. Thank you. But I have tried disabling ResourceOptions.MacroExpand and those literals still get truncated. – Marc Guillot Sep 21 '20 at 16:52
  • 2
    See the section `Special Character Processing` in [this Emba help page](http://docwiki.embarcadero.com/RADStudio/Sydney/en/Preprocessing_Command_Text_(FireDAC)). The first line mentions the exclamation mark. – MartynA Sep 21 '20 at 16:53
  • @AndreasRejbrand I don't know what I did wrong, but on a second try disabling the MacroExpand property runs like a charm. Thank youl – Marc Guillot Sep 21 '20 at 20:47
  • 2
    Anyway, don't forget to always use parameters to put string values in queries. This doesn't apply to such a table-less SELECT, but it solves most of similar problems, and is both safer (avoid SQL injection) and faster (allow to reuse prepared statements). – Arnaud Bouchez Sep 22 '20 at 07:50

0 Answers0