Skip to content

Commit

Permalink
Correclty compute row count when fetching more rows than exist
Browse files Browse the repository at this point in the history
Fixes #501
  • Loading branch information
hadley committed Nov 7, 2023
1 parent 3ab6283 commit 5db098d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# bigrquery (development version)

* `dbGetRowCount()` and `dbHasComplete()` now return correct values when you
try to fetch more rows than actually exist (#501).

* `dbReadTable()`, `dbWriteTable()`, `dbExistsTable()`, `dbRemoveTable()`,
and `dbListFields()` now all work with `DBI::Id()` (#537).

Expand Down
2 changes: 1 addition & 1 deletion R/dbi-result.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ setMethod(
bigint = res@bigint,
quiet = res@quiet
)
res@cursor$adv(n)
res@cursor$adv(nrow(data))

data
})
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-dbi-result.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ test_that("can retrieve query in pieces and that quiet is respected", {
expect_true(DBI::dbHasCompleted(res))
})

test_that("dbHasCompleted() is accurate if you fetch past end", {
con <- DBI::dbConnect(
bigquery(),
project = bq_test_project(),
dataset = "basedata"
)

res <- DBI::dbSendQuery(con, "SELECT cyl FROM mtcars LIMIT 5")
df <- DBI::dbFetch(res, 10)

expect_equal(DBI::dbGetRowCount(res), 5)
expect_true(DBI::dbHasCompleted(res))
})

test_that("can get metadata", {
con <- DBI::dbConnect(
bigquery(),
Expand Down

0 comments on commit 5db098d

Please sign in to comment.