From c5aed9c1d51b4504a9614a96fdb1651a1a58fa2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 16 Dec 2023 13:32:21 +0100 Subject: [PATCH] feat: Require support for `dbFetch(n = NA)` --- R/spec-result-fetch.R | 17 +++++++++++++++-- man/spec_result_fetch.Rd | 3 +++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/R/spec-result-fetch.R b/R/spec-result-fetch.R index 8699f7bbe..3cbcc1bbf 100644 --- a/R/spec-result-fetch.R +++ b/R/spec-result-fetch.R @@ -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: @@ -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. diff --git a/man/spec_result_fetch.Rd b/man/spec_result_fetch.Rd index 8459f90f5..96ffd66a3 100644 --- a/man/spec_result_fetch.Rd +++ b/man/spec_result_fetch.Rd @@ -11,6 +11,8 @@ columns as fields in the result set, even if the result is a single value or has one or zero rows. +Passing \code{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. } \description{ spec_result_fetch @@ -21,6 +23,7 @@ An attempt to fetch from a closed result set raises an error. If the \code{n} argument is not an atomic whole number greater or equal to -1 or Inf, an error is raised, but a subsequent call to \code{dbFetch()} with proper \code{n} argument succeeds. + Calling \code{dbFetch()} on a result set from a data manipulation query created by \code{\link[=dbSendStatement]{dbSendStatement()}} can be fetched and return an empty data frame, with a warning.