[英]RMySQL fetch - can't find inherited method
Using RMySQL I want to load data from a database into a dataframe in R. For this I'm using the following code: 我想使用RMySQL将数据库中的数据加载到R中的数据框中。为此,我使用以下代码:
Rconnectdb: Rconnectdb:
con <- dbConnect(MySQL(),
user="root", password="password",
dbname="prediction", host="localhost")
Main code 主要代号
library(RMySQL)
source("Rconnectdb") #load the database connection
query = "select received,isRefound from message" #specify query
rs=dbGetQuery(con,query) #resultset
dataset <- fetch(rs, n=-1) #fill dataset with all rows of the resultset
dbClearResult(rs) #clear resultset
Executing this I get the following error 执行此我得到以下错误
Error in function (classes, fdef, mtable) : unable to find an inherited method for function "fetch", for signature "data.frame", "numeric"
函数错误(类,fdef,mtable):无法找到函数“ fetch”,签名“ data.frame”,“数字”的继承方法
Any ideas? 有任何想法吗?
You're mistaking dbSendQuery
with dbGetQuery
. 您将
dbSendQuery
与dbGetQuery
。
dbGetQuery
combine dbSendQuery
, fetch
and dbClearResult
as per documentation: dbGetQuery
结合dbSendQuery
, fetch
和dbClearResult
按文件:
The function
dbSendQuery
only submits and synchronously executes the SQL statement to the database engine.dbSendQuery
函数仅向数据库引擎提交并同步执行SQL语句。 It does not extracts any records — for that you need to use the functionfetch
(make sure you invokedbClearResult
when you finish fetching the records you need).它不会提取任何记录-为此,您需要使用函数
fetch
(确保在完成提取所需的记录时调用dbClearResult
)。The function
dbGetQuery
does all these in one operation (submits the statement, fetches all output records, and clears the result set).函数
dbGetQuery
一次操作dbGetQuery
完成所有这些操作(提交语句,获取所有输出记录,并清除结果集)。
From ?dbGetQuery
in package DBI
. 来自软件包
DBI
?dbGetQuery
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.