R/dbIsValid__duckdb_driver.R

Defines functions dbIsValid__duckdb_driver

Documented in dbIsValid__duckdb_driver

#' @rdname duckdb_driver-class
#' @inheritParams DBI::dbIsValid
#' @usage NULL
dbIsValid__duckdb_driver <- function(dbObj, ...) {
  valid <- FALSE
  tryCatch(
    {
      was_locked <- rethrow_rapi_is_locked(dbObj@database_ref)
      con <- dbConnect(dbObj)
      # Keep driver alive, but only if needed
      if (was_locked) {
        rethrow_rapi_lock(dbObj@database_ref)
      }

      dbExecute(con, SQL("SELECT 1"))
      dbDisconnect(con)
      valid <- TRUE
    },
    error = function(c) {
    }
  )
  valid
}

#' @rdname duckdb_driver-class
#' @export
setMethod("dbIsValid", "duckdb_driver", dbIsValid__duckdb_driver)

Try the duckdb package in your browser

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

duckdb documentation built on Oct. 30, 2024, 5:06 p.m.