Skip to content

Commit

Permalink
Merge pull request #316 from r-dbi/f-296-fetch-na
Browse files Browse the repository at this point in the history
feat: Require support for `dbFetch(n = NA)`
  • Loading branch information
aviator-app[bot] authored Dec 16, 2023
2 parents f07d948 + c5aed9c commit 5a950dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 15 additions & 2 deletions R/spec-result-fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ spec_result_fetch <- list(
expect_identical(class(rows), "data.frame")
},

fetch_na_rows = function(ctx, con) {
if (as.package_version(ctx$tweaks$dbitest_version) < "1.7.4") {
skip(paste0("tweak: dbitest_version: ", ctx$tweaks$dbitest_version))
}

#' Passing `n = NA` is supported and returns an arbitrary number of rows (at least one)
#' as specified by the driver, but at most the remaining rows in the result set.
query <- trivial_query()
res <- local_result(dbSendQuery(con, query))
rows <- check_df(dbFetch(res, n = NA))
expect_equal(rows, data.frame(a = 1.5))
},

#'
fetch_closed = function(con) {
#' @section Failure modes:
Expand All @@ -60,19 +73,19 @@ spec_result_fetch <- list(
expect_error(dbFetch(res, 1.5))
expect_error(dbFetch(res, integer()))
expect_error(dbFetch(res, 1:3))
expect_error(dbFetch(res, NA_integer_))
},

fetch_n_good_after_bad = function(con) {
#' but a subsequent call to `dbFetch()` with proper `n` argument succeeds.
query <- trivial_query()
res <- local_result(dbSendQuery(con, query))
expect_error(dbFetch(res, NA_integer_))
expect_error(dbFetch(res, -2))
rows <- check_df(dbFetch(res))
expect_equal(rows, data.frame(a = 1.5))
},

fetch_no_return_value = function(con, table_name) {
#'
#' Calling `dbFetch()` on a result set from a data manipulation query
#' created by [dbSendStatement()]
#' can be fetched and return an empty data frame, with a warning.
Expand Down
3 changes: 3 additions & 0 deletions man/spec_result_fetch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5a950dc

Please sign in to comment.