查询在 Workbench 中有效,但在 ColdFusion 中返回错误
我创建了一个用于从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该问题是由“当作为查询运行时,这将返回正确的值”这一行引起的
,但是当这些值作为存储过程从 ColdFusion 传入时,结果为 -1(从查询中找不到任何行)。
我主要处理 MS SQL,但我相信在 MySQL 中 @ 符号定义了本地或会话变量。因此,当从 ColdFusion 调用时,该变量不存在,从而导致错误。
我将上面的行替换为
并调用存储过程返回了正确的结果。
The issue was caused in the line
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
and calling the stored procedure returned the correct result.