Create result sets
Source:R/dbSendQueryArrow_AdbiConnection.R, R/dbSendQuery_AdbiConnection_character.R, R/dbSendStatement_AdbiConnection_character.R
dbSendQuery.RdCreating result sets using DBI::dbSendQuery() (and by extension using
DBI::dbGetQuery()) mostly follows DBI specification.
One way where adbi deviates from DBI mechanisms is how the bigint setting
is not only per connection, but the per-connection setting can be overridden
on a result set basis.
As default, the connection setting is applied, but passing one of the
accepted values as bigint when creating a result set will subsequently use
that setting for all fetches using this result set.
Usage
# S4 method for class 'AdbiConnection'
dbSendQueryArrow(
conn,
statement,
...,
params = NULL,
immediate = NULL,
bigint = NULL
)
# S4 method for class 'AdbiConnection,character'
dbSendQuery(
conn,
statement,
...,
params = NULL,
immediate = NULL,
bigint = NULL
)
# S4 method for class 'AdbiConnection,character'
dbSendStatement(
conn,
statement,
...,
params = NULL,
immediate = NULL,
bigint = NULL
)Arguments
- conn
A DBI::DBIConnection object, as returned by
DBI::dbConnect().- statement
a character string containing SQL.
- ...
Other parameters passed on to methods.
- params
Optional query parameters (forwarded to
DBI::dbBind())- immediate
Use
TRUEfor direct execution,FALSEto bind parameters, orNULLto inspect placeholders when the driver supports it.- bigint
The R type that 64-bit integer types should be mapped to, default is chosen according to the connection setting. See
dbConnect()for the accepted values.
Value
An S4 class AdbiResult (inheriting from DBI::DBIResult).
Details
Multiple open result sets per connection are supported and support can be
disabled by setting options(adbi.allow_multiple_results = FALSE).
If not enabled, creating a new result will finalize potential other results
and throw a warning.
If parameter metadata is unavailable, bind before fetching when parameters are needed. Without metadata, adbi does not check the number or names of the parameters, so a mismatch is reported only if the driver checks for it, possibly not until the statement is executed.
Without metadata, adbi cannot tell whether a statement sent with
immediate = NULL has placeholders, so such a statement runs only once it
is bound or DBI::dbGetRowsAffected() is called, as DBI::dbExecute()
does.
Pass immediate = TRUE for a statement without placeholders to run when it
is sent.
For an unbound statement sent with immediate = FALSE,
DBI::dbGetRowsAffected() returns NA.
Examples
if (requireNamespace("adbcsqlite")) {
library(DBI)
con <- dbConnect(adbi::adbi(pkg = "adbcsqlite"), uri = ":memory:")
dbWriteTable(con, "swiss", swiss)
str(
dbGetQuery(con, "SELECT Examination from swiss WHERE Agriculture < 30")
)
str(
dbGetQuery(con, "SELECT Examination from swiss WHERE Agriculture < 30",
bigint = "numeric")
)
dbDisconnect(con)
}
#> 'data.frame': 10 obs. of 1 variable:
#> $ Examination: int 15 26 31 25 29 22 35 25 37 22
#> 'data.frame': 10 obs. of 1 variable:
#> $ Examination: num 15 26 31 25 29 22 35 25 37 22