Learn R Programming

pool (version 1.0.1)

DBI-wrap: DBI methods (simple wrappers)

Description

These pool method for DBI generics methods check out a connection (with poolCheckout()), re-call the generic, then return the connection to the pool (with poolReturn()).

Usage

# S4 method for Pool
dbDataType(dbObj, obj, ...)

# S4 method for Pool,ANY dbGetQuery(conn, statement, ...)

# S4 method for Pool,ANY dbExecute(conn, statement, ...)

# S4 method for Pool,ANY dbListFields(conn, name, ...)

# S4 method for Pool dbListTables(conn, ...)

# S4 method for Pool dbListObjects(conn, prefix = NULL, ...)

# S4 method for Pool,ANY dbReadTable(conn, name, ...)

# S4 method for Pool,ANY dbWriteTable(conn, name, value, ...)

# S4 method for Pool dbCreateTable(conn, name, fields, ..., row.names = NULL, temporary = FALSE)

# S4 method for Pool dbAppendTable(conn, name, value, ..., row.names = NULL)

# S4 method for Pool,ANY dbExistsTable(conn, name, ...)

# S4 method for Pool,ANY dbRemoveTable(conn, name, ...)

# S4 method for Pool dbIsReadOnly(dbObj, ...)

# S4 method for Pool sqlData(con, value, row.names = NA, ...)

# S4 method for Pool sqlCreateTable(con, table, fields, row.names = NA, temporary = FALSE, ...)

# S4 method for Pool sqlAppendTable(con, table, values, row.names = NA, ...)

# S4 method for Pool sqlInterpolate(conn, sql, ..., .dots = list())

# S4 method for Pool sqlParseVariables(conn, sql, ...)

# S4 method for Pool,ANY dbQuoteIdentifier(conn, x, ...)

# S4 method for Pool dbUnquoteIdentifier(conn, x, ...)

# S4 method for Pool dbQuoteLiteral(conn, x, ...)

# S4 method for Pool,ANY dbQuoteString(conn, x, ...)

Arguments

Examples

Run this code
mtcars1 <- mtcars[ c(1:16), ] # first half of the mtcars dataset
mtcars2 <- mtcars[-c(1:16), ] # second half of the mtcars dataset

pool <- dbPool(RSQLite::SQLite())

# write the mtcars1 table into the database
dbWriteTable(pool, "mtcars", mtcars1, row.names = TRUE)

# list the current tables in the database
dbListTables(pool)

# read the "mtcars" table from the database (only 16 rows)
dbReadTable(pool, "mtcars")

# append mtcars2 to the "mtcars" table already in the database
dbWriteTable(pool, "mtcars", mtcars2, row.names = TRUE, append = TRUE)

# read the "mtcars" table from the database (all 32 rows)
dbReadTable(pool, "mtcars")

# get the names of the columns in the databases's table
dbListFields(pool, "mtcars")

# use dbExecute to change the "mpg" and "cyl" values of the 1st row
dbExecute(pool,
  paste(
    "UPDATE mtcars",
    "SET mpg = '22.0', cyl = '10'",
    "WHERE row_names = 'Mazda RX4'"
  )
)

# read the 1st row of "mtcars" table to confirm the previous change
dbGetQuery(pool, "SELECT * FROM mtcars WHERE row_names = 'Mazda RX4'")

# drop the "mtcars" table from the database
dbRemoveTable(pool, "mtcars")

# list the current tables in the database
dbListTables(pool)

poolClose(pool)

Run the code above in your browser using DataLab