spec_meta_bind
Source:R/spec-meta-bind-runner.R
, R/spec-meta-bind-formals.R
, R/spec-meta-bind-expr.R
spec_meta_bind.Rd
spec_meta_bind
spec_meta_bind
spec_meta_bind
Value
dbBind()
returns the result set,
invisibly,
for queries issued by DBI::dbSendQuery()
or DBI::dbSendQueryArrow()
and
also for data manipulation statements issued by
DBI::dbSendStatement()
.
Specification
DBI clients execute parametrized statements as follows:
Call
DBI::dbSendQuery()
,DBI::dbSendQueryArrow()
orDBI::dbSendStatement()
with a query or statement that contains placeholders, store the returned DBI::DBIResult object in a variable. Mixing placeholders (in particular, named and unnamed ones) is not recommended. It is good practice to register a call toDBI::dbClearResult()
viaon.exit()
right after callingdbSendQuery()
ordbSendStatement()
(see the last enumeration item). UntilDBI::dbBind()
orDBI::dbBindArrow()
have been called, the returned result set object has the following behavior:DBI::dbFetch()
raises an error (fordbSendQuery()
anddbSendQueryArrow()
)DBI::dbGetRowCount()
returns zero (fordbSendQuery()
anddbSendQueryArrow()
)DBI::dbGetRowsAffected()
returns an integerNA
(fordbSendStatement()
)DBI::dbIsValid()
returnsTRUE
DBI::dbHasCompleted()
returnsFALSE
Call
DBI::dbBind()
orDBI::dbBindArrow()
:For
DBI::dbBind()
, theparams
argument must be a list where all elements have the same lengths and contain values supported by the backend. A data.frame is internally stored as such a list.For
DBI::dbBindArrow()
, theparams
argument must be a nanoarrow array stream, with one column per query parameter.
Retrieve the data or the number of affected rows from the
DBIResult
object.For queries issued by
dbSendQuery()
ordbSendQueryArrow()
, callDBI::dbFetch()
.For statements issued by
dbSendStatements()
, callDBI::dbGetRowsAffected()
. (Execution begins immediately after theDBI::dbBind()
call, the statement is processed entirely before the function returns.)
Repeat 2. and 3. as necessary.
Close the result set via
DBI::dbClearResult()
.
The elements of the params
argument do not need to be scalars,
vectors of arbitrary length
(including length 0)
are supported.
For queries, calling dbFetch()
binding such parameters returns
concatenated results, equivalent to binding and fetching for each set
of values and connecting via rbind()
.
For data manipulation statements, dbGetRowsAffected()
returns the
total number of rows affected if binding non-scalar parameters.
dbBind()
also accepts repeated calls on the same result set
for both queries
and data manipulation statements,
even if no results are fetched between calls to dbBind()
,
for both queries
and data manipulation statements.
If the placeholders in the query are named,
their order in the params
argument is not important.
At least the following data types are accepted on input (including NA):
logical for Boolean values
character (also with special characters such as spaces, newlines, quotes, and backslashes)
factor (bound as character, with warning)
lubridate::Date (also when stored internally as integer)
lubridate::POSIXct timestamps
POSIXlt timestamps
difftime values (also with units other than seconds and with the value stored as integer)
lists of raw for blobs (with
NULL
entries for SQL NULL values)objects of type blob::blob
Failure modes
Calling dbBind()
for a query without parameters
raises an error.
Binding too many
or not enough values,
or parameters with wrong names
or unequal length,
also raises an error.
If the placeholders in the query are named,
all parameter values must have names
(which must not be empty
or NA
),
and vice versa,
otherwise an error is raised.
The behavior for mixing placeholders of different types
(in particular mixing positional and named placeholders)
is not specified.
Calling dbBind()
on a result set already cleared by DBI::dbClearResult()
also raises an error.
See also
Other meta specifications:
spec_get_info
,
spec_meta_column_info
,
spec_meta_get_row_count
,
spec_meta_get_rows_affected
,
spec_meta_get_statement
,
spec_meta_has_completed
,
spec_meta_is_valid
Other meta specifications:
spec_get_info
,
spec_meta_column_info
,
spec_meta_get_row_count
,
spec_meta_get_rows_affected
,
spec_meta_get_statement
,
spec_meta_has_completed
,
spec_meta_is_valid
Other meta specifications:
spec_get_info
,
spec_meta_column_info
,
spec_meta_get_row_count
,
spec_meta_get_rows_affected
,
spec_meta_get_statement
,
spec_meta_has_completed
,
spec_meta_is_valid