From 3e201eadc1ed755877314fef4a3d50e141a3d506 Mon Sep 17 00:00:00 2001 From: Anthony Sena Date: Thu, 22 Apr 2021 11:24:59 -0400 Subject: [PATCH] Support DB Connector v4 (#83) --- inst/shiny/CharybdisResultsExplorer/global.R | 34 +++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/inst/shiny/CharybdisResultsExplorer/global.R b/inst/shiny/CharybdisResultsExplorer/global.R index 0d5fc5d..3dd03d2 100644 --- a/inst/shiny/CharybdisResultsExplorer/global.R +++ b/inst/shiny/CharybdisResultsExplorer/global.R @@ -4,6 +4,8 @@ library(DatabaseConnector) source("DataPulls.R") connPool <- NULL # Will be initialized if using a DB +dbConnectorVersionStr <- as.character(utils::packageVersion("DatabaseConnector"))[[1]] +dbConnectorVersion <- as.integer(strsplit(dbConnectorVersionStr, split="[.]")[[1]][1]) # Cleanup the database connPool if it was created onStop(function() { @@ -54,14 +56,30 @@ dataFile <- shinySettings$dataFile suppressWarnings(rm("cohort", "cohortCount", "database")) if (dataStorage == "database") { - connPool <- dbPool( - drv = DatabaseConnector::DatabaseConnectorDriver(), - dbms = shinySettings$connectionDetails$dbms, - server = shinySettings$connectionDetails$server, - port = shinySettings$connectionDetails$port, - user = shinySettings$connectionDetails$user, - password = shinySettings$connectionDetails$password - ) + # This is a hack to allow for users to run the Shiny app using + # the v3.x version of DB connector while also supporting the + # v4 driver that is now installed on data.ohdsi.org + if (dbConnectorVersion <= 3) { + # DatabaseConnector v3.x or less + connPool <- dbPool( + drv = DatabaseConnector::DatabaseConnectorDriver(), + dbms = shinySettings$connectionDetails$dbms, + server = shinySettings$connectionDetails$server, + port = shinySettings$connectionDetails$port, + user = shinySettings$connectionDetails$user, + password = shinySettings$connectionDetails$password + ) + } else { + # DatabaseConnector v4.x or higher + connPool <- dbPool( + drv = DatabaseConnector::DatabaseConnectorDriver(), + dbms = shinySettings$connectionDetails$dbms, + server = shinySettings$connectionDetails$server(), + port = shinySettings$connectionDetails$port(), + user = shinySettings$connectionDetails$user(), + password = shinySettings$connectionDetails$password() + ) + } loadDataFromDB(connPool) } else if (dataStorage == "s3") { fileExists <- aws.s3::head_object(dataFile, bucket = dataFolder)