DBI (version 0.2-7)

dbReadTable: Convenience functions for Importing/Exporting DBMS tables

Description

These functions mimic their R/Splus counterpart get, assign, exists, remove, and objects, except that they generate code that gets remotely executed in a database engine.

Usage

dbReadTable(conn, name, ...)
  dbWriteTable(conn, name, value, ...)
  dbExistsTable(conn, name, ...)
  dbRemoveTable(conn, name, ...)

Arguments

conn
a database connection object.
name
a character string specifying a DBMS table name.
value
a data.frame (or coercible to data.frame).
...
any optional arguments that the underlying database driver supports, e.g. [object Object],[object Object],[object Object]

Value

  • dbReadTable returns a data.frame; all other functions return TRUE or FALSE denoting whether the operation was successful or not.

Side Effects

A DBMS statement is generated and remotely executed on a database engine; the result set it produces is fetched in its entirety. These operations may failed if the underlying database driver runs out of available connections and/or result sets, or the operation violates DBMS integrity constraints (e.g., attempting to write duplicate values on a field that's defined as a primary key).

The semantics of assign are slightly extended to allow overwriting or appending to an existing table.

References

See the Database Interface definition document DBI.pdf in the base directory of this package or http://developer.r-project.org/db.

See Also

dbDriver, dbConnect, dbSendQuery, dbGetQuery, fetch, dbCommit, dbGetInfo, dbListTables, dbReadTable.

Examples

Run this code
conn <- dbConnect("MySQL", group = "vitalAnalysis")
con2 <- dbConnect("ODBC", "dsn", "user", "pwd")
if(dbExistsTable(con2, "fuel_frame")){
   fuel.frame <- dbReadTable(con2, "fuel_frame")
   dbRemoveTable(conn, "fuel_frame")
   dbWriteTable(conn, "fuel_frame", fuel.frame)
}
if(dbExistsTable(conn, "RESULTS")){
   dbWriteTable(conn, "RESULTS", results2000, append = T)
else
   dbWriteTable(conn, "RESULTS", results2000)
}

Run the code above in your browser using DataLab