prepare_sql | R Documentation |
Except for sql
, parameters are default values to be used when none are
supplied in sql
(i.e. when sql
is a tibble returned by read_sql()
).
prepare_sql(
sql,
quotesql = "yes",
values = parent.frame(),
execmethod = "get",
geometry = NA,
default.conn = default_conn()
)
sql |
An optionally-named list or character vector containing sql
commands, or a tibble returned by |
quotesql |
"yes" or "no" - should interpolated characters be quoted by default? Anything that isn't "no" is treated as "yes". |
values |
An environment containing variables to interpolate into the
SQL. Pass any object that is not an environment (commonly-used options
include "no", NA, FALSE or NULL) if interpolation is to be skipped, or
another environment containing values to interpolate to avoid using
|
execmethod |
One of "get", "execute", "sendq", "sends" or "spatial" -
which method should be used to execute the query? "get" means
|
geometry |
If |
default.conn |
Either the name of a sqlhelper connection, or a database
connection returned by |
The default.conn
parameter may be used to supply a connection object that
is not a configured sqlhelper connection which can then be used to
interpolate quoted strings.
A tibble containing 1 row per query with the following fields:
character. A name for this query
"yes" or "no". Should parameterized character values be quoted for this query?
"yes" or "no". Should this query be parameterized with values from R?
The method to
execute this query. One of "get" (DBI::dbGetQuery()
), "execute"
(DBI::dbExecute()
), "sendq" (DBI::dbSendQuery()
), "sends"
(DBI::dbSendStatement()
) or "spatial" (sf::st_read()
)
character. If execmethod
is "spatial", which is the
geometry column?
character. The name of the database connection to use for this query. Must be the name of a configured sqlhelper connection.
The sql query as entered
The value of file_name
The sql query to be executed, i.e. with interpolations and quoting in place
library(sqlhelper)
connect(
system.file("examples/sqlhelper_db_conf.yml",
package="sqlhelper"),
exclusive = TRUE
)
n <- 5
foo <- 'bar'
prepped <- prepare_sql(c("select {`foo`}", "select {n}"))
prepped
prepped$prepared_sql
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.