开发者

Second RMySQL operation fails - why?

开发者 https://www.devze.com 2023-01-29 01:09 出处:网络
I am running a script that stores different datasets to a MySQL database. This works so far, but only sequentially. e.g.:

I am running a script that stores different datasets to a MySQL database. This works so far, but only sequentially. e.g.:

# write table1 
replaceTable(con,tbl="table1",dframe=dframe1)

# write table2 
replaceTable(con,tbl="table2",dframe=dframe2)

If I select both (I use StatET / Eclipse) and run the selection, I get an error:

Error in function (classes, fdef, mtable)  : 
  unable to find an inherited method for function "dbWriteTable",
  for signature "MySQLConnection", "开发者_JAVA百科data.frame", "data.frame".

I guess this has to do with the fact that my con is still busy or so when the second request is started. When I run the script line after line it just works fine. Hence I wonder, how can I tell R to wait til the first request is ready and then go ahead ? How can I make R scripts interactive (just console like plot examples - no tcl/tk).

EDIT:

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 has two important arguments:

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’.

For past project I have successfully achieve appending, overwriting, creating, ... of tables with proper combinations of these.

0

精彩评论

暂无评论...
验证码 换一张
取 消