gpt4 book ai didi

mysql - 仅通过分配查询文本获取 "Arguments are of the wrong type..."异常

转载 作者:可可西里 更新时间:2023-11-01 06:37:32 24 4
gpt4 key购买 nike

我已经下载并安装了 MySQL Connector 5.1 x64,这样我就可以在 Delphi 中使用 MySQL。我可以与 ODBC 建立连接,并从我的 Delphi 环境和 MySQL Workbench 建立连接。

但是,当我在运行时构建查询时,我收到一条错误消息:

Project AAA.exe raised exception class EOleException with message 'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another'. Process stopped. Use Step or Run to continue.

我的代码:

qDates := TADOQuery.Create(Component);
qDates.Connection := FConnection;
qDates.SQL.Text :=
'select ' +
' * ' +
'from ' +
' resulttable ' +
'where ' +
' oid = :oid ' +
' and datedial >= :datebegin and datedial <= :dateend'; // <<-- Exception here

详情:
在我有机会配置参数之前,异常发生在文本分配上。
如果我注释掉 where 子句,赋值就没问题了。
这类似于 Using parameters with ADO Query (mysql/MyConnector)但不同之处在于我一次分配了整个文本,并且在我有机会配置参数之前得到了异常。

令人费解的部分 - 完全相同的代码在我的另一台机器上工作正常,但我无法弄清楚有什么不同。

因此问题 - 在 Delphi 代码和 MySQL 服务器之外是什么导致了上述异常?

最佳答案

这似乎是 MySQL ODBC 提供程序的一个怪癖。

如果在设置 SQL 文本后分配连接,那么它将起作用。原因可以查到here .

qDates := TADOQuery.Create(Component);
// do net yet assign TADOConnection to prevent roundtrip to ODBC provider
qDates.SQL.Text :=
'select ' +
' * ' +
'from ' +
' resulttable ' +
'where ' +
' oid = :oid ' +
' and datedial >= :datebegin and datedial <= :dateend';
qDates.Connection := FConnection;

更新

QC entry解释此问题的确切原因。

简而言之,ADODB 单元,从 RefreshFromOleDB 过程中修补这一行:

      Parameter.Attributes := dwFlags and $FFFFFFF0; { Mask out Input/Output flags }

收件人:

if dwFlags and $FFFFFFF0 <= adParamSigned + adParamNullable + adParamLong then
Parameter.Attributes := dwFlags and $FFFFFFF0; { Mask out Input/Output flags }

关于mysql - 仅通过分配查询文本获取 "Arguments are of the wrong type..."异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31140281/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com