dbBind {DBI} | R Documentation |
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
.
dbBind(res, params, ...)
res |
An object inheriting from |
params |
A list of bindings |
... |
Other arguments passed on to methods. |
Parametrised or prepared statements are executed as follows:
Call dbSendQuery
with a query that contains placeholders,
store the returned DBIResult
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 the DBIResult
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 same DBIResult
object.
Repeat 2. and 3. as necessary.
Close the result set via dbClearResult
.
Other DBIResult generics: DBIResult-class
,
SQL
, dbClearResult
,
dbColumnInfo
, dbFetch
,
dbGetInfo
, dbGetRowCount
,
dbGetRowsAffected
,
dbGetStatement
,
dbHasCompleted
, dbIsValid
## 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)