我正在运行一个将不同数据集存储到 MySQL 数据库的脚本。到目前为止,这是有效的,但只能按顺序进行。例如:
# write table1
replaceTable(con,tbl="table1",dframe=dframe1)
# write table2
replaceTable(con,tbl="table2",dframe=dframe2)
如果我选择两者(我使用 StatET/Eclipse)并运行选择,我会收到一个错误:
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function "dbWriteTable",
for signature "MySQLConnection", "data.frame", "data.frame".
我想这与我的 con 在第二个请求开始时仍然很忙有关。当我逐行运行脚本时,它工作正常。因此我想知道,我怎样才能告诉 R 等到第一个请求准备好然后继续?我怎样才能使 R 脚本交互(就像绘图示例一样的控制台 - 没有 tcl/tk)。
编辑:
require(RMySQL)
replaceTable <- function(con,tbl,dframe){
if(dbExistsTable(con,tbl)){
dbRemoveTable(con,tbl)
dbWriteTable(con,tbl,dframe)
cat("Existing database table updated / overwritten.")
}
else {
dbWriteTable(con,tbl,dframe)
cat("New database table created")
}
}
最佳答案
dbWriteTable
有两个重要参数:
overwrite: a logical specifying whether to overwrite an existing table
or not. Its default is ‘FALSE’.
append: a logical specifying whether to append to an existing table
in the DBMS. Its default is ‘FALSE’.
对于过去的项目,我已经成功地实现了追加、覆盖、创建……这些表的适当组合。
关于mysql - 第二个 RMySQL 操作失败 - 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4375737/