此过程在远程和本地主机上都可以从 MySQL 命令行运行,并且在从 PHP 调用时也可以运行。在所有情况下,补助金都是足够的:
CREATE PROCEDURE `myDB`.`lee_expout` (IN e int, IN g int)
BEGIN
select lm.groupname, lee.location, starttime, dark,
inadist,smldist,lardist,emptydur,inadur,smldur,lardur,emptyct,entct,inact,smlct,larct
from lee join leegroup_map lm using (location)
where exp_id= e and std_interval!=0 and groupset_id= g
order by starttime,groupname,location;
END
我试图从 R 调用它:
library(DBI)
library(RMySQL)
db <- dbConnect(MySQL(), user="user", password="pswd",
dbname="myDB", host="the.host.com")
#args to pass to the procedure
exp_id<-16
group_id<-2
#the procedure call
p <- paste('CALL lee_expout(', exp_id, ',', group_id,')', sep= ' ')
#the bare query
q <- paste('select lm.groupname, lee.location, starttime, dark,
inadist,smldist,lardist,emptydur,inadur,smldur,lardur,emptyct,entct,inact,smlct,larct
from lee join leegroup_map lm using (location)
where exp_id=',
exp_id,
' and std_interval!=0 and groupset_id=',
group_id,
'order by starttime,groupname,location', sep=' ')
rs_p <- dbSendQuery(db, statement=p) #run procedure and fail
p_data<-fetch(rs_p,n=30)
rs_q <- dbSendQuery(db, statement=q) #or comment out p, run query and succeed
q_data<-fetch(rs_q,n=30)
裸查询运行良好。过程调用失败
RApache 警告/错误!!!mysqlExecStatement(conn, statement, ...) 中的错误:RS-DBI 驱动程序:(无法运行语句:PROCEDURE myDB.lee_expout 无法在给定上下文中返回结果集)
MySQL文档说
对于只能在运行时确定返回结果集的语句,PROCEDURE %s can't return a result set in the given context 发生错误。
人们会认为,如果一个程序要抛出那个错误,它会在所有情况下抛出,而不仅仅是从 R 中抛出。
关于如何解决这个问题的任何想法?