Prepared statements are SQL statements that are parsed and cached
by the server to increase performance when the SQL code is to be executed
repeatedly but with different data.There are three distinct operations involved with prepared statements:
parsing and caching the SQL statement, binding data.frame
columns to the SQL, and executing the code (possibly repeatedly).
The function dbPrepareStatement
takes a connection where
to parse and cache the SQL code. Part of this operation is to
embed references to data.frame
column numbers in the SQL code
and to specify their classes through the bind=
argument.
The ROracle
package uses :n
inside
the SQL statement to bind the $n'th$ column, but other RDBMSs
use the question mark to signal a place holder, e.g., ?
.
The object that dbPrepareStatement
produces is then
used together with a data.frame
(which should agree with the
bound specification) in calls to dbExecStatement
to be executed
for each row of the data.frame
. This can be repeated with
new data.
Embedding column names, instead of column numbers, is not supported,
since some valid R names are not legal SQL names (e.g., R names
with dots "."
in them).