File: test-db-sql.R

package info (click to toggle)
r-cran-dbplyr 2.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,376 kB
  • sloc: sh: 13; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,062 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
test_that("2nd edition uses sql methods", {
  local_methods(
    db_analyze.Test = function(con, ...) abort("db_method")
  )

  con <- structure(list(), class = c("Test", "DBIConnection"))
  expect_snapshot(expect_error(dbplyr_analyze(con), "db_method"))

  local_methods(
    dbplyr_edition.Test = function(con) 2,
    sql_table_analyze.Test = function(con, ...) abort("sql_method")
  )
  expect_error(dbplyr_analyze(con), "sql_method")
})

test_that("sql_query_rows() works", {
  expect_equal(
    sql_query_rows(simulate_dbi(), ident("abc")),
    sql("SELECT COUNT(*) FROM `abc` AS `master`")
  )
})

test_that("handles DBI error", {
  con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
  on.exit(DBI::dbDisconnect(con))

  expect_snapshot({
    (expect_error(db_analyze(con, "tbl")))
    (expect_error(db_create_index(con, "tbl", "col")))

    (expect_error(db_explain(con, "invalid sql")))
    (expect_error(db_query_fields(con, "does not exist")))
    (expect_error(db_save_query(con, "invalid sql", "tbl")))
  },
  transform = snap_transform_dbi
  )
})