ExecSQL中的参数AExecDirect有什么作用?

What does the parameter AExecDirect in ExecSQL do?

我正在阅读 class TFDCustomQuery 的文档,我很好奇 function ExecSQL(AExecDirect: Boolean): LongInt; overload;.

中参数 AExecDirect 的含义

文档 (http://docwiki.embarcadero.com/Libraries/Tokyo/en/FireDAC.Comp.Client.TFDCustomQuery.ExecSQL) 没有解释这个参数的作用。

如果将 True 传递给 AExecDirect 参数,FireDAC 将在执行前省略命令准备(以及一些与使用数据库管理系统)。因此,它的目的只是为了在没有显式命令准备的情况下只执行一次的命令。

关于对象的这个 ExecSQL method overload. Calling this one modifies the DirectExecute 选项(通过 AExecDirect 参数值)有一件重要的事情需要注意,这可能不是预期的。

在某些情况下可能会出现问题,当使用传递给 AExecDirect 参数的 True 值调用此方法重载时,期望以后调用另一个 ExecSQL overloads calls will implicitly prepare the command. They won't, as the DirectExecute 选项将被启用。

所以,DirectExecute 选项引用实际上描述了这个参数(因此这个方法重载的这个参数设置了这个选项):

Controls the preparation of SQL statements.

Use the DirectExecute property to specify whether FireDAC should prepare an SQL statement before its execution (False) or execute it directly (True). The default value is False.

This property was introduced at first for MS SQL Server support. The prepared and the direct execution may have different effects, and even the prepared execution may fail. If you will get peculiar errors, then try to set DirectExecute to True.