简体   繁体   English

RMySQL获取-找不到继承的方法

[英]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 . 您将dbSendQuerydbGetQuery
dbGetQuery combine dbSendQuery , fetch and dbClearResult as per documentation: dbGetQuery结合dbSendQueryfetchdbClearResult按文件:

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 function fetch (make sure you invoke dbClearResult 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.

相关问题 无法在 R 3.0.2 (ubuntu 14.04) 上安装 RMySQL - Can't install RMySQL on R 3.0.2 (ubuntu 14.04) 用RMySQL获取的整数列不能转换为double - Integer column fetched with RMySQL can't be converted to double rmysql - 错误:无法初始化未知字符集 - rmysql - Error: Can't initialize character set unknown R MySQL将大整数作为字符串获取 - R RMySQL fetch big ints as strings Symfony 5 和 Doctrine,找不到使用 3 个相关实体获取结果的方法 - Symfony 5 and Doctrine, can't find a way to fetch results with 3 related entities 为什么 fetch 方法不能获取任何东西?(feat node.js,restAPI) - Why fetch method can't fetch anything?(feat node.js, restAPI) R库RMySQL无法启动 - R library RMySQL doesn't start 无法为签名“ character”,“ missing”找到函数“ dbReadTable”的继承方法 - unable to find an inherited method for function ‘dbReadTable’ for signature ‘“character”, “missing”’ 如何修复 dbWriteTable 错误“无法找到用于签名的函数 &#39;dbWriterTable&#39; 的继承方法......?” - How to fix dbWriteTable error “unable to find an inherited method for function 'dbWriterTable' for signature…?” RMySQL,获取错误 - RS-DBI驱动程序警告:(获取行时出错) - RMySQL, fetch errors - RS-DBI driver warning: (error while fetching rows)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM