delphi firedac 特殊字符& 如何存入数据库?

参数化脚本可以解决

但是很多情况下 参数化是没直接脚本方便,测试  可以用 & 转义 & 但到数据库后 会出现 两个&,所以这是临时解决方法

在官网找到了:

FireDAC
ContentsIndexHome
PreviousUpNext
TADResourceOptions.MacroCreate Property

Controls automatic filling of Macros collection.

Group
Links

Use MacroCreate property to control automatic filling of Macros collection. If it is True, SQL preprocessor scans SQL command text for '!' or '&' symbols, extracts macro names and puts them into Macros collection. The scanning will be performed at each command text change. The default value is True. 

Setting MacroCreate to False, may be usefull, if:

  • target DBMS uses '!', '&' symbols in its own SQL dialect and FireDAC cannot recognize them as a SQL construction. Then SQL commands with these symbols may confuse FireDAC SQL preprocessor. See Preprocessing Command Text for macros description.
  • application fills Macros collection "by hands".
  • application does not use macros at all.

Setting PreprocessCmdText to False, sets MacroCreate to False.

google 翻译:

firedac  

使用MacroCreate属性可以控制Macros集合的自动填充。如果为True,则SQL预处理程序将在SQL命令文本中扫描“!”。或“&”符号,提取宏名称并将其放入“宏”集合中。将在每次命令文本更改时执行扫描。默认值是true。

在以下情况下,将MacroCreate设置为False可能会有用:

目标DBMS在其自己的SQL方言中使用“!”,“&”符号,并且FireDAC无法将其识别为SQL构造。然后,带有这些符号的SQL命令可能会使FireDAC SQL预处理器混乱。有关宏的描述,请参见预处理命令文本。
应用程序“手动”填充Macros集合。
应用程序根本不使用宏。
将PreprocessCmdText设置为False,将MacroCreate设置为False。

http://docs.embarcadero.com/products/rad_studio/firedac/frames.html?frmname=topic&frmfile=uADStanOption_TADResourceOptions_MacroCreate.html

原文地址:https://www.cnblogs.com/iwana/p/13185910.html