tests/testthat/test-dbClearResult.R

test_that("warning on dbFetch if result set open", {
  con <- dbConnect(SQLite(), ":memory:")
  on.exit(dbDisconnect(con))

  res <- dbSendQuery(con, "SELECT 1;")
  expect_false(dbHasCompleted(res))

  expect_warning(dbGetQuery(con, "SELECT 1;"), "pending rows")

  expect_warning(dbClearResult(res), "Expired")
})

test_that("accessing cleared result throws error", {
  con <- dbConnect(SQLite(), ":memory:")
  on.exit(dbDisconnect(con))

  res <- dbSendQuery(con, "SELECT 1;")
  dbClearResult(res)

  expect_error(dbFetch(res), "Invalid result set")
  expect_error(dbGetInfo(res), "closed")
})

Try the RSQLite package in your browser

Any scripts or data that you put into this service are public.

RSQLite documentation built on Nov. 5, 2023, 1:10 a.m.