From 0ea4fd7dc9b932cdfef00fd8fa7d90c587360587 Mon Sep 17 00:00:00 2001 From: Will Beasley Date: Thu, 7 Oct 2021 23:38:12 -0500 Subject: [PATCH] remove more RODBC reference ref #117 --- R/dx-upload-sql-server.R | 62 --------------------------------------- R/retrieve-key-value.R | 15 ++-------- man/retrieve_key_value.Rd | 4 +-- 3 files changed, 4 insertions(+), 77 deletions(-) diff --git a/R/dx-upload-sql-server.R b/R/dx-upload-sql-server.R index 08facae..f9a9a88 100644 --- a/R/dx-upload-sql-server.R +++ b/R/dx-upload-sql-server.R @@ -1,16 +1,3 @@ -retrieve_column_info <- function(dsn_name, table_name) { - warning("`OuhscMunge::retrieve_column_info()` is deprecated and will be removed in the future. Please create a GitHub issue if this is a problem, or post to https://github.com/OuhscBbmc/OuhscMunge/issues/117.") - tryCatch(expr = { - channel <- RODBC::odbcConnect(dsn_name) - RODBC::getSqlTypeInfo("Microsoft SQL Server") - RODBC::odbcGetInfo(channel) - d_column_info <- RODBC::sqlColumns(channel, table_name) - }, - finally = RODBC::odbcClose(channel) - ) - d_column_info -} - validate_column_names <- function(dsn_name, table_name, d) { # See if the names match exactly. d_column_info <- retrieve_column_info(dsn_name, table_name) @@ -56,52 +43,3 @@ validate_character_length <- function(dsn_name, table_name, d) { violation_possible = (!as.logical(d_column_info$COLUMN_SIZE) & vapply(d, function(x) max(nchar(x)), numeric(1))) ) } - -# - - -### Upload Visit Records to SQL Server -############################# -# sapply(ds, function(x) max(nchar(x))) -# dput(colnames(ds)) - - -# startTime <- base::Sys.time() -# dbTable <- "Osdh.tblC1ClientActivity" -# channel <- RODBC::odbcConnect("MiechvEvaluation") -# RODBC::getSqlTypeInfo("Microsoft SQL Server") -# RODBC::odbcGetInfo(channel) -# columnInfo <- RODBC::sqlColumns(channel, dbTable) -# varTypes <- as.character(columnInfo$TYPE_NAME) -# names(varTypes) <- as.character(columnInfo$COLUMN_NAME) #varTypes -# RODBC::sqlSave(channel, dsSlim, dbTable, append=TRUE, rownames=FALSE, fast=TRUE, varTypes=varTypes) -# RODBC::odbcClose(channel) -# (elapsedDuration <- Sys.time() - startTime) # 0.519052 secs 2013-10-27 -# -# #Visually inspect the dataset you're trying to upload -# head(dsSlim, 15) -# summary(dsSlim) -# -# # #See if the names match exactly -# # data.frame(DBColumnName = as.character(columnInfo$COLUMN_NAME), -# # DFVariableName = colnames(dsSlim), -# # Violation = (colnames(dsSlim)!=as.character(columnInfo$COLUMN_NAME)) -# # ) -# -# # #See if the there's a violoation of nulls -# # data.frame(ColumnName = colnames(dsSlim), -# # DBAllowsNulls = as.logical(columnInfo$NULLABLE), -# # DFHasNulls = sapply(dsSlim, function(x) { any(is.na(x)) }), -# # Violation = (!as.logical(columnInfo$NULLABLE) & sapply(dsSlim, function(x) { any(is.na(x)) })) -# # ) -# -# #See if types are consistent -# data.frame(DBType=varTypes, DFType=sapply(dsSlim, class)) -# -# #See if the there's a violoation of characters being too long. This only works for strings, not dates or numbers -# data.frame(ColumnName = colnames(dsSlim), -# DBType = varTypes, -# DBMaxSize = columnInfo$COLUMN_SIZE, -# DFMaxSize = sapply(dsSlim, function(x) { max(nchar(x)) }), -# PossibleViolation = (!as.logical(columnInfo$COLUMN_SIZE) & sapply(dsSlim, function(x) { max(nchar(x)) })) -# ) diff --git a/R/retrieve-key-value.R b/R/retrieve-key-value.R index 3bb4a20..87e1d45 100644 --- a/R/retrieve-key-value.R +++ b/R/retrieve-key-value.R @@ -6,8 +6,8 @@ #' #' @param key The key associated with the desired value. Required character vector with one element #' @param project_name The project name associated with the desired value. Required character vector with one element -#' @param dsn_name Name of the locally-defined DSN passed to [RODBC::odbcConnect()](RODBC::odbcConnect()). -#' @param channel An *optional* connection handle as returned by [RODBC::odbcConnect()]. See Details below. Optional. +#' @param dsn_name Name of the locally-defined DSN passed to [DBI::dbConnect()]. +#' @param channel An *optional* connection handle as returned by [DBI::dbConnect()]. See Details below. Optional. #' @return A `character` vector with one element. #' #' @details @@ -57,10 +57,6 @@ retrieve_key_value <- function( if (!requireNamespace("odbc", quietly = TRUE)) stop("The function `retrieve_key_value()` cannot run if the `odbc` package is not installed. Please install it and try again.") - # if (!requireNamespace("RODBC", quietly = TRUE)) - # stop("The function `retrieve_key_value()` cannot run if the `RODBC` package is not installed. Please install it and try again.") - # if (!requireNamespace("RODBCext", quietly = TRUE)) - # stop("The function `retrieve_key_value()` cannot run if the `RODBCext` package is not installed. Please install it and try again.") sql <- "EXEC security.prc_key_value_static @project=?, @attribute = ?" @@ -93,13 +89,6 @@ retrieve_key_value <- function( if (close_channel_on_exit) DBI::dbDisconnect(channel) } ) - # base::tryCatch( - # expr = { - # ds_value <- RODBCext::sqlExecute(channel, sql, d_input, fetch = TRUE, stringsAsFactors = FALSE) - # }, finally = { - # if (close_channel_on_exit) RODBC::odbcClose(channel) - # } - # ) if (nrow(ds_value) == 0L) { stop("No row was found with the desired [key]-by-[project_name] combination.") diff --git a/man/retrieve_key_value.Rd b/man/retrieve_key_value.Rd index 45789cc..e1cfd70 100644 --- a/man/retrieve_key_value.Rd +++ b/man/retrieve_key_value.Rd @@ -11,9 +11,9 @@ retrieve_key_value(key, project_name, dsn_name, channel = NULL) \item{project_name}{The project name associated with the desired value. Required character vector with one element} -\item{dsn_name}{Name of the locally-defined DSN passed to \url{RODBC::odbcConnect()}.} +\item{dsn_name}{Name of the locally-defined DSN passed to \code{\link[DBI:dbConnect]{DBI::dbConnect()}}.} -\item{channel}{An \emph{optional} connection handle as returned by \code{\link[RODBC:odbcConnect]{RODBC::odbcConnect()}}. See Details below. Optional.} +\item{channel}{An \emph{optional} connection handle as returned by \code{\link[DBI:dbConnect]{DBI::dbConnect()}}. See Details below. Optional.} } \value{ A \code{character} vector with one element.