dbBind
From DBI v0.5-1
by Kirill Müller
Bind values to a parameterised/prepared statement
The dbSendQuery
function can be called with queries
that contain placeholders for values. This function binds these placeholders
to actual values, and is intended to be called on the result of
dbSendQuery
before calling dbFetch
.
Usage
dbBind(res, params, ...)
Arguments
- res
- An object inheriting from
DBIResult
. - params
- A list of bindings
- ...
- Other arguments passed on to methods.
Details
Parametrised or prepared statements are executed as follows:
- Call
dbSendQuery
with a query that contains placeholders, store the returnedDBIResult
object in a variable. Currently, the syntax for the placeholders is backend-specific, e.g.,?
,$
,$name
and:name
. Mixing placeholders (in particular, named and unnamed ones) is not recommended. - Call
dbBind
on theDBIResult
object with a list that specifies actual values for the placeholders. The list must be named or unnamed, depending on the kind of placeholders used. Named values are matched to named paramters, unnamed values are matched by position. - Call
dbFetch
on the sameDBIResult
object. - Repeat 2. and 3. as necessary.
- Close the result set via
dbClearResult
.
See Also
Other DBIResult generics: DBIResult-class
,
SQL
, dbClearResult
,
dbColumnInfo
, dbFetch
,
dbGetInfo
, dbGetRowCount
,
dbGetRowsAffected
,
dbGetStatement
,
dbHasCompleted
, dbIsValid
Examples
library(DBI)
## Not run:
# con <- dbConnect(RSQLite::SQLite(), ":memory:")
#
# dbWriteTable(con, "iris", iris)
# iris_result <- dbSendQuery(con, "SELECT * FROM iris WHERE [Petal.Width] > ?")
# dbBind(iris_result, list(2.3))
# dbFetch(iris_result)
# dbBind(iris_result, list(3))
# dbFetch(iris_result)
#
# dbClearResult(iris_result)
# dbDisconnect(con)
# ## End(Not run)
Community examples
Looks like there are no examples yet.