Description Usage Arguments Details Value See Also Examples
Together, SQLite()
and dbConnect()
allow you to connect to
a SQLite database file. See DBI::dbSendQuery()
for how to issue queries
and receive results.
1 2 3 4 5 6 7 8 9 10 11 12 13 | SQLite(...)
## S4 method for signature 'SQLiteDriver'
dbConnect(drv, dbname = "", ...,
loadable.extensions = TRUE, default.extensions = loadable.extensions,
cache_size = NULL, synchronous = "off", flags = SQLITE_RWC,
vfs = NULL)
## S4 method for signature 'SQLiteConnection'
dbConnect(drv, ...)
## S4 method for signature 'SQLiteConnection'
dbDisconnect(conn, ...)
|
... |
In previous versions, |
drv, conn |
An objected generated by |
dbname |
The path to the database file. SQLite keeps each database instance in one single file. The name of the database is the file name, thus database names should be legal file names in the running platform. There are two exceptions:
|
loadable.extensions |
When |
default.extensions |
When |
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 |
flags |
|
vfs |
Select the SQLite3 OS interface. See
http://www.sqlite.org/vfs.html for details. Allowed values are
|
Connections are automatically cleaned-up after they're deleted and
reclaimed by the GC. You can use DBI::dbDisconnect()
to terminate the
connection early, but it will not actually close until all open result
sets have been closed (and you'll get a warning message to this effect).
SQLite()
returns an object of class SQLiteDriver.
dbConnect()
returns an object of class SQLiteConnection.
The corresponding generic functions DBI::dbConnect()
and DBI::dbDisconnect()
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | library(DBI)
# Initialize a temporary in memory database and copy a data.frame into it
con <- dbConnect(RSQLite::SQLite(), ":memory:")
data(USArrests)
dbWriteTable(con, "USArrests", USArrests)
dbListTables(con)
# Fetch all query results into a data frame:
dbGetQuery(con, "SELECT * FROM USArrests")
# Or do it in batches
rs <- dbSendQuery(con, "SELECT * FROM USArrests")
d1 <- dbFetch(rs, n = 10) # extract data in chunks of 10 rows
dbHasCompleted(rs)
d2 <- dbFetch(rs, n = -1) # extract all remaining data
dbHasCompleted(rs)
dbClearResult(rs)
# clean up
dbDisconnect(con)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.