查询在 Workbench 中有效,但在 ColdFusion 中返回错误

发布于 2024-11-16 16:31:21 字数 1721 浏览 3 评论 0原文

我创建了一个用于从 FreeRADIUS 访问会计数据的存储过程,该过程已在 MySQL Workbench 中进行了测试并且运行良好,但是当作为 cfquery/cfstoredproc 运行时,我收到错误“EXECUTE 参数不正确”。

我已经检查了为 MySQL 4/5 设置的驱动程序(数据库是 MySQL 5),并尝试从 MySQL Workbench 复制并粘贴调用并在不使用 cfqueryparam 的情况下运行,如下所示,但它仍然返回相同的错误。

存储过程是用创建的

DELIMITER $$
CREATE PROCEDURE radius.GetUserDataUsageForMonth(IN StartDate DATE, IN EndDate DATE, IN UserName     
VARCHAR(100))
BEGIN

SET @records = (SELECT COUNT(UserName) FROM `radius`.`radacct` WHERE userName = @UserName AND AcctStartTime BETWEEN @StartDate AND @EndDate) - 1;

SET @SqlQuery = 'SELECT SUM(AcctOutputOctets) AS BytesIN, SUM(AcctInputOctets) AS BytesOUT FROM
        (SELECT * FROM `radius`.`radacct` WHERE userName = @UserName AND AcctStartTime BETWEEN @StartDate AND @EndDate LIMIT ? 

        UNION ALL

        SELECT * FROM `radius`.`radacct` WHERE userName = @UserName AND AcctStartTime < @StartDate ORDER BY AcctStartTime DESC LIMIT 1) AS Totals;';

PREPARE stmt FROM @SqlQuery;
EXECUTE stmt USING @records;
DEALLOCATE PREPARE stmt;
END $$
DELIMITER ;

要调用它,我正在使用:

<cfquery name="qRadAccount_currentData" datasource="#application.datasource_radius#">
    CALL radius.GetUserDataUsageForMonth('2011-06-01','2011-07-01','ryan.french');
</cfquery>

我也尝试过

<cfstoredproc procedure="radius.GetUserDataUsageForMonth" datasource="#application.datasource_radius#" result="qRadAccount_currentData">
    <cfprocparam cfsqltype="cf_sql_date" value="2011-06-01">
    <cfprocparam cfsqltype="cf_sql_date" value="2011-07-01">
    <cfprocparam cfsqltype="cf_sql_varchar" value="ryan.french">
</cfstoredproc>

I've created a stored procedure for accessing accounting data from FreeRADIUS, which has been tested in MySQL Workbench and runs fine, but when running as a cfquery/cfstoredproc I get the error 'Incorrect arguments to EXECUTE'.

I have checked the driver is set up for MySQL 4/5 (the database is MySQL 5) and have tried copying and pasting the call from MySQL Workbench and running without using cfqueryparam as shown below but it still returns the same error.

The stored procedure was created with

DELIMITER $
CREATE PROCEDURE radius.GetUserDataUsageForMonth(IN StartDate DATE, IN EndDate DATE, IN UserName     
VARCHAR(100))
BEGIN

SET @records = (SELECT COUNT(UserName) FROM `radius`.`radacct` WHERE userName = @UserName AND AcctStartTime BETWEEN @StartDate AND @EndDate) - 1;

SET @SqlQuery = 'SELECT SUM(AcctOutputOctets) AS BytesIN, SUM(AcctInputOctets) AS BytesOUT FROM
        (SELECT * FROM `radius`.`radacct` WHERE userName = @UserName AND AcctStartTime BETWEEN @StartDate AND @EndDate LIMIT ? 

        UNION ALL

        SELECT * FROM `radius`.`radacct` WHERE userName = @UserName AND AcctStartTime < @StartDate ORDER BY AcctStartTime DESC LIMIT 1) AS Totals;';

PREPARE stmt FROM @SqlQuery;
EXECUTE stmt USING @records;
DEALLOCATE PREPARE stmt;
END $
DELIMITER ;

To call this I am using:

<cfquery name="qRadAccount_currentData" datasource="#application.datasource_radius#">
    CALL radius.GetUserDataUsageForMonth('2011-06-01','2011-07-01','ryan.french');
</cfquery>

I have also tried

<cfstoredproc procedure="radius.GetUserDataUsageForMonth" datasource="#application.datasource_radius#" result="qRadAccount_currentData">
    <cfprocparam cfsqltype="cf_sql_date" value="2011-06-01">
    <cfprocparam cfsqltype="cf_sql_date" value="2011-07-01">
    <cfprocparam cfsqltype="cf_sql_varchar" value="ryan.french">
</cfstoredproc>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

豆芽 2024-11-23 16:31:21

该问题是由“当作为查询运行时,这将返回正确的值”这一行引起的

SET @records = (SELECT COUNT(UserName) FROM `radius`.`radacct` WHERE userName = @UserName AND AcctStartTime BETWEEN @StartDate AND @EndDate) - 1;

,但是当这些值作为存储过程从 ColdFusion 传入时,结果为 -1(从查询中找不到任何行)。

我主要处理 MS SQL,但我相信在 MySQL 中 @ 符号定义了本地或会话变量。因此,当从 ColdFusion 调用时,该变量不存在,从而导致错误。

我将上面的行替换为

SET @records = (SELECT COUNT(UserName) FROM `radius`.`radacct` WHERE userName = UserName AND AcctStartTime BETWEEN StartDate AND EndDate) - 1;

并调用存储过程返回了正确的结果。

The issue was caused in the line

SET @records = (SELECT COUNT(UserName) FROM `radius`.`radacct` WHERE userName = @UserName AND AcctStartTime BETWEEN @StartDate AND @EndDate) - 1;

When run as a query, this would return the correct value, however when the values are passed in as a stored procedure from ColdFusion, the result was -1 (no rows were found from the query).

I mostly deal in MS SQL, but I believe that in MySQL the @ symbol defines a local or session variable. As a result, when calling from ColdFusion the variable did not exist, resulting in the error.

I replaced the line above with

SET @records = (SELECT COUNT(UserName) FROM `radius`.`radacct` WHERE userName = UserName AND AcctStartTime BETWEEN StartDate AND EndDate) - 1;

and calling the stored procedure returned the correct result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文