0

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

我已经检查了驱动程序是否设置为 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>
4

1 回答 1

0

问题是在线路中引起的

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;

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

于 2011-06-24T01:29:49.070 回答