Skip to content

Commit 5bafe83

Browse files
committed
verify n arg of dbFetch
1 parent cccfcf7 commit 5bafe83

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
This avoids problems with drivers that don't support batch sizes larger than the input size.
1313
To restore the behavior prior to this release pass `batch_rows = 1024` or set `options(odbc.batch_rows = 1024)` (#391).
1414
* `dbBind()` and `dbFetch()` now support multiple result sets (@vkapartzianis, #234)
15+
* `dbFetch()` now verifies that `n` is a valid input.
1516

1617
# odbc 1.2.3
1718

R/Result.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ setMethod(
5555
setMethod(
5656
"dbFetch", "OdbcResult",
5757
function(res, n = -1, ...) {
58+
n <- check_n(n)
5859
result_fetch(res@ptr, n)
5960
})
6061

R/utils.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,11 @@ id_field <- function(id, field, default = NULL) {
5858
default
5959
}
6060
}
61+
62+
check_n <- function(n) {
63+
if (length(n) != 1) stop("`n` must be scalar", call. = FALSE)
64+
if (n < -1) stopc("`n` must be nonnegative or -1")
65+
if (is.infinite(n)) n <- -1
66+
if (trunc(n) != n) stopc("`n` must be a whole number", call. = FALSE)
67+
n
68+
}

0 commit comments

Comments
 (0)