From e0e00cb8d0e9f08b58d9854f2801b84f8aeff91a Mon Sep 17 00:00:00 2001 From: Will Beasley Date: Fri, 3 Nov 2023 18:56:10 -0500 Subject: [PATCH 1/2] better messages during db upload --- R/upload-sqls-odbc.R | 25 +++++++++++++++++-------- man/upload_sqls_odbc.Rd | 10 ++++++++-- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/R/upload-sqls-odbc.R b/R/upload-sqls-odbc.R index 3dcfebf..f1a7bbd 100644 --- a/R/upload-sqls-odbc.R +++ b/R/upload-sqls-odbc.R @@ -14,7 +14,10 @@ #' @param transaction Should the clear and upload steps be wrapped in a rollback transaction? #' @param timezone The server time zone. Passed to [DBI::dbConnect()]. #' @param timezone_out The time zone returned to R. Passed to [DBI::dbConnect()]. See https://www.tidyverse.org/blog/2019/12/odbc-1-2-0/. -#' @param verbose Write a message about the status of a successful upload. +#' @param verbose Display messages about the status of an upload. +#' @param verbose_detail Display a message about the connection's low-level details. +#' +#' @returns A boolean value that was returned by [DBI::dbWriteTable()]. #' #' @details #' If `transaction` is `TRUE` and the upload fails, the table is rolled back to the state before function was called. @@ -54,7 +57,8 @@ upload_sqls_odbc <- function( timezone_out = "UTC", transaction = FALSE, - verbose = TRUE + verbose = TRUE, + verbose_detail = FALSE ) { checkmate::assert_data_frame(d , null.ok=FALSE , any.missing=TRUE) @@ -69,9 +73,10 @@ upload_sqls_odbc <- function( checkmate::assert_character(timezone , len=1L, any.missing=FALSE) checkmate::assert_character(timezone_out , len=1L, any.missing=FALSE) checkmate::assert_logical( verbose , len=1L, any.missing=FALSE) + checkmate::assert_logical( verbose_detail , len=1L, any.missing=FALSE) start_time <- base::Sys.time() - print(start_time) + if (verbose) message ("Writing starting at ", strftime(start_time, "%F %T.")) if (convert_logical_to_integer) { d <- dplyr::mutate_if(d, is.logical, as.integer) @@ -123,8 +128,9 @@ upload_sqls_odbc <- function( DBI::dbBegin(channel) } - if (verbose) { - DBI::dbGetInfo(channel) + if (verbose_detail) { + # browser() + print(DBI::dbGetInfo(channel)) } # Check the *qualified* table exists. @@ -162,20 +168,22 @@ upload_sqls_odbc <- function( } if (verbose) { - message(result) + # message("Writing result: ", result) message( sprintf( - "The table `%s.%s` had %s rows written over dsn `%s` in %0.3f minutes.", + "The table `%s.%s` had %s rows written over dsn `%s` in %0.3f minutes at %s.", schema_name, table_name, format(nrow(d), big.mark = ",", scientific = FALSE), dsn_name, - difftime(Sys.time(), start_time, units = "mins") + difftime(Sys.time(), start_time, units = "mins"), + strftime(Sys.time(), "%F %T") ) ) } + invisible(result) }, error = function(e) { if (transaction) { @@ -191,5 +199,6 @@ upload_sqls_odbc <- function( if (exists("result_truncate")) suppressWarnings(DBI::dbClearResult(result_truncate)) # A warning message is produced if it was already cleared above. + }) } diff --git a/man/upload_sqls_odbc.Rd b/man/upload_sqls_odbc.Rd index 1af5397..a967334 100644 --- a/man/upload_sqls_odbc.Rd +++ b/man/upload_sqls_odbc.Rd @@ -15,7 +15,8 @@ upload_sqls_odbc( timezone = "UTC", timezone_out = "UTC", transaction = FALSE, - verbose = TRUE + verbose = TRUE, + verbose_detail = FALSE ) } \arguments{ @@ -39,7 +40,12 @@ upload_sqls_odbc( \item{transaction}{Should the clear and upload steps be wrapped in a rollback transaction?} -\item{verbose}{Write a message about the status of a successful upload.} +\item{verbose}{Display messages about the status of an upload.} + +\item{verbose_detail}{Display a message about the connection's low-level details.} +} +\value{ +A boolean value that was returned by \code{\link[DBI:dbWriteTable]{DBI::dbWriteTable()}}. } \description{ The function performs some extra configuration to improve robustness. From beb6450fc36c32bacccc49410b60e48408904768 Mon Sep 17 00:00:00 2001 From: Will Beasley Date: Thu, 14 Dec 2023 17:21:40 -0600 Subject: [PATCH 2/2] re-introduce the binding I'm not sure why it was turned off --- DESCRIPTION | 2 +- R/retrieve-key-value.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index be1026a..9ea3a2b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: OuhscMunge Title: Data Manipulation Operations Description: Data manipulation operations frequently used in OUHSC BBMC projects. -Version: 0.2.0.9015 +Version: 0.2.0.9016 Authors@R: person("Will", "Beasley", email="wibeasley@hotmail.com", role=c("aut", "cre"), comment = c(ORCID = "0000-0002-5613-5006")) URL: https://github.com/OuhscBbmc/OuhscMunge, http://ouhsc.edu/bbmc/ diff --git a/R/retrieve-key-value.R b/R/retrieve-key-value.R index 7280990..87e3f65 100644 --- a/R/retrieve-key-value.R +++ b/R/retrieve-key-value.R @@ -74,7 +74,7 @@ retrieve_key_value <- function( base::tryCatch( expr = { query <- DBI::dbSendQuery(channel, sql) - # bind <- DBI::dbBind(query, list(project_name, key)) + bind <- DBI::dbBind(query, list(project_name, key)) ds_value <- DBI::dbFetch(query) }, finally = {