Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Authors@R: c(
person("Ben", "Baumer", role = "ctb"),
person("Brian", "Diggs", role = "ctb"),
person("Brian", "Zhang", role = "ctb"),
person("Bulat", "Yapparov", role = "ctb"),
person("Cassio", "Pereira", role = "ctb"),
person("Christophe", "Dervieux", role = "ctb"),
person("David", "Hall", role = "ctb"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Exported the internal functions `sew()` (previously named `wrap()`) and `is_low_change()` to make it possible for other graphics systems such as **rgl** to work in **knitr** like base and grid graphics in base R (thanks, @dmurdoch, #1892 #1853).

- For `sql` code chunks, parameterized queries will be executed through native database api if the chunk option `params` is provided (thanks, @byapparov, #1987).

## BUG FIXES

- Reverted the fix for #1595 since it caused problems in **kableExtra** (thanks, @bttomio, haozhu233/kableExtra#607), and applied a different fix to the original problem (i.e., add `{}` before `[`).
Expand Down
9 changes: 8 additions & 1 deletion R/engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ eng_sql = function(options) {
if (is.na(max.print) || is.null(max.print))
max.print = -1
sql = one_string(options$code)
params = options$params

query = interpolate_from_env(conn, sql)
if (isFALSE(options$eval)) return(engine_output(options, query, ''))
Expand All @@ -558,8 +559,14 @@ eng_sql = function(options) {
data = DBI::dbFetch(res, n = max.print)
DBI::dbClearResult(res)
data

} else {
DBI::dbGetQuery(conn, query)
if (length(params) == 0) {
DBI::dbGetQuery(conn, query)
} else {
# If params option is provided, parameters are not interplolated
DBI::dbGetQuery(conn, sql, params = params)
}
}
}, error = function(e) {
if (!options$error) stop(e)
Expand Down