File: spec-result-clear-result.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 (69 lines) | stat: -rw-r--r-- 2,365 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#' spec_result_clear_result
#' @family result specifications
#' @family Arrow specifications
#' @usage NULL
#' @format NULL
#' @keywords NULL
spec_result_clear_result <- list(
  clear_result_formals = function() {
    # <establish formals of described functions>
    expect_equal(names(formals(dbClearResult)), c("res", "..."))
  },

  clear_result_return_query = function(con) {
    #' @return
    #' `dbClearResult()` returns `TRUE`, invisibly, for result sets obtained from
    #' `dbSendQuery()`,
    res <- dbSendQuery(con, trivial_query())
    expect_invisible_true(dbClearResult(res))
  },

  clear_result_return_statement = function(ctx, con, table_name) {
    #' `dbSendStatement()`,
    res <- dbSendStatement(con, ctx$tweaks$create_table_as(table_name, "SELECT 1"))
    expect_invisible_true(dbClearResult(res))
  },

  clear_result_return_query_arrow = function(ctx, con, table_name) {
    # Failed on SQL Server
    skip_if_not_dbitest(ctx, "1.7.99.3")

    #' or `dbSendQueryArrow()`,
    res <- dbSendQueryArrow(con, ctx$tweaks$create_table_as(table_name, "SELECT 1"))
    expect_invisible_true(dbClearResult(res))
  },

  #'
  cannot_clear_result_twice_query = function(con) {
    #' @section Failure modes:
    #' An attempt to close an already closed result set issues a warning
    #' for `dbSendQuery()`,
    res <- dbSendQuery(con, trivial_query())
    dbClearResult(res)
    expect_warning(expect_invisible_true(dbClearResult(res)))
  },

  cannot_clear_result_twice_statement = function(ctx, con, table_name) {
    #' `dbSendStatement()`,
    res <- dbSendStatement(con, ctx$tweaks$create_table_as(table_name, "SELECT 1"))
    dbClearResult(res)
    expect_warning(expect_invisible_true(dbClearResult(res)))
  },

  cannot_clear_result_twice_query_arrow = function(ctx, con, table_name) {
    # Failed on SQL Server
    skip_if_not_dbitest(ctx, "1.7.99.4")

    #' and `dbSendQueryArrow()`,
    res <- dbSendQueryArrow(con, ctx$tweaks$create_table_as(table_name, "SELECT 1"))
    dbClearResult(res)
    expect_warning(expect_invisible_true(dbClearResult(res)))
  },

  #' @section Specification:
  #' `dbClearResult()` frees all resources associated with retrieving
  #' the result of a query or update operation.
  #' The DBI backend can expect a call to `dbClearResult()` for each
  #' [dbSendQuery()] or [dbSendStatement()] call.
  NULL
)