File: spec-result-create-table-with-data-type.R

package info (click to toggle)
r-cran-dbitest 1.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,216 kB
  • sloc: sh: 10; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,197 bytes parent folder | download | duplicates (2)
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
#' spec_result_create_table_with_data_type
#' @family result specifications
#' @usage NULL
#' @format NULL
#' @keywords NULL
spec_result_create_table_with_data_type <- list(
  data_type_create_table = function(ctx, con) {
    #' @section Specification:
    #' All data types returned by `dbDataType()` are usable in an SQL statement
    #' of the form
    check_connection_data_type <- function(value) {
      table_name <- random_table_name()
      local_remove_test_table(con, table_name)
      #' `"CREATE TABLE test (a ...)"`.
      query <- paste0("CREATE TABLE ", table_name, " (a ", dbDataType(con, value), ")")
      eval(bquote(dbExecute(con, .(query))))
    }

    expect_conn_has_data_type <- function(value) {
      eval(bquote(
        expect_error(check_connection_data_type(.(value)), NA)
      ))
    }

    expect_conn_has_data_type(logical(1))
    expect_conn_has_data_type(integer(1))
    expect_conn_has_data_type(numeric(1))
    expect_conn_has_data_type(character(1))
    expect_conn_has_data_type(Sys.Date())
    expect_conn_has_data_type(Sys.time())
    if (!isTRUE(ctx$tweaks$omit_blob_tests)) {
      expect_conn_has_data_type(list(as.raw(0:10)))
    }
  },
  #
  NULL
)