mysql - 第二个 RMySQL 操作失败 - 为什么?

标签 mysql r

我正在运行一个将不同数据集存储到 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/

相关文章:

r - kableExtra:动态add_header_above标签

R:如何在data.frame的每个col中总计NA的数量

php foreach 将 2 个数组合并为 1 行(工作日和数据)

r - 按总和聚合数据帧

r - 将缺失的行添加到 data.table

mysql - 由于外键约束,无法删除行

r - 编织 PDF 时如何去除垃圾代码

php - 每 X 分钟刷新一些脚本函数的最佳方法是什么?

MySQL死锁与存储过程生成UID

php - 多个 LIKE 引用多行的 WHERE 条件