我已经创建了一个存储过程,用于从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>
答案 0 :(得分: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;
并调用存储过程返回了正确的结果。