delphi - Delphi 10 西雅图中的 FDQuery 参数

标签 delphi ms-access ms-access-2010 delphi-10-seattle firedac

我有这个查询:

SELECT * FROM Vente WHERE 
(DatePart ("d", Vente.DateDebut)=01) and
(DatePart ("m", Vente.DateDebut)=06) and
(DatePart ("yyyy", Vente.DateDebut)=2017);

此查询在 MS Access 2010 中工作正常,但是当我尝试从 TFDQuery 组件执行它时,它给了我一个错误:

[FireDAC][Phys][ODBC][Microsoft][Pilote ODBC Microsoft Access] Too few parameters. 3 Expected ...

有什么问题吗?我该如何解决这个问题?

更新:

这似乎是 DatePart () 函数中的问题,因为我也尝试了这个:

SELECT DatePart ("d", Vente.DateDebut) FROM Vente

它给了我同样的错误,只是“3 Expected ...”变成了“1 Expected ...”。

最佳答案

我最好的猜测是,驱动程序拒绝您的查询,因为您使用了 "(引号)字符串转义。例如 FireDAC MS Access 元数据类在内部使用 '(撇号)来转义字符串值。如果我是对的,您将很难在 FireDAC 应用程序以及 MS Access 中使用可执行的字符串常量编写 SQL 查询,因为对于 FireDAC 您将编写如下查询(撇号必须在 Delphi 代码中转义):

SELECT DatePart(''d'', Vente.DateDebut) FROM Vente

这是 MS Access 无法理解的。它需要引号,而这对于 FireDAC 来说是 Not Acceptable :

SELECT DatePart("d", Vente.DateDebut) FROM Vente

我不知道有什么方法可以让您为 FireDAC 和 MS Access 编写带有字符串常量的命令。 这应该适用于 FireDAC(不适用于 MS Access):

SELECT * FROM Vente WHERE
({EXTRACT(DAY, Vente.DateDebut)} = :Day) AND
({EXTRACT(MONTH, Vente.DateDebut)} = :Month) AND
({EXTRACT(YEAR, Vente.DateDebut)} = :Year)

在对 MS Access 进行预处理后,它应该生成如下命令(注意撇号):

SELECT * FROM Vente WHERE
(DATEPART('d', Vente.DateDebut) = :Day) AND
(DATEPART('m', Vente.DateDebut) = :Month) AND
(DATEPART('yyyy', Vente.DateDebut) = :Year)

关于delphi - Delphi 10 西雅图中的 FDQuery 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44847507/

相关文章:

delphi - Delphi var参数的数据类型转换

delphi - 如何创建带有在设计时接受其他控件的子面板的自定义控件?

delphi - 是否可以使用 DWScript 创建读取-评估-打印循环 (REPL)?

out-of-memory - 访问时出现内存不足错误

德尔福: how to disable TWebBrowser security certificate alert?

ms-access - 查询表达式中存在语法错误(缺少运算符)?

ms-access - VBA CreateObject ("MSXML2.DOMDocument60") 引发错误 429

excel - 如何在 Recordset 中使用变量!

sql - OleDbDataReader 说它正在读取的表中没有数据 (VB.NET)

excel - 访问 : Sheet. 中的 VBA 删除方法在 For Next 循环中不起作用