Skip to content

Commit

Permalink
Test for unknown infix and vector value - fixes #1299
Browse files Browse the repository at this point in the history
  • Loading branch information
mgirlich committed Jun 30, 2023
1 parent ed6b09c commit 6683f25
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 13 deletions.
2 changes: 1 addition & 1 deletion R/backend-postgres-old.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ db_write_table.PostgreSQLConnection <- function(con,
#' @export
db_query_fields.PostgreSQLConnection <- function(con, sql, ...) {
sql <- sql_subquery(con, sql)
fields <- glue_sql2(con, "SELECT * FROM {sql} WHERE 0=1")
fields <- glue_sql2(con, "SELECT * FROM {.from sql} WHERE 0=1")

qry <- dbSendQuery(con, fields)
on.exit(dbClearResult(qry))
Expand Down
5 changes: 0 additions & 5 deletions tests/testthat/_snaps/build-sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
Condition
Error in `glue_check_collapse()`:
! Collapsing is only allowed for "col" and "val", not for "name".
Code
glue_sql2("{.sql x*}", .con = con)
Condition
Error in `glue_check_collapse()`:
! Collapsing is only allowed for "col" and "val", not for "sql".
Code
glue_sql2("{.from x*}", .con = con)
Condition
Expand Down
7 changes: 0 additions & 7 deletions tests/testthat/test-build-sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ test_that("glue_sql() interpolates .name correctly", {
expect_equal(glue_sql2("{.name ident_q('ta ble')}", .con = con), sql("ta ble"))
})

test_that("glue_sql() interpolates .sql correctly", {
con <- simulate_dbi()
expect_equal(glue_sql2("{.sql 'ta ble'}", .con = con), sql("ta ble"))
expect_equal(glue_sql2("{.sql sql('ta ble')}", .con = con), sql("ta ble"))
})

test_that("glue_sql() interpolates .col correctly", {
con <- simulate_dbi()
expect_equal(glue_sql2("{.col 'x'}", .con = con), sql("`x`"))
Expand Down Expand Up @@ -76,7 +70,6 @@ test_that("glue_sql() can collapse", {
expect_snapshot(error = TRUE, {
glue_sql2("{.tbl x*}", .con = con)
glue_sql2("{.name x*}", .con = con)
glue_sql2("{.sql x*}", .con = con)
glue_sql2("{.from x*}", .con = con)
})
})
3 changes: 3 additions & 0 deletions tests/testthat/test-translate-sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ test_that("magrittr pipe is translated", {
test_that("user infix functions are translated", {
local_con(simulate_dbi())
expect_equal(test_translate_sql(x %like% y), sql("`x` like `y`"))

# keep case and also works with vectors of length > 1 #1299
expect_equal(test_translate_sql(x %LIKE% 1:2), sql("`x` LIKE (1, 2)"))
})

test_that("sql() evaluates input locally", {
Expand Down

0 comments on commit 6683f25

Please sign in to comment.