query {RSQLite}R Documentation

Execute a SQL statement on a database connection

Description

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.

Usage

## 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)

Arguments

conn

an SQLiteConnection object.

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 SQLiteResult object.

n

maximum number of records to retrieve per fetch. Use -1 to retrieve all pending records; use 0 for to fetch the default number of rows as defined in SQLite

...

Unused. Needed for compatibility with generic.

Examples

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)

[Package RSQLite version 1.0.0 Index]