Learn R Programming

RSQLite (version 1.0.0)

dbConnect,SQLiteDriver-method: Connect to/disconnect from a SQLite database.

Description

Connect to/disconnect from a SQLite database.

Usage

# S4 method for SQLiteDriver
dbConnect(drv, dbname = "",
  loadable.extensions = TRUE, cache_size = NULL, synchronous = "off",
  flags = SQLITE_RWC, vfs = NULL)

# S4 method for SQLiteConnection dbConnect(drv)

# S4 method for SQLiteConnection dbDisconnect(conn)

Arguments

drv,conn

An objected generated by SQLite, or an existing '>SQLiteConnection. If an connection, the connection will be cloned.

dbname

The path to the database file. There are two special values:

  • "": creates a temporary on-disk database The file will be deleted when the connection is closed.

  • ":memory:": create a temporary in-memory database.

loadable.extensions

When TRUE (default) SQLite3 loadable extensions are enabled. Setting this value to FALSE prevents extensions from being loaded.

cache_size

Advanced option. A positive integer to change the maximum number of disk pages that SQLite holds in memory (SQLite's default is 2000 pages). See http://www.sqlite.org/pragma.html#pragma_cache_size for details.

synchronous

Advanced options. Possible values for synchronous are "off" (the default), "normal", or "full". Users have reported significant speed ups using sychronous = "off", and the SQLite documentation itself implies considerable improved performance at the very modest risk of database corruption in the unlikely case of the operating system (not the R application) crashing. See http://www.sqlite.org/pragma.html#pragma_synchronous for details.

flags

SQLITE_RWC: open the database in read/write mode and create the database file if it does not already exist; SQLITE_RW: open the database in read/write mode. Raise an error if the file does not already exist; SQLITE_RO: open the database in read only mode. Raise an error if the file does not already exist

vfs

Select the SQLite3 OS interface. See http://www.sqlite.org/vfs.html for details. Allowed values are "unix-posix", "unix-unix-afp", "unix-unix-flock", "unix-dotfile", and "unix-none".

Examples

Run this code
# NOT RUN {
# Create temporary in-memory db
tmp <- dbConnect(SQLite(), ":memory:")
summary(tmp)
dbDisconnect(tmp)

# Create temporary on-disk db with bigger cache and safer synchronisation
tmp <- dbConnect(SQLite(), "", cache_size = 5000, synchronous = "full")
summary(tmp)
dbDisconnect(tmp)
# }

Run the code above in your browser using DataLab