sqliteCopyDatabase {RSQLite} | R Documentation |
This function copies a database connection to a file or to another
database connection. It can be used to save an in-memory database
(created using dbname = ":memory:"
) to a file or to create an
in-memory database as a copy of anothe database.
sqliteCopyDatabase(from, to)
from |
A |
to |
Either a string specifying the file name where the copy will be
written or a |
This function uses SQLite's experimental online backup API to make the copy.
Returns NULL
.
Seth Falcon
http://www.sqlite.org/backup.html
## Create an in memory database db <- dbConnect(SQLite(), dbname = ":memory:") df <- data.frame(letters=letters[1:4], numbers=1:4, stringsAsFactors = FALSE) ok <- dbWriteTable(db, "table1", df, row.names = FALSE) stopifnot(ok) ## Copy the contents of the in memory database to ## the specified file backupDbFile <- tempfile() sqliteCopyDatabase(db, backupDbFile) diskdb <- dbConnect(SQLite(), dbname = backupDbFile) stopifnot(identical(df, dbReadTable(diskdb, "table1"))) ## Copy from one connection to another db2 <- dbConnect(SQLite(), dbname = ":memory:") sqliteCopyDatabase(db, db2) stopifnot(identical(df, dbReadTable(db2, "table1"))) ## cleanup dbDisconnect(db) dbDisconnect(diskdb) dbDisconnect(db2) unlink(backupDbFile)