Skip to content

Commit

Permalink
remove more RODBC reference
Browse files Browse the repository at this point in the history
ref #117
  • Loading branch information
wibeasley committed Oct 8, 2021
1 parent fecf2a6 commit 0ea4fd7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 77 deletions.
62 changes: 0 additions & 62 deletions R/dx-upload-sql-server.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)) }))
# )
15 changes: 2 additions & 13 deletions R/retrieve-key-value.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = ?"

Expand Down Expand Up @@ -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.")
Expand Down
4 changes: 2 additions & 2 deletions man/retrieve_key_value.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0ea4fd7

Please sign in to comment.