query {RSQLite} | R Documentation |
To retrieve results a chunk at a time, use dbSendQuery
,
dbFetch
, then ClearResult
. Alternatively, if you want all the
results (and they'll fit in memory) use dbGetQuery
which sends,
fetches and clears for you.
## S4 method for signature 'SQLiteConnection,character' dbSendQuery(conn, statement) ## S4 method for signature 'SQLiteConnection,character,data.frame' dbSendPreparedQuery(conn, statement, bind.data) ## S4 method for signature 'SQLiteResult' dbFetch(res, n = 0) ## S4 method for signature 'SQLiteResult' fetch(res, n = 0) ## S4 method for signature 'SQLiteResult' dbClearResult(res, ...) ## S4 method for signature 'SQLiteConnection' dbClearResult(res, ...) ## S4 method for signature 'SQLiteConnection' dbListResults(conn, ...) ## S4 method for signature 'SQLiteConnection,character' dbGetQuery(conn, statement) ## S4 method for signature 'SQLiteConnection,character,data.frame' dbGetPreparedQuery(conn, statement, bind.data)
conn |
an |
statement |
a character vector of length one specifying the SQL statement that should be executed. Only a single SQL statment should be provided. |
bind.data |
A data frame of data to be bound. |
res |
an |
n |
maximum number of records to retrieve per fetch. Use |
... |
Unused. Needed for compatibility with generic. |
con <- dbConnect(SQLite(), ":memory:") dbWriteTable(con, "arrests", datasets::USArrests) # Run query to get results as dataframe dbGetQuery(con, "SELECT * FROM arrests limit 3") # Send query to pull requests in batches res <- dbSendQuery(con, "SELECT * FROM arrests") data <- fetch(res, n = 2) data dbHasCompleted(res) dbListResults(con) dbClearResult(res) # Use dbSendPreparedQuery/dbGetPreparedQuery for "prepared" queries dbGetPreparedQuery(con, "SELECT * FROM arrests WHERE Murder < ?", data.frame(x = 3)) dbGetPreparedQuery(con, "SELECT * FROM arrests WHERE Murder < (:x)", data.frame(x = 3)) dbDisconnect(con)