RSQLite (version 0.8-0)

sqliteCopyDatabase: Copy a SQLite database to a file

Description

This function allows you to copy the main database of a given database connection to a file. It can be used to save an in-memory database created using dbname = ":memory:".

Usage

sqliteCopyDatabase(db, filename)

Arguments

db
A SQLiteConnection object.
filename
A string containing the path where the copy will be written.

Value

  • Returns TRUE if the copy was successful and FALSE if an error code was returned by the SQLite API.

Details

This function uses SQLite's online backup API to make the copy. The target file given by filename will be over written if it already exists.

References

http://www.sqlite.org/backup.html

Examples

Run this code
## Create an in memory database
db <- dbConnect(SQLite(), dbname = ":memory:")
df <- data.frame(letters=letters[1:4], numbers=1:4)
ok <- dbWriteTable(db, "table1", df, row.names = FALSE)
stopifnot(ok)

## Copy the contents of the in memory database to
## the specified file
backupDbFile <- tempfile()
ok <- sqliteCopyDatabase(db, backupDbFile)
stopifnot(ok)

## cleanup
dbDisconnect(db)
unlink(backupDbFile)

Run the code above in your browser using DataLab