From dc9b006d90e6ea7290868783a56dc5060999e896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 24 Mar 2024 11:34:04 +0100 Subject: [PATCH] Document behavior --- R/Driver.R | 20 +++++++++++--------- R/dbConnect__duckdb_driver.R | 10 ++++++++-- man/duckdb.Rd | 10 ++++++++-- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/R/Driver.R b/R/Driver.R index b2eed12d1..99698bd2c 100644 --- a/R/Driver.R +++ b/R/Driver.R @@ -31,25 +31,27 @@ duckdb <- function(dbdir = DBDIR_MEMORY, read_only = FALSE, bigint = "numeric", check_flag(read_only) check_bigint(bigint) - # R packages are not allowed to write extensions into home directory, so use R_user_dir instead - if (!("extension_directory" %in% names(config))) { - config["extension_directory"] <- file.path(tools::R_user_dir("duckdb", "data"), "extensions") - } - if (!("secret_directory" %in% names(config))) { - config["secret_directory"] <- file.path(tools::R_user_dir("duckdb", "data"), "stored_secrets") - } - dbdir <- path_normalize(dbdir) if (dbdir != DBDIR_MEMORY) { drv <- driver_registry[[dbdir]] # We reuse an existing driver object if the database is still alive. # If not, we fall back to creating a new driver object with a new database. if (!is.null(drv) && rapi_lock(drv@database_ref)) { - # FIXME: Check that readonly and config are identical + # We don't care about different read_only or config settings here. + # The bigint setting can be actually picked up by dbConnect(), we update it here. + drv@bigint <- bigint return(drv) } } + # R packages are not allowed to write extensions into home directory, so use R_user_dir instead + if (!("extension_directory" %in% names(config))) { + config["extension_directory"] <- file.path(tools::R_user_dir("duckdb", "data"), "extensions") + } + if (!("secret_directory" %in% names(config))) { + config["secret_directory"] <- file.path(tools::R_user_dir("duckdb", "data"), "stored_secrets") + } + # Always create new database for in-memory, # allows isolation and mixing different configs drv <- new( diff --git a/R/dbConnect__duckdb_driver.R b/R/dbConnect__duckdb_driver.R index 50a30c61a..2307cc160 100644 --- a/R/dbConnect__duckdb_driver.R +++ b/R/dbConnect__duckdb_driver.R @@ -8,7 +8,10 @@ #' data is kept in RAM. #' @param ... Ignored #' @param debug Print additional debug information such as queries -#' @param read_only Set to `TRUE` for read-only operation +#' @param read_only Set to `TRUE` for read-only operation. +#' For file-based databases, this is only applied when the database file is opened for the first time. +#' Subsequent connections (via the same `drv` object or a `drv` object pointing to the same path) +#' will silently ignore this flag. #' @param timezone_out The time zone returned to R, defaults to `"UTC"`, which #' is currently the only timezone supported by duckdb. #' If you want to display datetime values in the local timezone, @@ -18,7 +21,10 @@ #' is chosen, the timestamp will be returned as it would appear in the specified time zone. #' If `"force"` is chosen, the timestamp will have the same clock #' time as the timestamp in the database, but with the new time zone. -#' @param config Named list with DuckDB configuration flags +#' @param config Named list with DuckDB configuration flags, see +#' for the possible options. +#' These flags are only applied when the database object is instantiated. +#' Subsequent connections will silently ignore these flags. #' @param bigint How 64-bit integers should be returned. There are two options: `"numeric"` and `"integer64"`. #' If `"numeric"` is selected, bigint integers will be treated as double/numeric. #' If `"integer64"` is selected, bigint integers will be set to bit64 encoding. diff --git a/man/duckdb.Rd b/man/duckdb.Rd index fd2b57cd0..b1eea5de7 100644 --- a/man/duckdb.Rd +++ b/man/duckdb.Rd @@ -41,13 +41,19 @@ duckdb_adbc() directory in the file system. With the default (or \code{""}), all data is kept in RAM.} -\item{read_only}{Set to \code{TRUE} for read-only operation} +\item{read_only}{Set to \code{TRUE} for read-only operation. +For file-based databases, this is only applied when the database file is opened for the first time. +Subsequent connections (via the same \code{drv} object or a \code{drv} object pointing to the same path) +will silently ignore this flag.} \item{bigint}{How 64-bit integers should be returned. There are two options: \code{"numeric"} and \code{"integer64"}. If \code{"numeric"} is selected, bigint integers will be treated as double/numeric. If \code{"integer64"} is selected, bigint integers will be set to bit64 encoding.} -\item{config}{Named list with DuckDB configuration flags} +\item{config}{Named list with DuckDB configuration flags, see +\url{https://duckdb.org/docs/configuration/overview#configuration-reference} for the possible options. +These flags are only applied when the database object is instantiated. +Subsequent connections will silently ignore these flags.} \item{drv}{Object returned by \code{duckdb()}}