diff --git a/.github/workflows/R_CMD_check_Hades.yaml b/.github/workflows/R_CMD_check_Hades.yaml index b38e5642..79cf8773 100644 --- a/.github/workflows/R_CMD_check_Hades.yaml +++ b/.github/workflows/R_CMD_check_Hades.yaml @@ -28,22 +28,22 @@ jobs: GITHUB_PAT: ${{ secrets.GH_TOKEN }} R_REMOTES_NO_ERRORS_FROM_WARNINGS: true RSPM: ${{ matrix.config.rspm }} - CDM5_ORACLE_CDM_SCHEMA: ${{ secrets.CDM5_ORACLE_CDM_SCHEMA }} + CDM5_ORACLE_CDM54_SCHEMA: ${{ secrets.CDM5_ORACLE_CDM54_SCHEMA }} CDM5_ORACLE_OHDSI_SCHEMA: ${{ secrets.CDM5_ORACLE_OHDSI_SCHEMA }} CDM5_ORACLE_PASSWORD: ${{ secrets.CDM5_ORACLE_PASSWORD }} CDM5_ORACLE_SERVER: ${{ secrets.CDM5_ORACLE_SERVER }} CDM5_ORACLE_USER: ${{ secrets.CDM5_ORACLE_USER }} - CDM5_POSTGRESQL_CDM_SCHEMA: ${{ secrets.CDM5_POSTGRESQL_CDM_SCHEMA }} + CDM5_POSTGRESQL_CDM54_SCHEMA: ${{ secrets.CDM5_POSTGRESQL_CDM54_SCHEMA }} CDM5_POSTGRESQL_OHDSI_SCHEMA: ${{ secrets.CDM5_POSTGRESQL_OHDSI_SCHEMA }} CDM5_POSTGRESQL_PASSWORD: ${{ secrets.CDM5_POSTGRESQL_PASSWORD }} CDM5_POSTGRESQL_SERVER: ${{ secrets.CDM5_POSTGRESQL_SERVER }} CDM5_POSTGRESQL_USER: ${{ secrets.CDM5_POSTGRESQL_USER }} - CDM5_SQL_SERVER_CDM_SCHEMA: ${{ secrets.CDM5_SQL_SERVER_CDM_SCHEMA }} + CDM5_SQL_SERVER_CDM54_SCHEMA: ${{ secrets.CDM5_SQL_SERVER_CDM54_SCHEMA }} CDM5_SQL_SERVER_OHDSI_SCHEMA: ${{ secrets.CDM5_SQL_SERVER_OHDSI_SCHEMA }} CDM5_SQL_SERVER_PASSWORD: ${{ secrets.CDM5_SQL_SERVER_PASSWORD }} CDM5_SQL_SERVER_SERVER: ${{ secrets.CDM5_SQL_SERVER_SERVER }} CDM5_SQL_SERVER_USER: ${{ secrets.CDM5_SQL_SERVER_USER }} - CDM5_REDSHIFT_CDM_SCHEMA: ${{ secrets.CDM5_REDSHIFT_CDM_SCHEMA }} + CDM5_REDSHIFT_CDM54_SCHEMA: ${{ secrets.CDM5_REDSHIFT_CDM54_SCHEMA }} CDM5_REDSHIFT_OHDSI_SCHEMA: ${{ secrets.CDM5_REDSHIFT_OHDSI_SCHEMA }} CDM5_REDSHIFT_PASSWORD: ${{ secrets.CDM5_REDSHIFT_PASSWORD }} CDM5_REDSHIFT_SERVER: ${{ secrets.CDM5_REDSHIFT_SERVER }} @@ -52,10 +52,16 @@ jobs: CDM_SNOWFLAKE_OHDSI_SCHEMA: ${{ secrets.CDM_SNOWFLAKE_OHDSI_SCHEMA }} CDM_SNOWFLAKE_PASSWORD: ${{ secrets.CDM_SNOWFLAKE_PASSWORD }} CDM_SNOWFLAKE_CONNECTION_STRING: ${{ secrets.CDM_SNOWFLAKE_CONNECTION_STRING }} - CDM_SNOWFLAKE_USER: ${{ secrets.CDM_SNOWFLAKE_USER }} + CDM_SNOWFLAKE_USER: ${{ secrets.CDM_SNOWFLAKE_USER }} CDM5_SPARK_USER: ${{ secrets.CDM5_SPARK_USER }} CDM5_SPARK_PASSWORD: ${{ secrets.CDM5_SPARK_PASSWORD }} CDM5_SPARK_CONNECTION_STRING: ${{ secrets.CDM5_SPARK_CONNECTION_STRING }} + CDM5_SPARK_CDM_SCHEMA: ${{ secrets.CDM5_SPARK_CDM_SCHEMA }} + CDM5_SPARK_OHDSI_SCHEMA: ${{ secrets.CDM5_SPARK_OHDSI_SCHEMA }} + CDM_BIG_QUERY_CONNECTION_STRING: ${{ secrets.CDM_BIG_QUERY_CONNECTION_STRING }} + CDM_BIG_QUERY_KEY_FILE: ${{ secrets.CDM_BIG_QUERY_KEY_FILE }} + CDM_BIG_QUERY_CDM_SCHEMA: ${{ secrets.CDM_BIG_QUERY_CDM_SCHEMA }} + CDM_BIG_QUERY_OHDSI_SCHEMA: ${{ secrets.CDM_BIG_QUERY_OHDSI_SCHEMA }} steps: - uses: actions/checkout@v3 @@ -174,4 +180,3 @@ jobs: if: ${{ env.new_version != '' }} run: | curl --data "build=true" -X POST https://registry.hub.docker.com/u/ohdsi/broadsea-methodslibrary/trigger/f0b51cec-4027-4781-9383-4b38b42dd4f5/ - diff --git a/.github/workflows/R_CMD_check_main_weekly.yaml b/.github/workflows/R_CMD_check_main_weekly.yaml index f12ecd0f..4c5e0751 100644 --- a/.github/workflows/R_CMD_check_main_weekly.yaml +++ b/.github/workflows/R_CMD_check_main_weekly.yaml @@ -20,22 +20,22 @@ jobs: GITHUB_PAT: ${{ secrets.GH_TOKEN }} R_REMOTES_NO_ERRORS_FROM_WARNINGS: true RSPM: ${{ matrix.config.rspm }} - CDM5_ORACLE_CDM_SCHEMA: ${{ secrets.CDM5_ORACLE_CDM_SCHEMA }} + CDM5_ORACLE_CDM54_SCHEMA: ${{ secrets.CDM5_ORACLE_CDM54_SCHEMA }} CDM5_ORACLE_OHDSI_SCHEMA: ${{ secrets.CDM5_ORACLE_OHDSI_SCHEMA }} CDM5_ORACLE_PASSWORD: ${{ secrets.CDM5_ORACLE_PASSWORD }} CDM5_ORACLE_SERVER: ${{ secrets.CDM5_ORACLE_SERVER }} CDM5_ORACLE_USER: ${{ secrets.CDM5_ORACLE_USER }} - CDM5_POSTGRESQL_CDM_SCHEMA: ${{ secrets.CDM5_POSTGRESQL_CDM_SCHEMA }} + CDM5_POSTGRESQL_CDM54_SCHEMA: ${{ secrets.CDM5_POSTGRESQL_CDM54_SCHEMA }} CDM5_POSTGRESQL_OHDSI_SCHEMA: ${{ secrets.CDM5_POSTGRESQL_OHDSI_SCHEMA }} CDM5_POSTGRESQL_PASSWORD: ${{ secrets.CDM5_POSTGRESQL_PASSWORD }} CDM5_POSTGRESQL_SERVER: ${{ secrets.CDM5_POSTGRESQL_SERVER }} CDM5_POSTGRESQL_USER: ${{ secrets.CDM5_POSTGRESQL_USER }} - CDM5_SQL_SERVER_CDM_SCHEMA: ${{ secrets.CDM5_SQL_SERVER_CDM_SCHEMA }} + CDM5_SQL_SERVER_CDM54_SCHEMA: ${{ secrets.CDM5_SQL_SERVER_CDM54_SCHEMA }} CDM5_SQL_SERVER_OHDSI_SCHEMA: ${{ secrets.CDM5_SQL_SERVER_OHDSI_SCHEMA }} CDM5_SQL_SERVER_PASSWORD: ${{ secrets.CDM5_SQL_SERVER_PASSWORD }} CDM5_SQL_SERVER_SERVER: ${{ secrets.CDM5_SQL_SERVER_SERVER }} CDM5_SQL_SERVER_USER: ${{ secrets.CDM5_SQL_SERVER_USER }} - CDM5_REDSHIFT_CDM_SCHEMA: ${{ secrets.CDM5_REDSHIFT_CDM_SCHEMA }} + CDM5_REDSHIFT_CDM54_SCHEMA: ${{ secrets.CDM5_REDSHIFT_CDM54_SCHEMA }} CDM5_REDSHIFT_OHDSI_SCHEMA: ${{ secrets.CDM5_REDSHIFT_OHDSI_SCHEMA }} CDM5_REDSHIFT_PASSWORD: ${{ secrets.CDM5_REDSHIFT_PASSWORD }} CDM5_REDSHIFT_SERVER: ${{ secrets.CDM5_REDSHIFT_SERVER }} @@ -44,10 +44,12 @@ jobs: CDM_SNOWFLAKE_OHDSI_SCHEMA: ${{ secrets.CDM_SNOWFLAKE_OHDSI_SCHEMA }} CDM_SNOWFLAKE_PASSWORD: ${{ secrets.CDM_SNOWFLAKE_PASSWORD }} CDM_SNOWFLAKE_CONNECTION_STRING: ${{ secrets.CDM_SNOWFLAKE_CONNECTION_STRING }} - CDM_SNOWFLAKE_USER: ${{ secrets.CDM_SNOWFLAKE_USER }} + CDM_SNOWFLAKE_USER: ${{ secrets.CDM_SNOWFLAKE_USER }} CDM5_SPARK_USER: ${{ secrets.CDM5_SPARK_USER }} CDM5_SPARK_PASSWORD: ${{ secrets.CDM5_SPARK_PASSWORD }} CDM5_SPARK_CONNECTION_STRING: ${{ secrets.CDM5_SPARK_CONNECTION_STRING }} + CDM5_SPARK_CDM_SCHEMA: ${{ secrets.CDM5_SPARK_CDM_SCHEMA }} + CDM5_SPARK_OHDSI_SCHEMA: ${{ secrets.CDM5_SPARK_OHDSI_SCHEMA }} steps: - uses: actions/checkout@v3 @@ -69,4 +71,4 @@ jobs: with: args: 'c("--no-manual", "--as-cran")' error-on: '"warning"' - check-dir: '"check"' + check-dir: '"check"' \ No newline at end of file diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index 58f20b8d..6de6acd1 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ -Version: 6.2.4 -Date: 2023-09-07 07:52:51 UTC -SHA: 0275322b097fac96668c8804dd0acd8466c1442c +Version: 6.3.0 +Date: 2023-11-08 13:53:53 UTC +SHA: 105405047c12c144c4486ecfacb41d68a70be778 diff --git a/DESCRIPTION b/DESCRIPTION index 87e8351a..2b02b0c7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: DatabaseConnector Type: Package Title: Connecting to Various Database Platforms -Version: 6.2.4 -Date: 2023-09-07 +Version: 6.3.0 +Date: 2023-11-08 Authors@R: c( person("Martijn", "Schuemie", email = "schuemie@ohdsi.org", role = c("aut", "cre")), person("Marc", "Suchard", role = c("aut")), @@ -20,7 +20,7 @@ Depends: R (>= 4.0.0) Imports: rJava, - SqlRender (>= 1.15.2), + SqlRender (>= 1.16.0), methods, stringr, readr, diff --git a/NEWS.md b/NEWS.md index 5d419c41..d84e6c6b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,19 @@ +DatabaseConnector 6.3.0 +======================= + +Changes: + +1. On Snowflake always using `QUOTED_IDENTIFIERS_IGNORE_CASE=TRUE` to avoid name mismatches when using quotes. + +2. Updated Redshift drivers. + +3. Added unit tests for all supported platforms. + +Bugfixes: + +1. Fix bug on BigQuery where wait time was too short to avoid rate limit error. + + DatabaseConnector 6.2.4 ======================= diff --git a/R/Connect.R b/R/Connect.R index 481a3482..783aece6 100644 --- a/R/Connect.R +++ b/R/Connect.R @@ -34,6 +34,12 @@ checkIfDbmsIsSupported <- function(dbms) { "synapse", "duckdb" ) + deprecated <- c( + "hive", + "impala", + "netezza", + "pdw" + ) if (!dbms %in% supportedDbmss) { abort(sprintf( "DBMS '%s' not supported. Please use one of these values: '%s'", @@ -41,6 +47,17 @@ checkIfDbmsIsSupported <- function(dbms) { paste(supportedDbmss, collapse = "', '") )) } + if (dbms %in% deprecated) { + warn(sprintf( + paste(c("DBMS '%s' has been deprecated. Current functionality is provided as is.", + "No futher support will be provided.", + "Please consider switching to a different database platform."), + collapse = " "), + dbms), + .frequency = "regularly", + .frequency_id = "deprecated_dbms" + ) + } } checkDetailValidation <- function(connectionDetails, name) { @@ -484,8 +501,8 @@ connectPostgreSql <- function(connectionDetails) { connectRedShift <- function(connectionDetails) { inform("Connecting using Redshift driver") - jarPath <- findPathToJar("^RedshiftJDBC.*\\.jar$", connectionDetails$pathToDriver) - if (grepl("RedshiftJDBC42", jarPath)) { + jarPath <- findPathToJar("^[Rr]edshift.*\\.jar$", connectionDetails$pathToDriver) + if (grepl("RedshiftJDBC42", jarPath) || grepl("redshift-jdbc42", jarPath)) { driver <- getJbcDriverSingleton("com.amazon.redshift.jdbc42.Driver", jarPath) } else { driver <- getJbcDriverSingleton("com.amazon.redshift.jdbc4.Driver", jarPath) @@ -709,7 +726,8 @@ connectSnowflake <- function(connectionDetails) { user = connectionDetails$user(), password = connectionDetails$password(), dbms = connectionDetails$dbms, - "CLIENT_TIMESTAMP_TYPE_MAPPING"="TIMESTAMP_NTZ" + "CLIENT_TIMESTAMP_TYPE_MAPPING"="TIMESTAMP_NTZ", + "QUOTED_IDENTIFIERS_IGNORE_CASE"="TRUE" ) } return(connection) diff --git a/R/DBI.R b/R/DBI.R index e2b2e5fd..6cfbfbb2 100644 --- a/R/DBI.R +++ b/R/DBI.R @@ -455,7 +455,7 @@ setMethod( ) } rowsAffected <- executeSql(connection = conn, sql = statement) - rowsAffected <- rJava::.jnew("java/lang/Integer", as.integer(rowsAffected)) + rowsAffected <- rJava::.jnew("java/lang/Double", as.double(sum(rowsAffected))) result <- new("DatabaseConnectorJdbcResult", content = rowsAffected, type = "rowsAffected", diff --git a/R/Drivers.R b/R/Drivers.R index 485407a9..74d5aa36 100644 --- a/R/Drivers.R +++ b/R/Drivers.R @@ -91,7 +91,7 @@ downloadJdbcDrivers <- function(dbms, pathToDriver = Sys.getenv("DATABASECONNECT jdbcDriverSources <- utils::read.csv(text = "row,dbms, fileName, baseUrl 1,postgresql,postgresqlV42.2.18.zip,https://ohdsi.github.io/DatabaseConnectorJars/ - 2,redshift,redShiftV2.1.0.9.zip,https://ohdsi.github.io/DatabaseConnectorJars/ + 2,redshift,redshift-jdbc42-2.1.0.20.zip,https://s3.amazonaws.com/redshift-downloads/drivers/jdbc/2.1.0.20/ 3,sql server,sqlServerV9.2.0.zip,https://ohdsi.github.io/DatabaseConnectorJars/ 4,oracle,oracleV19.8.zip,https://ohdsi.github.io/DatabaseConnectorJars/ 5,spark,DatabricksJDBC42-2.6.32.1054.zip,https://databricks-bi-artifacts.s3.us-east-2.amazonaws.com/simbaspark-drivers/jdbc/2.6.32/ @@ -162,7 +162,7 @@ getJbcDriverSingleton <- function(driverClass = "", classPath = "") { } checkPathToDriver <- function(pathToDriver, dbms) { - if (!is.null(dbms) && dbms %in% c("sqlite", "sqlite extended")) { + if (!is.null(dbms) && dbms %in% c("sqlite", "sqlite extended", "duckdb")) { return() } if (pathToDriver == "") { diff --git a/R/Sql.R b/R/Sql.R index b5905ecb..7453de77 100644 --- a/R/Sql.R +++ b/R/Sql.R @@ -255,44 +255,33 @@ lowLevelExecuteSql <- function(connection, sql) { UseMethod("lowLevelExecuteSql", connection) } -delayIfNecessary <- function(sql, regex, executionTimeList, threshold) { +ddlExecutionTimes <- new.env() +insertExecutionTimes <- new.env() + +delayIfNecessary <- function(sql, regex, executionTimes, threshold) { regexGroups <- stringr::str_match(sql, stringr::regex(regex, ignore_case = TRUE)) tableName <- regexGroups[3] if (!is.na(tableName) && !is.null(tableName)) { currentTime <- Sys.time() - lastExecutedTime <- executionTimeList[[tableName]] + lastExecutedTime <- executionTimes[[tableName]] if (!is.na(lastExecutedTime) && !is.null(lastExecutedTime)) { - delta <- currentTime - lastExecutedTime + delta <- difftime(currentTime, lastExecutedTime, units = "secs") if (delta < threshold) { Sys.sleep(threshold - delta) } } - - executionTimeList[[tableName]] <- currentTime + executionTimes[[tableName]] <- currentTime } - return(executionTimeList) } delayIfNecessaryForDdl <- function(sql) { - ddlList <- getOption("ddlList") - if (is.null(ddlList)) { - ddlList <- list() - } - regexForDdl <- "(^CREATE\\s+TABLE\\s+IF\\s+EXISTS|^CREATE\\s+TABLE|^DROP\\s+TABLE\\s+IF\\s+EXISTS|^DROP\\s+TABLE)\\s+([a-zA-Z0-9_$#-]*\\.?\\s*(?:[a-zA-Z0-9_]+)*)" - updatedList <- delayIfNecessary(sql, regexForDdl, ddlList, 5) - options(ddlList = updatedList) + delayIfNecessary(sql, regexForDdl, ddlExecutionTimes, 5) } delayIfNecessaryForInsert <- function(sql) { - insetList <- getOption("insetList") - if (is.null(insetList)) { - insetList <- list() - } - regexForInsert <- "(^INSERT\\s+INTO)\\s+([a-zA-Z0-9_$#-]*\\.?\\s*(?:[a-zA-Z0-9_]+)*)" - updatedList <- delayIfNecessary(sql, regexForInsert, insetList, 5) - options(insetList = updatedList) + delayIfNecessary(sql, regexForInsert, insertExecutionTimes, 5) } #' @export @@ -302,18 +291,23 @@ lowLevelExecuteSql.default <- function(connection, sql) { statement <- rJava::.jcall(connection@jConnection, "Ljava/sql/Statement;", "createStatement") on.exit(rJava::.jcall(statement, "V", "close")) - hasResultSet <- rJava::.jcall(statement, "Z", "execute", as.character(sql), check = FALSE) + if (dbms(connection) == "spark") { + # For some queries the DataBricks JDBC driver will throw an error saying no ROWCOUNT is returned + # when using executeLargeUpdate, so using execute instead. + rJava::.jcall(statement, "Z", "execute", as.character(sql), check = FALSE) + rowsAffected <- rJava::.jcall(statement, "I", "getUpdateCount", check = FALSE) + if (rowsAffected == -1) { + rowsAffected <- 0 + } + } else { + rowsAffected <- rJava::.jcall(statement, "J", "executeLargeUpdate", as.character(sql), check = FALSE) + } if (dbms(connection) == "bigquery") { delayIfNecessaryForDdl(sql) delayIfNecessaryForInsert(sql) } - rowsAffected <- 0 - if (!hasResultSet) { - rowsAffected <- rJava::.jcall(statement, "I", "getUpdateCount", check = FALSE) - } - delta <- Sys.time() - startTime logTrace(paste("Executing SQL took", delta, attr(delta, "units"))) invisible(rowsAffected) @@ -421,9 +415,9 @@ executeSql <- function(connection, batched <- runAsBatch && supportsBatchUpdates(connection) sqlStatements <- SqlRender::splitSql(sql) + rowsAffected <- c() if (batched) { batchSize <- 1000 - rowsAffected <- 0 for (start in seq(1, length(sqlStatements), by = batchSize)) { end <- min(start + batchSize - 1, length(sqlStatements)) @@ -441,7 +435,7 @@ executeSql <- function(connection, tryCatch( { startQuery <- Sys.time() - rowsAffected <- c(rowsAffected, rJava::.jcall(statement, "[I", "executeBatch")) + rowsAffected <- c(rowsAffected, rJava::.jcall(statement, "[J", "executeLargeBatch")) delta <- Sys.time() - startQuery if (profile) { inform(paste("Statements", start, "through", end, "took", delta, attr(delta, "units"))) @@ -471,7 +465,7 @@ executeSql <- function(connection, tryCatch( { startQuery <- Sys.time() - lowLevelExecuteSql(connection, sqlStatement) + rowsAffected <- c(rowsAffected, lowLevelExecuteSql(connection, sqlStatement)) delta <- Sys.time() - startQuery if (profile) { inform(paste("Statement ", i, "took", delta, attr(delta, "units"))) @@ -498,9 +492,7 @@ executeSql <- function(connection, delta <- Sys.time() - startTime inform(paste("Executing SQL took", signif(delta, 3), attr(delta, "units"))) } - if (batched) { invisible(rowsAffected) - } } convertFields <- function(dbms, result) { diff --git a/cran-comments.md b/cran-comments.md index ad55f89e..123fd033 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,4 +1,4 @@ -This update includes 1 changes and 2 bugfixes, including the fix requested by Prof. Hornik. (see NEWS.md). +This update includes 3 changes and 1 bugfixes. (see NEWS.md). --- @@ -14,4 +14,4 @@ There were no ERRORs or WARNINGs. ## Downstream dependencies -DatabaseConnector is used by CDMConnector, which was tested with this new version. No issues were found. \ No newline at end of file +DatabaseConnector is used by Achilles, CohortAlgebra, CohortExplorer, TreatmentPatterns, and CDMConnector, which were tested with this new version. No issues were found. \ No newline at end of file diff --git a/docs/404.html b/docs/404.html index 73b89288..da23bf91 100644 --- a/docs/404.html +++ b/docs/404.html @@ -32,7 +32,7 @@
diff --git a/docs/articles/Connecting.html b/docs/articles/Connecting.html index 8385f4c1..830a00b6 100644 --- a/docs/articles/Connecting.html +++ b/docs/articles/Connecting.html @@ -33,7 +33,7 @@ @@ -91,7 +91,7 @@vignettes/Connecting.Rmd
Connecting.Rmd
## Inserting data took 0.0521 secs
+## Inserting data took 0.0571 secs
querySql(conn, "SELECT COUNT(*) FROM main.cars;")
## COUNT(*)
diff --git a/docs/articles/DbiAndDbplyr.html b/docs/articles/DbiAndDbplyr.html
index 139a4d0d..f80c8cdb 100644
--- a/docs/articles/DbiAndDbplyr.html
+++ b/docs/articles/DbiAndDbplyr.html
@@ -33,7 +33,7 @@
@@ -92,7 +92,7 @@ Using DatabaseConnector through DBI and
Martijn J.
Schuemie
- 2023-09-07
+ 2023-11-08
Source: vignettes/DbiAndDbplyr.Rmd
DbiAndDbplyr.Rmd
diff --git a/docs/articles/Querying.html b/docs/articles/Querying.html
index bb43aa57..89701c20 100644
--- a/docs/articles/Querying.html
+++ b/docs/articles/Querying.html
@@ -33,7 +33,7 @@
@@ -91,7 +91,7 @@ Querying a database
Martijn J.
Schuemie
- 2023-09-07
+ 2023-11-08
Source: vignettes/Querying.Rmd
Querying.Rmd
diff --git a/docs/articles/index.html b/docs/articles/index.html
index 2986d96e..d7b8e32b 100644
--- a/docs/articles/index.html
+++ b/docs/articles/index.html
@@ -17,7 +17,7 @@
diff --git a/docs/authors.html b/docs/authors.html
index 95203a33..70d79724 100644
--- a/docs/authors.html
+++ b/docs/authors.html
@@ -17,7 +17,7 @@
diff --git a/docs/index.html b/docs/index.html
index b6624d43..4f2f28cf 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -35,7 +35,7 @@
diff --git a/docs/news/index.html b/docs/news/index.html
index d5e51dda..a12defec 100644
--- a/docs/news/index.html
+++ b/docs/news/index.html
@@ -17,7 +17,7 @@
@@ -67,7 +67,16 @@ Changelog
-DatabaseConnector 6.2.4
+DatabaseConnector 6.3.0
+Changes:
+On Snowflake always using QUOTED_IDENTIFIERS_IGNORE_CASE=TRUE
to avoid name mismatches when using quotes.
+Updated Redshift drivers.
+Added unit tests for all supported platforms.
+
Bugfixes:
+- Fix bug on BigQuery where wait time was too short to avoid rate limit error.
+
+
+DatabaseConnector 6.2.42023-09-07
Changes:
- The
DatabaseConnectorConnection
class is now defined at runtime, preventing the “Found more than one class ‘Microsoft SQL Server’” error when using the odbc
package while DatabaseConnector
is installed.
Bugfixes:
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml
index ef6b0e5f..b0a3c684 100644
--- a/docs/pkgdown.yml
+++ b/docs/pkgdown.yml
@@ -5,5 +5,5 @@ articles:
Connecting: Connecting.html
DbiAndDbplyr: DbiAndDbplyr.html
Querying: Querying.html
-last_built: 2023-09-07T04:23Z
+last_built: 2023-11-08T13:18Z
diff --git a/docs/pull_request_template.html b/docs/pull_request_template.html
index a216f966..edc816be 100644
--- a/docs/pull_request_template.html
+++ b/docs/pull_request_template.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/DatabaseConnector-package.html b/docs/reference/DatabaseConnector-package.html
index 51b5a18f..36dc0b7e 100644
--- a/docs/reference/DatabaseConnector-package.html
+++ b/docs/reference/DatabaseConnector-package.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/DatabaseConnectorDbiResult-class.html b/docs/reference/DatabaseConnectorDbiResult-class.html
index 5c8e02f4..4f81b4ff 100644
--- a/docs/reference/DatabaseConnectorDbiResult-class.html
+++ b/docs/reference/DatabaseConnectorDbiResult-class.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/DatabaseConnectorDriver-class.html b/docs/reference/DatabaseConnectorDriver-class.html
index 1c193aa3..54407e61 100644
--- a/docs/reference/DatabaseConnectorDriver-class.html
+++ b/docs/reference/DatabaseConnectorDriver-class.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/DatabaseConnectorDriver.html b/docs/reference/DatabaseConnectorDriver.html
index bd5813cf..d38dd784 100644
--- a/docs/reference/DatabaseConnectorDriver.html
+++ b/docs/reference/DatabaseConnectorDriver.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/DatabaseConnectorJdbcResult-class.html b/docs/reference/DatabaseConnectorJdbcResult-class.html
index 65fb7876..640494bf 100644
--- a/docs/reference/DatabaseConnectorJdbcResult-class.html
+++ b/docs/reference/DatabaseConnectorJdbcResult-class.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/assertTempEmulationSchemaSet.html b/docs/reference/assertTempEmulationSchemaSet.html
index 7bd4365c..e12be44b 100644
--- a/docs/reference/assertTempEmulationSchemaSet.html
+++ b/docs/reference/assertTempEmulationSchemaSet.html
@@ -19,7 +19,7 @@
diff --git a/docs/reference/computeDataHash.html b/docs/reference/computeDataHash.html
index 73822767..d4bec885 100644
--- a/docs/reference/computeDataHash.html
+++ b/docs/reference/computeDataHash.html
@@ -19,7 +19,7 @@
diff --git a/docs/reference/connect.html b/docs/reference/connect.html
index 3f5ff767..60a1c286 100644
--- a/docs/reference/connect.html
+++ b/docs/reference/connect.html
@@ -152,7 +152,7 @@
diff --git a/docs/reference/createConnectionDetails.html b/docs/reference/createConnectionDetails.html
index 1855e440..672f7a84 100644
--- a/docs/reference/createConnectionDetails.html
+++ b/docs/reference/createConnectionDetails.html
@@ -151,7 +151,7 @@
diff --git a/docs/reference/createDbiConnectionDetails.html b/docs/reference/createDbiConnectionDetails.html
index 6d9a1f7b..1efc90c3 100644
--- a/docs/reference/createDbiConnectionDetails.html
+++ b/docs/reference/createDbiConnectionDetails.html
@@ -19,7 +19,7 @@
diff --git a/docs/reference/createZipFile.html b/docs/reference/createZipFile.html
index 0ad540e8..241c64ea 100644
--- a/docs/reference/createZipFile.html
+++ b/docs/reference/createZipFile.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/dateAdd.html b/docs/reference/dateAdd.html
index 28763fa9..e9f1cc25 100644
--- a/docs/reference/dateAdd.html
+++ b/docs/reference/dateAdd.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dateDiff.html b/docs/reference/dateDiff.html
index 0a654c48..9593d103 100644
--- a/docs/reference/dateDiff.html
+++ b/docs/reference/dateDiff.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dateFromParts.html b/docs/reference/dateFromParts.html
index 663cb60a..c01ab6d7 100644
--- a/docs/reference/dateFromParts.html
+++ b/docs/reference/dateFromParts.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/day.html b/docs/reference/day.html
index 217dfebc..8fcb040e 100644
--- a/docs/reference/day.html
+++ b/docs/reference/day.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbAppendTable-DatabaseConnectorConnection-character-method.html b/docs/reference/dbAppendTable-DatabaseConnectorConnection-character-method.html
index 6093ef3a..c8ef7e25 100644
--- a/docs/reference/dbAppendTable-DatabaseConnectorConnection-character-method.html
+++ b/docs/reference/dbAppendTable-DatabaseConnectorConnection-character-method.html
@@ -25,7 +25,7 @@
diff --git a/docs/reference/dbClearResult-DatabaseConnectorDbiResult-method.html b/docs/reference/dbClearResult-DatabaseConnectorDbiResult-method.html
index ea4f6517..5216204d 100644
--- a/docs/reference/dbClearResult-DatabaseConnectorDbiResult-method.html
+++ b/docs/reference/dbClearResult-DatabaseConnectorDbiResult-method.html
@@ -19,7 +19,7 @@
diff --git a/docs/reference/dbClearResult-DatabaseConnectorJdbcResult-method.html b/docs/reference/dbClearResult-DatabaseConnectorJdbcResult-method.html
index e8bbe322..a9f6e186 100644
--- a/docs/reference/dbClearResult-DatabaseConnectorJdbcResult-method.html
+++ b/docs/reference/dbClearResult-DatabaseConnectorJdbcResult-method.html
@@ -19,7 +19,7 @@
diff --git a/docs/reference/dbColumnInfo-DatabaseConnectorDbiResult-method.html b/docs/reference/dbColumnInfo-DatabaseConnectorDbiResult-method.html
index 93ed55af..88182aae 100644
--- a/docs/reference/dbColumnInfo-DatabaseConnectorDbiResult-method.html
+++ b/docs/reference/dbColumnInfo-DatabaseConnectorDbiResult-method.html
@@ -20,7 +20,7 @@
diff --git a/docs/reference/dbColumnInfo-DatabaseConnectorJdbcResult-method.html b/docs/reference/dbColumnInfo-DatabaseConnectorJdbcResult-method.html
index cd1e4362..d76696ee 100644
--- a/docs/reference/dbColumnInfo-DatabaseConnectorJdbcResult-method.html
+++ b/docs/reference/dbColumnInfo-DatabaseConnectorJdbcResult-method.html
@@ -20,7 +20,7 @@
diff --git a/docs/reference/dbConnect-DatabaseConnectorDriver-method.html b/docs/reference/dbConnect-DatabaseConnectorDriver-method.html
index 45cc100e..28594da0 100644
--- a/docs/reference/dbConnect-DatabaseConnectorDriver-method.html
+++ b/docs/reference/dbConnect-DatabaseConnectorDriver-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbCreateTable-DatabaseConnectorConnection-method.html b/docs/reference/dbCreateTable-DatabaseConnectorConnection-method.html
index 2e81216e..1c6c7538 100644
--- a/docs/reference/dbCreateTable-DatabaseConnectorConnection-method.html
+++ b/docs/reference/dbCreateTable-DatabaseConnectorConnection-method.html
@@ -22,7 +22,7 @@
diff --git a/docs/reference/dbDisconnect-DatabaseConnectorConnection-method.html b/docs/reference/dbDisconnect-DatabaseConnectorConnection-method.html
index e5e4a112..d6c0be6e 100644
--- a/docs/reference/dbDisconnect-DatabaseConnectorConnection-method.html
+++ b/docs/reference/dbDisconnect-DatabaseConnectorConnection-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbExecute-DatabaseConnectorConnection-character-method.html b/docs/reference/dbExecute-DatabaseConnectorConnection-character-method.html
index 46ab80c1..294dcb9a 100644
--- a/docs/reference/dbExecute-DatabaseConnectorConnection-character-method.html
+++ b/docs/reference/dbExecute-DatabaseConnectorConnection-character-method.html
@@ -23,7 +23,7 @@
diff --git a/docs/reference/dbExistsTable-DatabaseConnectorConnection-character-method.html b/docs/reference/dbExistsTable-DatabaseConnectorConnection-character-method.html
index 30323292..61bd7a36 100644
--- a/docs/reference/dbExistsTable-DatabaseConnectorConnection-character-method.html
+++ b/docs/reference/dbExistsTable-DatabaseConnectorConnection-character-method.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/dbFetch-DatabaseConnectorDbiResult-method.html b/docs/reference/dbFetch-DatabaseConnectorDbiResult-method.html
index fdb75195..dbda3d88 100644
--- a/docs/reference/dbFetch-DatabaseConnectorDbiResult-method.html
+++ b/docs/reference/dbFetch-DatabaseConnectorDbiResult-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbFetch-DatabaseConnectorJdbcResult-method.html b/docs/reference/dbFetch-DatabaseConnectorJdbcResult-method.html
index d5163b22..5c7652b3 100644
--- a/docs/reference/dbFetch-DatabaseConnectorJdbcResult-method.html
+++ b/docs/reference/dbFetch-DatabaseConnectorJdbcResult-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbGetInfo-DatabaseConnectorConnection-method.html b/docs/reference/dbGetInfo-DatabaseConnectorConnection-method.html
index d8b620a0..65f4104a 100644
--- a/docs/reference/dbGetInfo-DatabaseConnectorConnection-method.html
+++ b/docs/reference/dbGetInfo-DatabaseConnectorConnection-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbGetInfo-DatabaseConnectorDriver-method.html b/docs/reference/dbGetInfo-DatabaseConnectorDriver-method.html
index cb35a590..8c4f2e8b 100644
--- a/docs/reference/dbGetInfo-DatabaseConnectorDriver-method.html
+++ b/docs/reference/dbGetInfo-DatabaseConnectorDriver-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbGetQuery-DatabaseConnectorConnection-character-method.html b/docs/reference/dbGetQuery-DatabaseConnectorConnection-character-method.html
index 67d4367e..e279a0bd 100644
--- a/docs/reference/dbGetQuery-DatabaseConnectorConnection-character-method.html
+++ b/docs/reference/dbGetQuery-DatabaseConnectorConnection-character-method.html
@@ -23,7 +23,7 @@
diff --git a/docs/reference/dbGetRowCount-DatabaseConnectorDbiResult-method.html b/docs/reference/dbGetRowCount-DatabaseConnectorDbiResult-method.html
index a6a1c0a0..3901f879 100644
--- a/docs/reference/dbGetRowCount-DatabaseConnectorDbiResult-method.html
+++ b/docs/reference/dbGetRowCount-DatabaseConnectorDbiResult-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbGetRowCount-DatabaseConnectorJdbcResult-method.html b/docs/reference/dbGetRowCount-DatabaseConnectorJdbcResult-method.html
index a180e4ea..6f95f1ba 100644
--- a/docs/reference/dbGetRowCount-DatabaseConnectorJdbcResult-method.html
+++ b/docs/reference/dbGetRowCount-DatabaseConnectorJdbcResult-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbGetRowsAffected-DatabaseConnectorDbiResult-method.html b/docs/reference/dbGetRowsAffected-DatabaseConnectorDbiResult-method.html
index 19a25e52..f03c47e6 100644
--- a/docs/reference/dbGetRowsAffected-DatabaseConnectorDbiResult-method.html
+++ b/docs/reference/dbGetRowsAffected-DatabaseConnectorDbiResult-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbGetRowsAffected-DatabaseConnectorJdbcResult-method.html b/docs/reference/dbGetRowsAffected-DatabaseConnectorJdbcResult-method.html
index 679a87f1..821ed731 100644
--- a/docs/reference/dbGetRowsAffected-DatabaseConnectorJdbcResult-method.html
+++ b/docs/reference/dbGetRowsAffected-DatabaseConnectorJdbcResult-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbGetStatement-DatabaseConnectorDbiResult-method.html b/docs/reference/dbGetStatement-DatabaseConnectorDbiResult-method.html
index d8c427f7..de1a5dd7 100644
--- a/docs/reference/dbGetStatement-DatabaseConnectorDbiResult-method.html
+++ b/docs/reference/dbGetStatement-DatabaseConnectorDbiResult-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbGetStatement-DatabaseConnectorJdbcResult-method.html b/docs/reference/dbGetStatement-DatabaseConnectorJdbcResult-method.html
index e0b5f7da..dc6cfd98 100644
--- a/docs/reference/dbGetStatement-DatabaseConnectorJdbcResult-method.html
+++ b/docs/reference/dbGetStatement-DatabaseConnectorJdbcResult-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbHasCompleted-DatabaseConnectorDbiResult-method.html b/docs/reference/dbHasCompleted-DatabaseConnectorDbiResult-method.html
index 71a23e18..3f4e4875 100644
--- a/docs/reference/dbHasCompleted-DatabaseConnectorDbiResult-method.html
+++ b/docs/reference/dbHasCompleted-DatabaseConnectorDbiResult-method.html
@@ -19,7 +19,7 @@
diff --git a/docs/reference/dbHasCompleted-DatabaseConnectorJdbcResult-method.html b/docs/reference/dbHasCompleted-DatabaseConnectorJdbcResult-method.html
index 4e613ea3..7b0ef020 100644
--- a/docs/reference/dbHasCompleted-DatabaseConnectorJdbcResult-method.html
+++ b/docs/reference/dbHasCompleted-DatabaseConnectorJdbcResult-method.html
@@ -19,7 +19,7 @@
diff --git a/docs/reference/dbIsValid-DatabaseConnectorDbiConnection-method.html b/docs/reference/dbIsValid-DatabaseConnectorDbiConnection-method.html
index 56bb47a7..83c0b58f 100644
--- a/docs/reference/dbIsValid-DatabaseConnectorDbiConnection-method.html
+++ b/docs/reference/dbIsValid-DatabaseConnectorDbiConnection-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbIsValid-DatabaseConnectorJdbcConnection-method.html b/docs/reference/dbIsValid-DatabaseConnectorJdbcConnection-method.html
index 7abdc282..f35ec937 100644
--- a/docs/reference/dbIsValid-DatabaseConnectorJdbcConnection-method.html
+++ b/docs/reference/dbIsValid-DatabaseConnectorJdbcConnection-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbListFields-DatabaseConnectorConnection-character-method.html b/docs/reference/dbListFields-DatabaseConnectorConnection-character-method.html
index 3b581f5d..cfaf80c8 100644
--- a/docs/reference/dbListFields-DatabaseConnectorConnection-character-method.html
+++ b/docs/reference/dbListFields-DatabaseConnectorConnection-character-method.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/dbListTables-DatabaseConnectorConnection-method.html b/docs/reference/dbListTables-DatabaseConnectorConnection-method.html
index efd91608..c57b20c8 100644
--- a/docs/reference/dbListTables-DatabaseConnectorConnection-method.html
+++ b/docs/reference/dbListTables-DatabaseConnectorConnection-method.html
@@ -20,7 +20,7 @@
diff --git a/docs/reference/dbReadTable-DatabaseConnectorConnection-character-method.html b/docs/reference/dbReadTable-DatabaseConnectorConnection-character-method.html
index 292132a7..a9d6eb53 100644
--- a/docs/reference/dbReadTable-DatabaseConnectorConnection-character-method.html
+++ b/docs/reference/dbReadTable-DatabaseConnectorConnection-character-method.html
@@ -19,7 +19,7 @@
diff --git a/docs/reference/dbRemoveTable-DatabaseConnectorConnection-ANY-method.html b/docs/reference/dbRemoveTable-DatabaseConnectorConnection-ANY-method.html
index 2efa5ce0..0bbeb660 100644
--- a/docs/reference/dbRemoveTable-DatabaseConnectorConnection-ANY-method.html
+++ b/docs/reference/dbRemoveTable-DatabaseConnectorConnection-ANY-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbSendQuery-DatabaseConnectorDbiConnection-character-method.html b/docs/reference/dbSendQuery-DatabaseConnectorDbiConnection-character-method.html
index e9ab030e..9aba5b3f 100644
--- a/docs/reference/dbSendQuery-DatabaseConnectorDbiConnection-character-method.html
+++ b/docs/reference/dbSendQuery-DatabaseConnectorDbiConnection-character-method.html
@@ -22,7 +22,7 @@
diff --git a/docs/reference/dbSendQuery-DatabaseConnectorJdbcConnection-character-method.html b/docs/reference/dbSendQuery-DatabaseConnectorJdbcConnection-character-method.html
index e6a3c15f..9e7454c2 100644
--- a/docs/reference/dbSendQuery-DatabaseConnectorJdbcConnection-character-method.html
+++ b/docs/reference/dbSendQuery-DatabaseConnectorJdbcConnection-character-method.html
@@ -22,7 +22,7 @@
diff --git a/docs/reference/dbSendStatement-DatabaseConnectorConnection-character-method.html b/docs/reference/dbSendStatement-DatabaseConnectorConnection-character-method.html
index e02654bd..b725655c 100644
--- a/docs/reference/dbSendStatement-DatabaseConnectorConnection-character-method.html
+++ b/docs/reference/dbSendStatement-DatabaseConnectorConnection-character-method.html
@@ -23,7 +23,7 @@
diff --git a/docs/reference/dbUnloadDriver-DatabaseConnectorDriver-method.html b/docs/reference/dbUnloadDriver-DatabaseConnectorDriver-method.html
index b72e7cff..b6a862f9 100644
--- a/docs/reference/dbUnloadDriver-DatabaseConnectorDriver-method.html
+++ b/docs/reference/dbUnloadDriver-DatabaseConnectorDriver-method.html
@@ -25,7 +25,7 @@
diff --git a/docs/reference/dbWriteTable-DatabaseConnectorConnection-ANY-method.html b/docs/reference/dbWriteTable-DatabaseConnectorConnection-ANY-method.html
index 815439ad..eeefe22f 100644
--- a/docs/reference/dbWriteTable-DatabaseConnectorConnection-ANY-method.html
+++ b/docs/reference/dbWriteTable-DatabaseConnectorConnection-ANY-method.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/dbms.html b/docs/reference/dbms.html
index b4b962ed..f6a56def 100644
--- a/docs/reference/dbms.html
+++ b/docs/reference/dbms.html
@@ -20,7 +20,7 @@
diff --git a/docs/reference/disconnect.html b/docs/reference/disconnect.html
index 2b316a4a..3183b0cc 100644
--- a/docs/reference/disconnect.html
+++ b/docs/reference/disconnect.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/downloadJdbcDrivers.html b/docs/reference/downloadJdbcDrivers.html
index 2745a5f8..45fc6188 100644
--- a/docs/reference/downloadJdbcDrivers.html
+++ b/docs/reference/downloadJdbcDrivers.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/dropEmulatedTempTables.html b/docs/reference/dropEmulatedTempTables.html
index bcb31913..149610f7 100644
--- a/docs/reference/dropEmulatedTempTables.html
+++ b/docs/reference/dropEmulatedTempTables.html
@@ -20,7 +20,7 @@
diff --git a/docs/reference/eoMonth.html b/docs/reference/eoMonth.html
index 905ed705..5fddef98 100644
--- a/docs/reference/eoMonth.html
+++ b/docs/reference/eoMonth.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/executeSql.html b/docs/reference/executeSql.html
index c1a9bd9d..9f58ddb6 100644
--- a/docs/reference/executeSql.html
+++ b/docs/reference/executeSql.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/existsTable.html b/docs/reference/existsTable.html
index 0aa2237d..21659b49 100644
--- a/docs/reference/existsTable.html
+++ b/docs/reference/existsTable.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/extractQueryTimes.html b/docs/reference/extractQueryTimes.html
index 14a7daa3..c616cbea 100644
--- a/docs/reference/extractQueryTimes.html
+++ b/docs/reference/extractQueryTimes.html
@@ -19,7 +19,7 @@
@@ -105,15 +105,15 @@ Examples
executeSql(connection, "CREATE TABLE test (x INT);")
#> | | | 0% | |======================================================================| 100%
-#> Executing SQL took 0.0115 secs
+#> Executing SQL took 0.0109 secs
querySql(connection, "SELECT * FROM test;")
#> [1] X
#> <0 rows> (or 0-length row.names)
extractQueryTimes(logFile)
#> query startTime milliseconds thread
-#> 1 CREATE TABLE test (x INT) 2023-09-07 00:26:46 1 Main thread
-#> 2 SELECT * FROM test 2023-09-07 00:26:46 2 Main thread
+#> 1 CREATE TABLE test (x INT) 2023-11-08 14:18:33 1 Main thread
+#> 2 SELECT * FROM test 2023-11-08 14:18:33 2 Main thread
ParallelLogger::unregisterLogger("MY_LOGGER")
#> [1] TRUE
diff --git a/docs/reference/getAvailableJavaHeapSpace.html b/docs/reference/getAvailableJavaHeapSpace.html
index 220cecaf..b2210397 100644
--- a/docs/reference/getAvailableJavaHeapSpace.html
+++ b/docs/reference/getAvailableJavaHeapSpace.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/getTableNames.html b/docs/reference/getTableNames.html
index 766825c9..58de9a40 100644
--- a/docs/reference/getTableNames.html
+++ b/docs/reference/getTableNames.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/inDatabaseSchema.html b/docs/reference/inDatabaseSchema.html
index 3b6c3ae2..9069a3b4 100644
--- a/docs/reference/inDatabaseSchema.html
+++ b/docs/reference/inDatabaseSchema.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/index.html b/docs/reference/index.html
index d2594ae7..0bea3d87 100644
--- a/docs/reference/index.html
+++ b/docs/reference/index.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/insertTable.html b/docs/reference/insertTable.html
index 5046b080..7e0453c6 100644
--- a/docs/reference/insertTable.html
+++ b/docs/reference/insertTable.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/isSqlReservedWord.html b/docs/reference/isSqlReservedWord.html
index 30b05943..62fd9cc4 100644
--- a/docs/reference/isSqlReservedWord.html
+++ b/docs/reference/isSqlReservedWord.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/jdbcDrivers.html b/docs/reference/jdbcDrivers.html
index 27f7a7ca..175e2346 100644
--- a/docs/reference/jdbcDrivers.html
+++ b/docs/reference/jdbcDrivers.html
@@ -20,7 +20,7 @@
diff --git a/docs/reference/lowLevelExecuteSql.html b/docs/reference/lowLevelExecuteSql.html
index 348f7d90..f3e7b27c 100644
--- a/docs/reference/lowLevelExecuteSql.html
+++ b/docs/reference/lowLevelExecuteSql.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/lowLevelQuerySql.html b/docs/reference/lowLevelQuerySql.html
index 4c300eb0..de89effc 100644
--- a/docs/reference/lowLevelQuerySql.html
+++ b/docs/reference/lowLevelQuerySql.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/lowLevelQuerySqlToAndromeda.html b/docs/reference/lowLevelQuerySqlToAndromeda.html
index 50a929cb..5405e6ac 100644
--- a/docs/reference/lowLevelQuerySqlToAndromeda.html
+++ b/docs/reference/lowLevelQuerySqlToAndromeda.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/month.html b/docs/reference/month.html
index 631ad8f8..cd71d614 100644
--- a/docs/reference/month.html
+++ b/docs/reference/month.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/querySql.html b/docs/reference/querySql.html
index 29479789..b2b3a4af 100644
--- a/docs/reference/querySql.html
+++ b/docs/reference/querySql.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/querySqlToAndromeda.html b/docs/reference/querySqlToAndromeda.html
index 8ae1c641..5d4bb6b2 100644
--- a/docs/reference/querySqlToAndromeda.html
+++ b/docs/reference/querySqlToAndromeda.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/renderTranslateExecuteSql.html b/docs/reference/renderTranslateExecuteSql.html
index 49e37ecc..8e66a7d9 100644
--- a/docs/reference/renderTranslateExecuteSql.html
+++ b/docs/reference/renderTranslateExecuteSql.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/renderTranslateQueryApplyBatched.html b/docs/reference/renderTranslateQueryApplyBatched.html
index 9ab7c4e9..28526a00 100644
--- a/docs/reference/renderTranslateQueryApplyBatched.html
+++ b/docs/reference/renderTranslateQueryApplyBatched.html
@@ -20,7 +20,7 @@
diff --git a/docs/reference/renderTranslateQuerySql.html b/docs/reference/renderTranslateQuerySql.html
index a4c05827..4573529d 100644
--- a/docs/reference/renderTranslateQuerySql.html
+++ b/docs/reference/renderTranslateQuerySql.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/renderTranslateQuerySqlToAndromeda.html b/docs/reference/renderTranslateQuerySqlToAndromeda.html
index 9194047d..99f38d21 100644
--- a/docs/reference/renderTranslateQuerySqlToAndromeda.html
+++ b/docs/reference/renderTranslateQuerySqlToAndromeda.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/requiresTempEmulation.html b/docs/reference/requiresTempEmulation.html
index 1bbc2c5d..0e734353 100644
--- a/docs/reference/requiresTempEmulation.html
+++ b/docs/reference/requiresTempEmulation.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/year.html b/docs/reference/year.html
index 34f58ea8..03b93f81 100644
--- a/docs/reference/year.html
+++ b/docs/reference/year.html
@@ -18,7 +18,7 @@
diff --git a/extras/DatabaseConnector.pdf b/extras/DatabaseConnector.pdf
index 0459a090..001e6423 100644
Binary files a/extras/DatabaseConnector.pdf and b/extras/DatabaseConnector.pdf differ
diff --git a/extras/PackageMaintenance.R b/extras/PackageMaintenance.R
index 95f6ae42..1470e15a 100644
--- a/extras/PackageMaintenance.R
+++ b/extras/PackageMaintenance.R
@@ -81,6 +81,13 @@ databaseSchema <- Sys.getenv("CDM5_ORACLE_OHDSI_SCHEMA")
tables <- getTableNames(connection, databaseSchema, cast = "none")
sql <- paste(sprintf("DROP TABLE %s.%s;", databaseSchema, tables), collapse= "\n")
executeSql(connection, sql)
+
+databaseSchema <- Sys.getenv("CDM5_ORACLE_CDM54_SCHEMA")
+tables <- getTableNames(connection, databaseSchema, cast = "none")
+tables <- tables[grepl("", tables)]
+sql <- paste(sprintf("DROP TABLE %s.%s;", databaseSchema, tables), collapse= "\n")
+executeSql(connection, sql)
+
disconnect(connection)
# Postgres
diff --git a/extras/TestOtherPlatforms.R b/extras/TestOtherPlatforms.R
index d86697df..012ddad0 100644
--- a/extras/TestOtherPlatforms.R
+++ b/extras/TestOtherPlatforms.R
@@ -68,11 +68,23 @@ scratchDatabaseSchemaDataBricks <- "scratch"
connectionDetailsSnowflake <- createConnectionDetails(
dbms = "snowflake",
connectionString = keyring::key_get("snowflakeConnectionString"),
+ # connectionString = paste(keyring::key_get("snowflakeConnectionString"), "QUOTED_IDENTIFIERS_IGNORE_CASE=TRUE", sep="&"),
user = keyring::key_get("snowflakeUser"),
password = keyring::key_get("snowflakePassword")
)
-cdmDatabaseSchemaSnowflake <- "ohdsi.eunomia"
-scratchDatabaseSchemaSnowflake <- "ohdsi.scratch"
+cdmDatabaseSchemaSnowflake <- "ATLAS.SYNPUF110K_CDM_53"
+scratchDatabaseSchemaSnowflake <- "ATLAS.RESULTS"
+
+# Snowflake
+connectionDetailsSnowflake <- createConnectionDetails(
+ dbms = "snowflake",
+ server = Sys.getenv("CDM_SNOWFLAKE_SERVER"),
+ user = Sys.getenv("CDM_SNOWFLAKE_USER"),
+ password = Sys.getenv("CDM_SNOWFLAKE_PASSWORD")
+)
+connection <- connect(connectionDetailsSnowflake)
+cdmDatabaseSchemaSnowflake <- "ATLAS.SYNPUF110K_CDM_53"
+scratchDatabaseSchemaSnowflake <- "ATLAS.RESULTS"
# Open and close connection -----------------------------------------------
@@ -521,6 +533,67 @@ hash <- computeDataHash(connection = connection,
expect_true(is.character(hash))
disconnect(connection)
+# Test updates -----------------------------------------------------------------
+sql <- "CREATE TABLE #temp (x INT);
+ INSERT INTO #temp (x) SELECT 123;
+ DELETE FROM #temp WHERE x = 123;
+ DROP TABLE #temp;"
+
+# BigQuery
+options(sqlRenderTempEmulationSchema = scratchDatabaseSchemaBigQuery)
+connection <- connect(connectionDetailsBigQuery)
+
+expect_equal(renderTranslateExecuteSql(connection, sql), c(0, 1, 1, 0))
+
+expect_equal(renderTranslateExecuteSql(connection, sql, runAsBatch = TRUE), c(0, 1, 1, 0))
+
+rowsAffected <- dbSendStatement(connection, sql)
+expect_equal(dbGetRowsAffected(rowsAffected), 2)
+dbClearResult(rowsAffected)
+
+disconnect(connection)
+
+# Azure
+connection <- connect(connectionDetailsAzure)
+
+expect_equal(renderTranslateExecuteSql(connection, sql), c(0, 1, 1, 0))
+
+expect_equal(renderTranslateExecuteSql(connection, sql, runAsBatch = TRUE), c(0, 1, 1, 0))
+
+rowsAffected <- dbSendStatement(connection, sql)
+expect_equal(dbGetRowsAffected(rowsAffected), 2)
+dbClearResult(rowsAffected)
+
+disconnect(connection)
+
+# Databricks JDBC
+options(sqlRenderTempEmulationSchema = scratchDatabaseSchemaDataBricks)
+connection <- connect(connectionDetailsDataBricksJdbc)
+
+expect_equal(renderTranslateExecuteSql(connection, sql), c(-1, -1, 0, -1))
+
+expect_equal(renderTranslateExecuteSql(connection, sql, runAsBatch = TRUE), c(-1, -1, 0, -1))
+
+rowsAffected <- dbSendStatement(connection, sql)
+expect_equal(dbGetRowsAffected(rowsAffected), -3)
+dbClearResult(rowsAffected)
+
+disconnect(connection)
+
+# Databricks ODBC
+options(sqlRenderTempEmulationSchema = scratchDatabaseSchemaDataBricks)
+connection <- connect(connectionDetailsDataBricksOdbc)
+
+expect_equal(renderTranslateExecuteSql(connection, sql), c(0, 0, 0, 0))
+
+expect_equal(renderTranslateExecuteSql(connection, sql, runAsBatch = TRUE), c(0, 0, 0, 0))
+
+rowsAffected <- dbSendStatement(connection, sql)
+expect_equal(dbGetRowsAffected(rowsAffected), 0)
+dbClearResult(rowsAffected)
+
+disconnect(connection)
+
# Test dbplyr ------------------------------------------------------------------
source("tests/testthat/dbplyrTestFunction.R")
@@ -709,7 +782,11 @@ db <- DBI::dbConnect(odbc::odbc(),
connection <- connect(connectionDetailsBigQuery)
renderTranslateQuerySql(connection, "SELECT TOP 1 \"person_id\" FROM @schema.person;", schema = cdmDatabaseSchemaBigQuery)
-querySql(connection, "SELECT `person_id` FROM synpuf_2m.person LIMIT 1;")
+querySql(connection, "SELECT \"PERSON_ID\" FROM ATLAS.SYNPUF110K_CDM_53.person LIMIT 1;")
disconnect(connection)
+
+connection <- connect(connectionDetailsSnowflake)
+renderTranslateQuerySql(connection, "SELECT TOP 1 \"person_id\" FROM @schema.person;", schema = cdmDatabaseSchemaSnowflake)
+disconnect(connection)
diff --git a/extras/UploadDataToTestServer.R b/extras/UploadDataToTestServer.R
new file mode 100644
index 00000000..6d53e37a
--- /dev/null
+++ b/extras/UploadDataToTestServer.R
@@ -0,0 +1,135 @@
+# Copy Eunomia to a test server ------------------------------------------------
+
+# Assumes connectionDetails points to the test server to upload to
+databaseSchema <- "eunomia"
+
+library(DatabaseConnector)
+
+
+connection <- connect(connectionDetails)
+renderTranslateExecuteSql(
+ connection = connection,
+ sql = "CREATE SCHEMA @database_schema;",
+ database_schema = databaseSchema
+)
+
+eunomiaCd <- Eunomia::getEunomiaConnectionDetails()
+eunomiaConn <- connect(eunomiaCd)
+
+tableNames <- getTableNames(eunomiaConn, "main")
+for (i in seq_along(tableNames)) {
+ # for (i in 15:length(tableNames)) {
+ message(sprintf("Copying table %s", tableNames[i]))
+ table <- renderTranslateQuerySql(
+ connection = eunomiaConn,
+ sql = "SELECT * FROM main.@table_name;",
+ table_name = tableNames[i])
+ if (tableNames[i] == "cost") {
+ colnames(table)[colnames(table) == "REVEUE_CODE_SOURCE_VALUE"] <- "REVENUE_CODE_SOURCE_VALUE"
+ }
+ insertTable(
+ connection = connection,
+ databaseSchema = databaseSchema,
+ tableName = tableNames[i],
+ data = table,
+ dropTableIfExists = TRUE,
+ createTable = TRUE,
+ progressBar = TRUE
+ )
+}
+
+disconnect(connection)
+disconnect(eunomiaConn)
+
+# Copy data from one test server to another ------------------------------------
+
+library(DatabaseConnector)
+options(andromedaTempFolder = "e:/andromedaTemp")
+
+fromConnection <- connect(
+ dbms = "sql server",
+ user = Sys.getenv("CDM5_SQL_SERVER_USER"),
+ password = URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD")),
+ server = Sys.getenv("CDM5_SQL_SERVER_SERVER")
+)
+fromDatabaseSchema <- Sys.getenv("CDM5_SQL_SERVER_CDM54_SCHEMA")
+
+toConnection <- connect(
+ dbms = "postgresql",
+ user = Sys.getenv("CDM5_POSTGRESQL_USER"),
+ password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD")),
+ server = Sys.getenv("CDM5_POSTGRESQL_SERVER")
+)
+toDatabaseSchema <- Sys.getenv("CDM5_POSTGRESQL_CDM_SCHEMA")
+
+# toConnection <- connect(
+# dbms = "postgresql",
+# user = Sys.getenv("LOCAL_POSTGRES_USER"),
+# password = Sys.getenv("LOCAL_POSTGRES_PASSWORD"),
+# server = Sys.getenv("LOCAL_POSTGRES_SERVER")
+# )
+# toDatabaseSchema <- Sys.getenv("LOCAL_POSTGRES_CDM_SCHEMA")
+
+
+tableNames <- getTableNames(fromConnection, fromDatabaseSchema)
+for (i in seq_along(tableNames)) {
+ # for (i in 31:length(tableNames)) {
+ message(sprintf("Copying table %s", tableNames[i]))
+ andromeda <- Andromeda::andromeda()
+ renderTranslateQuerySqlToAndromeda(
+ connection = fromConnection,
+ sql = "SELECT * FROM @database_schema.@table_name;",
+ andromeda = andromeda,
+ andromedaTableName = tableNames[i],
+ database_schema = fromDatabaseSchema,
+ table_name = tableNames[i])
+ insertTable(
+ connection = toConnection,
+ databaseSchema = toDatabaseSchema,
+ tableName = tableNames[i],
+ data = andromeda[[tableNames[i]]],
+ dropTableIfExists = TRUE,
+ createTable = TRUE,
+ progressBar = TRUE
+ )
+ # querySql(toConnection, "SELECT * FROM cdmv5.condition_era LIMIT 10;")
+ Andromeda::close(andromeda)
+}
+
+
+# change timestamp fields to dates if needed:
+toTableNames <- getTableNames(toConnection, toDatabaseSchema)
+for (i in seq_along(toTableNames)) {
+ tableName <- toTableNames[i]
+ row <- renderTranslateQuerySql(toConnection,
+ sql = "SELECT TOP 1 * FROM @schema.@table;",
+ schema = toDatabaseSchema,
+ table = tableName)
+ dateFieldIdx <- which(grepl("_DATE$", colnames(row)))
+ for (j in dateFieldIdx) {
+ if (!is(row[,j], "Date")) {
+ writeLines(sprintf("Incorrect type of field %s in table %s: %s", colnames(row)[j], tableName, class(row[,j])[1]))
+ sql <- "ALTER TABLE @schema.@table ALTER COLUMN @column TYPE date;"
+ renderTranslateExecuteSql(toConnection,
+ sql = sql,
+ schema = toDatabaseSchema,
+ table = tableName,
+ column = colnames(row)[j])
+ }
+ }
+}
+
+# Create indices:
+sql <- readLines("https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.4.0/inst/ddl/5.4/postgresql/OMOPCDM_postgresql_5.4_indices.sql")
+sql <- sql[!grepl("note_nlp", sql)]
+
+renderTranslateExecuteSql(
+ connection = toConnection,
+ sql = paste(sql, collapse = "\n"),
+ cdmDatabaseSchema = toDatabaseSchema
+)
+
+disconnect(fromConnection)
+disconnect(toConnection)
+
+
diff --git a/extras/UploadEunomiaToTestServer.R b/extras/UploadEunomiaToTestServer.R
deleted file mode 100644
index de3a1c9a..00000000
--- a/extras/UploadEunomiaToTestServer.R
+++ /dev/null
@@ -1,40 +0,0 @@
-# Assumes connectionDetails points to the test server to upload to
-databaseSchema <- "eunomia"
-
-library(DatabaseConnector)
-
-
-connection <- connect(connectionDetails)
-renderTranslateExecuteSql(
- connection = connection,
- sql = "CREATE SCHEMA @database_schema;",
- database_schema = databaseSchema
-)
-
-eunomiaCd <- Eunomia::getEunomiaConnectionDetails()
-eunomiaConn <- connect(eunomiaCd)
-
-tableNames <- getTableNames(eunomiaConn, "main")
-for (i in seq_along(tableNames)) {
- # for (i in 15:length(tableNames)) {
- message(sprintf("Copying table %s", tableNames[i]))
- table <- renderTranslateQuerySql(
- connection = eunomiaConn,
- sql = "SELECT * FROM main.@table_name;",
- table_name = tableNames[i])
- if (tableNames[i] == "cost") {
- colnames(table)[colnames(table) == "REVEUE_CODE_SOURCE_VALUE"] <- "REVENUE_CODE_SOURCE_VALUE"
- }
- insertTable(
- connection = connection,
- databaseSchema = databaseSchema,
- tableName = tableNames[i],
- data = table,
- dropTableIfExists = TRUE,
- createTable = TRUE,
- progressBar = TRUE
- )
-}
-
-disconnect(connection)
-disconnect(eunomiaConn)
diff --git a/inst/doc/Connecting.pdf b/inst/doc/Connecting.pdf
index 1ff79f83..5860d1ce 100644
Binary files a/inst/doc/Connecting.pdf and b/inst/doc/Connecting.pdf differ
diff --git a/inst/doc/DbiAndDbplyr.pdf b/inst/doc/DbiAndDbplyr.pdf
index b02298c9..da7f83dc 100644
Binary files a/inst/doc/DbiAndDbplyr.pdf and b/inst/doc/DbiAndDbplyr.pdf differ
diff --git a/inst/doc/Querying.pdf b/inst/doc/Querying.pdf
index c20d56ae..296276c4 100644
Binary files a/inst/doc/Querying.pdf and b/inst/doc/Querying.pdf differ
diff --git a/tests/testthat/dbplyrTestFunction.R b/tests/testthat/dbplyrTestFunction.R
index c19aba4a..e97debdc 100644
--- a/tests/testthat/dbplyrTestFunction.R
+++ b/tests/testthat/dbplyrTestFunction.R
@@ -6,7 +6,8 @@ testDbplyrFunctions <- function(connectionDetails, cdmDatabaseSchema) {
assertTempEmulationSchemaSet(connectionDetails$dbms)
connection <- connect(connectionDetails)
- on.exit(disconnect(connection))
+ on.exit(dropEmulatedTempTables(connection))
+ on.exit(disconnect(connection), add = TRUE)
person <- tbl(connection, inDatabaseSchema(cdmDatabaseSchema, "person"))
observationPeriod <- tbl(connection, inDatabaseSchema(cdmDatabaseSchema, "observation_period"))
@@ -178,7 +179,6 @@ testDbplyrFunctions <- function(connectionDetails, cdmDatabaseSchema) {
# names(dumbNameCars) <- c("Car speed", "Dist. to Stop")
# copy_to(connection, dumbNameCars, name = "dn_cars")
- dropEmulatedTempTables(connection)
# disconnect(connection)
invisible(NULL)
}
diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R
index bf1696c2..63c5be46 100644
--- a/tests/testthat/setup.R
+++ b/tests/testthat/setup.R
@@ -1,5 +1,6 @@
-# Download the JDBC drivers used in the tests
+library(DatabaseConnector)
+# Download the JDBC drivers used in the tests ----------------------------------
if (Sys.getenv("DONT_DOWNLOAD_JDBC_DRIVERS", "") != "TRUE") {
oldJarFolder <- Sys.getenv("DATABASECONNECTOR_JAR_FOLDER")
Sys.setenv("DATABASECONNECTOR_JAR_FOLDER" = tempfile("jdbcDrivers"))
@@ -10,12 +11,258 @@ if (Sys.getenv("DONT_DOWNLOAD_JDBC_DRIVERS", "") != "TRUE") {
downloadJdbcDrivers("redshift")
downloadJdbcDrivers("spark")
downloadJdbcDrivers("snowflake")
-
- withr::defer(
- {
+ downloadJdbcDrivers("bigquery")
+
+ if (testthat::is_testing()) {
+ withr::defer({
unlink(Sys.getenv("DATABASECONNECTOR_JAR_FOLDER"), recursive = TRUE, force = TRUE)
Sys.setenv("DATABASECONNECTOR_JAR_FOLDER" = oldJarFolder)
},
testthat::teardown_env()
+ )
+ }
+}
+
+# Helper functions -------------------------------------------------------------
+addDbmsToLabel <- function(label, testServer) {
+ # Test sections are not shown in R check, so also printing them here:
+ writeLines(sprintf("Test: %s (%s)", label, testServer$connectionDetails$dbms))
+ return(sprintf("%s (%s)", label, testServer$connectionDetails$dbms))
+}
+
+# Create a list with testing server details ------------------------------
+testServers <- list()
+
+# Postgres
+parts <- unlist(strsplit(Sys.getenv("CDM5_POSTGRESQL_SERVER"), "/"))
+host <- parts[1]
+database <- parts[2]
+port <- "5432"
+connectionString <- paste0("jdbc:postgresql://", host, ":", port, "/", database)
+testServers[[length(testServers) + 1]] <- list(
+ connectionDetails = createConnectionDetails(
+ dbms = "postgresql",
+ user = Sys.getenv("CDM5_POSTGRESQL_USER"),
+ password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD")),
+ server = Sys.getenv("CDM5_POSTGRESQL_SERVER")
+ ),
+ connectionDetails2 = details <- createConnectionDetails(
+ dbms = "postgresql",
+ connectionString = !!connectionString,
+ user = Sys.getenv("CDM5_POSTGRESQL_USER"),
+ password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD"))
+ ),
+ cdmDatabaseSchema = Sys.getenv("CDM5_POSTGRESQL_CDM54_SCHEMA"),
+ tempEmulationSchema = NULL
+)
+
+# SQL Server
+connectionString <- paste0("jdbc:sqlserver://", Sys.getenv("CDM5_SQL_SERVER_SERVER"))
+testServers[[length(testServers) + 1]] <- list(
+ connectionDetails = details <- createConnectionDetails(
+ dbms = "sql server",
+ user = Sys.getenv("CDM5_SQL_SERVER_USER"),
+ password = URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD")),
+ server = Sys.getenv("CDM5_SQL_SERVER_SERVER")
+ ),
+ connectionDetails2 = details <- createConnectionDetails(
+ dbms = "sql server",
+ connectionString = !!connectionString,
+ user = Sys.getenv("CDM5_SQL_SERVER_USER"),
+ password = URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD"))
+ ),
+ cdmDatabaseSchema = Sys.getenv("CDM5_SQL_SERVER_CDM54_SCHEMA"),
+ tempEmulationSchema = NULL
+)
+
+# Oracle
+port <- "1521"
+parts <- unlist(strsplit(Sys.getenv("CDM5_ORACLE_SERVER"), "/"))
+host <- parts[1]
+sid <- parts[2]
+connectionString <- paste0("jdbc:oracle:thin:@", host, ":", port, ":", sid)
+testServers[[length(testServers) + 1]] <- list(
+ connectionDetails = details <- createConnectionDetails(
+ dbms = "oracle",
+ user = Sys.getenv("CDM5_ORACLE_USER"),
+ password = URLdecode(Sys.getenv("CDM5_ORACLE_PASSWORD")),
+ server = Sys.getenv("CDM5_ORACLE_SERVER")
+ ),
+ connectionDetails2 = details <- createConnectionDetails(
+ dbms = "oracle",
+ connectionString = !!connectionString,
+ user = Sys.getenv("CDM5_ORACLE_USER"),
+ password = URLdecode(Sys.getenv("CDM5_ORACLE_PASSWORD"))
+ ),
+ cdmDatabaseSchema = Sys.getenv("CDM5_ORACLE_CDM54_SCHEMA"),
+ tempEmulationSchema = Sys.getenv("CDM5_ORACLE_OHDSI_SCHEMA")
+)
+
+# RedShift
+parts <- unlist(strsplit(Sys.getenv("CDM5_REDSHIFT_SERVER"), "/"))
+host <- parts[1]
+database <- parts[2]
+port <- "5439"
+connectionString <- paste0("jdbc:redshift://", host, ":", port, "/", database)
+testServers[[length(testServers) + 1]] <- list(
+ connectionDetails = details <- createConnectionDetails(
+ dbms = "redshift",
+ user = Sys.getenv("CDM5_REDSHIFT_USER"),
+ password = URLdecode(Sys.getenv("CDM5_REDSHIFT_PASSWORD")),
+ server = Sys.getenv("CDM5_REDSHIFT_SERVER")
+ ),
+ connectionDetails2 = details <- createConnectionDetails(
+ dbms = "redshift",
+ connectionString = connectionString,
+ user = Sys.getenv("CDM5_REDSHIFT_USER"),
+ password = URLdecode(Sys.getenv("CDM5_REDSHIFT_PASSWORD"))
+ ),
+ cdmDatabaseSchema = Sys.getenv("CDM5_REDSHIFT_CDM54_SCHEMA"),
+ tempEmulationSchema = NULL
+)
+
+# Snowflake
+testServers[[length(testServers) + 1]] <- list(
+ connectionDetails = details <- createConnectionDetails(
+ dbms = "snowflake",
+ user = Sys.getenv("CDM_SNOWFLAKE_USER"),
+ password = URLdecode(Sys.getenv("CDM_SNOWFLAKE_PASSWORD")),
+ connectionString = Sys.getenv("CDM_SNOWFLAKE_CONNECTION_STRING")
+ ),
+ NULL,
+ cdmDatabaseSchema = Sys.getenv("CDM_SNOWFLAKE_CDM53_SCHEMA"),
+ tempEmulationSchema = Sys.getenv("CDM_SNOWFLAKE_OHDSI_SCHEMA")
+)
+
+# Databricks (Spark)
+testServers[[length(testServers) + 1]] <- list(
+ connectionDetails = details <- createConnectionDetails(
+ dbms = "spark",
+ user = Sys.getenv("CDM5_SPARK_USER"),
+ password = URLdecode(Sys.getenv("CDM5_SPARK_PASSWORD")),
+ connectionString = Sys.getenv("CDM5_SPARK_CONNECTION_STRING")
+ ),
+ NULL,
+ cdmDatabaseSchema = Sys.getenv("CDM5_SPARK_CDM_SCHEMA"),
+ tempEmulationSchema = Sys.getenv("CDM5_SPARK_OHDSI_SCHEMA")
+)
+
+# BigQuery
+# To avoid rate limit on BigQuery, only test on 1 OS:
+if (.Platform$OS.type == "windows") {
+ bqKeyFile <- tempfile(fileext = ".json")
+ writeLines(Sys.getenv("CDM_BIG_QUERY_KEY_FILE"), bqKeyFile)
+ if (testthat::is_testing()) {
+ withr::defer(unlink(bqKeyFile, force = TRUE), testthat::teardown_env())
+ }
+ bqConnectionString <- gsub("",
+ normalizePath(bqKeyFile, winslash = "/"),
+ Sys.getenv("CDM_BIG_QUERY_CONNECTION_STRING"))
+ testServers[[length(testServers) + 1]] <- list(
+ connectionDetails = details <- createConnectionDetails(
+ dbms = "bigquery",
+ user = "",
+ password = "",
+ connectionString = !!bqConnectionString
+ ),
+ NULL,
+ cdmDatabaseSchema = Sys.getenv("CDM_BIG_QUERY_CDM_SCHEMA"),
+ tempEmulationSchema = Sys.getenv("CDM_BIG_QUERY_OHDSI_SCHEMA")
)
}
+
+# SQLite
+sqliteFile <- tempfile(fileext = ".sqlite")
+if (testthat::is_testing()) {
+ withr::defer(unlink(sqliteFile, force = TRUE), testthat::teardown_env())
+}
+cdmDatabaseSchema <- "main"
+connectionDetails <- createConnectionDetails(
+ dbms = "sqlite",
+ server = sqliteFile
+)
+connection <- connect(connectionDetails)
+insertTable(
+ connection = connection,
+ databaseSchema = cdmDatabaseSchema,
+ tableName = "person",
+ data = data.frame(person_id = seq_len(100),
+ year_of_birth = round(runif(100, 1900, 2000)),
+ race_concept_id = as.numeric(NA),
+ gender_concept_id = rep(c(8507, 8532), 50),
+ care_site_id = round(runif(100, 1, 1e7)))
+)
+insertTable(
+ connection = connection,
+ databaseSchema = cdmDatabaseSchema,
+ tableName = "observation_period",
+ data = data.frame(person_id = seq_len(100),
+ observation_period_start_date = rep(as.Date("2000-01-01"), 100),
+ observation_period_end_date = rep(as.Date(c("2000-06-01", "2001-12-31")), 50),
+ period_type_concept_id = rep(0, 100))
+)
+insertTable(
+ connection = connection,
+ databaseSchema = cdmDatabaseSchema,
+ tableName = "vocabulary",
+ data = data.frame(vocabulary_id = c("a", "b"),
+ vocabulary_name = c("a", "b"),
+ vocabulary_reference= c("a", "b"),
+ vocabulary_version = c("a", "b"),
+ vocabulary_concpet_id = c(1, 2))
+)
+disconnect(connection)
+testServers[[length(testServers) + 1]] <- list(
+ connectionDetails = connectionDetails,
+ NULL,
+ cdmDatabaseSchema = cdmDatabaseSchema,
+ tempEmulationSchema = NULL
+)
+
+# DuckDB
+duckdbFile <- tempfile(fileext = ".duckdb")
+if (testthat::is_testing()) {
+ withr::defer(unlink(duckdbFile, force = TRUE), testthat::teardown_env())
+}
+cdmDatabaseSchema <- "main"
+connectionDetails <- createConnectionDetails(
+ dbms = "duckdb",
+ server = duckdbFile
+)
+connection <- connect(connectionDetails)
+insertTable(
+ connection = connection,
+ databaseSchema = cdmDatabaseSchema,
+ tableName = "person",
+ data = data.frame(person_id = seq_len(100),
+ year_of_birth = round(runif(100, 1900, 2000)),
+ race_concept_id = as.numeric(NA),
+ gender_concept_id = rep(c(8507, 8532), 50),
+ care_site_id = round(runif(100, 1, 1e7)))
+)
+insertTable(
+ connection = connection,
+ databaseSchema = cdmDatabaseSchema,
+ tableName = "observation_period",
+ data = data.frame(person_id = seq_len(100),
+ observation_period_start_date = rep(as.Date("2000-01-01"), 100),
+ observation_period_end_date = rep(as.Date(c("2000-06-01", "2001-12-31")), 50),
+ period_type_concept_id = rep(0, 100))
+)
+insertTable(
+ connection = connection,
+ databaseSchema = cdmDatabaseSchema,
+ tableName = "vocabulary",
+ data = data.frame(vocabulary_id = c("a", "b"),
+ vocabulary_name = c("a", "b"),
+ vocabulary_reference= c("a", "b"),
+ vocabulary_version = c("a", "b"),
+ vocabulary_concpet_id = c(1, 2))
+)
+disconnect(connection)
+testServers[[length(testServers) + 1]] <- list(
+ connectionDetails = connectionDetails,
+ NULL,
+ cdmDatabaseSchema = cdmDatabaseSchema,
+ tempEmulationSchema = NULL
+)
diff --git a/tests/testthat/test-BatchProcess.R b/tests/testthat/test-BatchProcess.R
index 041bbaae..ef84330a 100644
--- a/tests/testthat/test-BatchProcess.R
+++ b/tests/testthat/test-BatchProcess.R
@@ -1,114 +1,25 @@
-test_that("renderTranslateQueryApplyBatched works", {
- connection <- connect(
- dbms = "postgresql",
- user = Sys.getenv("CDM5_POSTGRESQL_USER"),
- password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD")),
- server = Sys.getenv("CDM5_POSTGRESQL_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_POSTGRESQL_CDM_SCHEMA")
- sql <- "SELECT TOP 10 * FROM @cdm_database_schema.vocabulary;"
-
- fun <- function(data, position, myString) {
- data$test <- myString
- return(data)
- }
- args <- list(myString = "MY STRING")
- data <- renderTranslateQueryApplyBatched(connection,
- sql,
- fun,
- args,
- cdm_database_schema = cdmDatabaseSchema
- )
- data <- do.call(rbind, data)
- expect_true("test" %in% colnames(data))
- expect_true(all(data$test == "MY STRING"))
- disconnect(connection)
-
-
- # Oracle ---------------------------------------
- connection <- connect(
- dbms = "oracle",
- user = Sys.getenv("CDM5_ORACLE_USER"),
- password = URLdecode(Sys.getenv("CDM5_ORACLE_PASSWORD")),
- server = Sys.getenv("CDM5_ORACLE_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_ORACLE_CDM_SCHEMA")
- sql <- "SELECT TOP 10 * FROM @cdm_database_schema.vocabulary;"
- data <- renderTranslateQueryApplyBatched(connection,
- sql,
- fun,
- args,
- cdm_database_schema = cdmDatabaseSchema
- )
- data <- do.call(rbind, data)
- expect_true("test" %in% colnames(data))
- expect_true(all(data$test == "MY STRING"))
- disconnect(connection)
-
- # SQL Server --------------------------------------
- connection <- connect(
- dbms = "sql server",
- user = Sys.getenv("CDM5_SQL_SERVER_USER"),
- password = URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD")),
- server = Sys.getenv("CDM5_SQL_SERVER_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_SQL_SERVER_CDM_SCHEMA")
-
- sql <- "SELECT TOP 10 * FROM @cdm_database_schema.vocabulary;"
- data <- renderTranslateQueryApplyBatched(connection,
- sql,
- fun,
- args,
- cdm_database_schema = cdmDatabaseSchema
- )
- data <- do.call(rbind, data)
- expect_true("test" %in% colnames(data))
- expect_true(all(data$test == "MY STRING"))
- disconnect(connection)
-
- # RedShift ----------------------------------------------
- connection <- connect(
- dbms = "redshift",
- user = Sys.getenv("CDM5_REDSHIFT_USER"),
- password = URLdecode(Sys.getenv("CDM5_REDSHIFT_PASSWORD")),
- server = Sys.getenv("CDM5_REDSHIFT_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_REDSHIFT_CDM_SCHEMA")
-
- sql <- "SELECT TOP 10 * FROM @cdm_database_schema.vocabulary;"
- data <- renderTranslateQueryApplyBatched(connection,
- sql,
- fun,
- args,
- cdm_database_schema = cdmDatabaseSchema
- )
- data <- do.call(rbind, data)
- expect_true("test" %in% colnames(data))
- expect_true(all(data$test == "MY STRING"))
- disconnect(connection)
-
-
- # Sqlite --------------------------------------------------
- dbFile <- tempfile()
- details <- createConnectionDetails(
- dbms = "sqlite",
- server = dbFile
- )
- connection <- connect(details)
- executeSql(connection, "CREATE TABLE person (x INT);
- INSERT INTO person (x) VALUES (1); INSERT INTO person (x) VALUES (2); INSERT INTO person (x) VALUES (3);")
-
- sql <- "SELECT * FROM person;"
- data <- renderTranslateQueryApplyBatched(
- connection,
- sql,
- fun,
- args
- )
- data <- do.call(rbind, data)
- expect_true("test" %in% colnames(data))
- expect_true(all(data$test == "MY STRING"))
-
- disconnect(connection)
- unlink(dbFile)
-})
+library(testthat)
+
+fun <- function(data, position, myString) {
+ data$test <- myString
+ return(data)
+}
+args <- list(myString = "MY STRING")
+
+for (testServer in testServers) {
+ test_that(addDbmsToLabel("Open and close connection", testServer), {
+ connection <- connect(testServer$connectionDetails)
+ on.exit(disconnect(connection))
+ sql <- "SELECT TOP 10 * FROM @cdm_database_schema.vocabulary;"
+ data <- renderTranslateQueryApplyBatched(
+ connection,
+ sql,
+ fun,
+ args,
+ cdm_database_schema = testServer$cdmDatabaseSchema
+ )
+ data <- do.call(rbind, data)
+ expect_true("test" %in% colnames(data))
+ expect_true(all(data$test == "MY STRING"))
+ })
+}
diff --git a/tests/testthat/test-connection.R b/tests/testthat/test-connection.R
index 88fce758..9fb1efa6 100644
--- a/tests/testthat/test-connection.R
+++ b/tests/testthat/test-connection.R
@@ -1,270 +1,24 @@
library(testthat)
-test_that("Open and close connection", {
- # Postgresql --------------------------------------------------
- details <- createConnectionDetails(
- dbms = "postgresql",
- user = Sys.getenv("CDM5_POSTGRESQL_USER"),
- password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD")),
- server = Sys.getenv("CDM5_POSTGRESQL_SERVER")
- )
- connection <- connect(details)
- expect_true(inherits(connection, "DatabaseConnectorConnection"))
- expect_equal(dbms(connection), "postgresql")
- expect_true(disconnect(connection))
-
- # SQL Server --------------------------------------------------
- details <- createConnectionDetails(
- dbms = "sql server",
- user = Sys.getenv("CDM5_SQL_SERVER_USER"),
- password = URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD")),
- server = Sys.getenv("CDM5_SQL_SERVER_SERVER")
- )
- connection <- connect(details)
- expect_true(inherits(connection, "DatabaseConnectorConnection"))
- expect_equal(dbms(connection), "sql server")
- expect_true(disconnect(connection))
-
- # Oracle --------------------------------------------------
- details <- createConnectionDetails(
- dbms = "oracle",
- user = Sys.getenv("CDM5_ORACLE_USER"),
- password = URLdecode(Sys.getenv("CDM5_ORACLE_PASSWORD")),
- server = Sys.getenv("CDM5_ORACLE_SERVER")
- )
- connection <- connect(details)
- expect_true(inherits(connection, "DatabaseConnectorConnection"))
- expect_equal(dbms(connection), "oracle")
- expect_true(disconnect(connection))
-
- # RedShift --------------------------------------------------
- details <- createConnectionDetails(
- dbms = "redshift",
- user = Sys.getenv("CDM5_REDSHIFT_USER"),
- password = URLdecode(Sys.getenv("CDM5_REDSHIFT_PASSWORD")),
- server = Sys.getenv("CDM5_REDSHIFT_SERVER")
- )
- connection <- connect(details)
- expect_true(inherits(connection, "DatabaseConnectorConnection"))
- expect_equal(dbms(connection), "redshift")
- expect_true(disconnect(connection))
-})
-
-test_that("Open and close connection using connection strings with embedded user and pw", {
- # Postgresql --------------------------------------------------
- parts <- unlist(strsplit(Sys.getenv("CDM5_POSTGRESQL_SERVER"), "/"))
- host <- parts[1]
- database <- parts[2]
- port <- "5432"
- connectionString <- paste0(
- "jdbc:postgresql://",
- host,
- ":",
- port,
- "/",
- database,
- "?user=",
- Sys.getenv("CDM5_POSTGRESQL_USER"),
- "&password=",
- URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD"))
- )
- details <- createConnectionDetails(dbms = "postgresql", connectionString = connectionString)
- connection <- connect(details)
- expect_true(inherits(connection, "DatabaseConnectorConnection"))
- expect_true(disconnect(connection))
-
- # SQL Server --------------------------------------------------
- connectionString <- paste0(
- "jdbc:sqlserver://",
- Sys.getenv("CDM5_SQL_SERVER_SERVER"),
- ";user=",
- Sys.getenv("CDM5_SQL_SERVER_USER"),
- ";password=",
- URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD"))
- )
-
- details <- createConnectionDetails(dbms = "sql server", connectionString = connectionString)
- connection <- connect(details)
- expect_true(inherits(connection, "DatabaseConnectorConnection"))
- expect_true(disconnect(connection))
-
- # Oracle --------------------------------------------------
- port <- "1521"
- parts <- unlist(strsplit(Sys.getenv("CDM5_ORACLE_SERVER"), "/"))
- host <- parts[1]
- sid <- parts[2]
-
- connectionString <- paste0(
- "jdbc:oracle:thin:",
- Sys.getenv("CDM5_ORACLE_USER"),
- "/",
- URLdecode(Sys.getenv("CDM5_ORACLE_PASSWORD")),
- "@",
- host,
- ":",
- port,
- ":",
- sid
- )
-
- details <- createConnectionDetails(dbms = "oracle", connectionString = connectionString)
- connection <- connect(details)
- expect_true(inherits(connection, "DatabaseConnectorConnection"))
- expect_true(disconnect(connection))
-
- # RedShift --------------------------------------------------
- parts <- unlist(strsplit(Sys.getenv("CDM5_REDSHIFT_SERVER"), "/"))
- host <- parts[1]
- database <- parts[2]
- port <- "5439"
- connectionString <- paste0(
- "jdbc:redshift://",
- host,
- ":",
- port,
- "/",
- database,
- "?user=",
- Sys.getenv("CDM5_REDSHIFT_USER"),
- "&password=",
- URLdecode(Sys.getenv("CDM5_REDSHIFT_PASSWORD"))
- )
- details <- createConnectionDetails(
- dbms = "redshift",
- connectionString = connectionString
- )
- connection <- connect(details)
- expect_true(inherits(connection, "DatabaseConnectorConnection"))
- expect_true(disconnect(connection))
-
- # Spark --------------------------------------------------
- # Disabling Spark unit tests until new testing server is up
- # connectionString <- sprintf(
- # "%s;UID=%s;PWD=%s",
- # Sys.getenv("CDM5_SPARK_CONNECTION_STRING"),
- # Sys.getenv("CDM5_SPARK_USER"),
- # URLdecode(Sys.getenv("CDM5_SPARK_PASSWORD"))
- # )
- #
- # details <- createConnectionDetails(
- # dbms = "spark",
- # connectionString = connectionString
- # )
- # connection <- connect(details)
- # expect_true(inherits(connection, "DatabaseConnectorConnection"))
- # expect_true(disconnect(connection))
-
- # Snowflake --------------------------------------------------
- # Disable Snowflake unit tests until we have a testing server
- # connectionString <- sprintf(
- # "%s;UID=%s;PWD=%s",
- # Sys.getenv("CDM5_SNOWFLAKE_CONNECTION_STRING"),
- # Sys.getenv("CDM5_SNOWFLAKE_USER"),
- # URLdecode(Sys.getenv("CDM5_SNOWFLAKE_PASSWORD"))
- # )
- #
- # details <- createConnectionDetails(
- # dbms = "snowflake",
- # connectionString = connectionString
- # )
- # connection <- connect(details)
- # expect_true(inherits(connection, "DatabaseConnectorConnection"))
- # expect_true(disconnect(connection))
-})
-
-test_that("Open and close connection using connection strings with separate user and pw", {
- # Postgresql --------------------------------------------------
- parts <- unlist(strsplit(Sys.getenv("CDM5_POSTGRESQL_SERVER"), "/"))
- host <- parts[1]
- database <- parts[2]
- port <- "5432"
- connectionString <- paste0("jdbc:postgresql://", host, ":", port, "/", database)
- details <- createConnectionDetails(
- dbms = "postgresql",
- connectionString = connectionString,
- user = Sys.getenv("CDM5_POSTGRESQL_USER"),
- password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD"))
- )
- connection <- connect(details)
- expect_true(inherits(connection, "DatabaseConnectorConnection"))
- expect_true(disconnect(connection))
-
- # SQL Server --------------------------------------------------
- connectionString <- paste0("jdbc:sqlserver://", Sys.getenv("CDM5_SQL_SERVER_SERVER"))
- details <- createConnectionDetails(
- dbms = "sql server",
- connectionString = connectionString,
- user = Sys.getenv("CDM5_SQL_SERVER_USER"),
- password = URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD"))
- )
- connection <- connect(details)
- expect_true(inherits(connection, "DatabaseConnectorConnection"))
- expect_true(disconnect(connection))
-
- # Oracle --------------------------------------------------
- port <- "1521"
- parts <- unlist(strsplit(Sys.getenv("CDM5_ORACLE_SERVER"), "/"))
- host <- parts[1]
- sid <- parts[2]
- connectionString <- paste0("jdbc:oracle:thin:@", host, ":", port, ":", sid)
- details <- createConnectionDetails(
- dbms = "oracle",
- connectionString = connectionString,
- user = Sys.getenv("CDM5_ORACLE_USER"),
- password = URLdecode(Sys.getenv("CDM5_ORACLE_PASSWORD"))
- )
- connection <- connect(details)
- expect_true(inherits(connection, "DatabaseConnectorConnection"))
- expect_true(disconnect(connection))
-
- # RedShift --------------------------------------------------
- parts <- unlist(strsplit(Sys.getenv("CDM5_REDSHIFT_SERVER"), "/"))
- host <- parts[1]
- database <- parts[2]
- port <- "5439"
- connectionString <- paste0(
- "jdbc:redshift://",
- host,
- ":",
- port,
- "/",
- database
- )
- details <- createConnectionDetails(
- dbms = "redshift",
- connectionString = connectionString,
- user = Sys.getenv("CDM5_REDSHIFT_USER"),
- password = URLdecode(Sys.getenv("CDM5_REDSHIFT_PASSWORD"))
- )
- connection <- connect(details)
- expect_true(inherits(connection, "DatabaseConnectorConnection"))
- expect_true(disconnect(connection))
-
- # Spark --------------------------------------------------
- # Disabling Spark unit tests until new testing server is up
- # details <- createConnectionDetails(
- # dbms = "spark",
- # connectionString = Sys.getenv("CDM5_SPARK_CONNECTION_STRING"),
- # user = Sys.getenv("CDM5_SPARK_USER"),
- # password = URLdecode(Sys.getenv("CDM5_SPARK_PASSWORD"))
- # )
- # connection <- connect(details)
- # expect_true(inherits(connection, "DatabaseConnectorConnection"))
- # expect_equal(dbms(connection), "spark")
- # expect_true(disconnect(connection))
-
- # Snowflake --------------------------------------------------
- # Disable Snowflake unit tests until we have a testing server
- # details <- createConnectionDetails(
- # dbms = "snowflake",
- # connectionString = Sys.getenv("CDM5_SNOWFLAKE_CONNECTION_STRING"),
- # user = Sys.getenv("CDM5_SNOWFLAKE_USER"),
- # password = URLdecode(Sys.getenv("CDM5_SNOWFLAKE_PASSWORD"))
- # )
- # connection <- connect(details)
- # expect_true(inherits(connection, "DatabaseConnectorConnection"))
- # expect_true(disconnect(connection))
-})
+for (testServer in testServers) {
+ test_that(addDbmsToLabel("Open and close connection", testServer), {
+ connection <- connect(testServer$connectionDetails)
+ expect_true(inherits(connection, "DatabaseConnectorConnection"))
+ expect_equal(dbms(connection), testServer$connectionDetails$dbms)
+ expect_true(disconnect(connection))
+ })
+}
+
+for (testServer in testServers) {
+ if (!is.null(testServer$connectionDetails2)) {
+ test_that(addDbmsToLabel("Open and close connection using secondary details", testServer), {
+ connection <- connect(testServer$connectionDetails2)
+ expect_true(inherits(connection, "DatabaseConnectorConnection"))
+ expect_equal(dbms(connection), testServer$connectionDetails2$dbms)
+ expect_true(disconnect(connection))
+ })
+ }
+}
test_that("Error is thrown when using incorrect dbms argument", {
expect_error(createConnectionDetails(dbms = "foobar"), "DBMS 'foobar' not supported")
@@ -284,9 +38,7 @@ test_that("Error is thrown when forgetting password", {
expect_error(connection <- connect(details), "Connection propery 'password' is NULL")
})
-
test_that("dbms function maps DBI connections to correct SQL dialect", {
-
mappings <- c(
'Microsoft SQL Server' = 'sql server',
'PqConnection' = 'postgresql',
@@ -294,16 +46,11 @@ test_that("dbms function maps DBI connections to correct SQL dialect", {
'BigQueryConnection' = 'bigquery',
'SQLiteConnection' = 'sqlite',
'duckdb_connection' = 'duckdb')
-
-
for(i in seq_along(mappings)) {
driver <- names(mappings)[i]
dialect <- unname(mappings)[i]
mockConstructor <- setClass(driver, contains = "DBIConnection")
mockConnection <- mockConstructor()
expect_equal(dbms(mockConnection), dialect)
-
- # duckdb is not yet supported in the current release of SqlRender
- if(dialect != "duckdb") expect_error(checkIfDbmsIsSupported(dbms(mockConnection)), NA)
}
})
diff --git a/tests/testthat/test-dataHash.R b/tests/testthat/test-dataHash.R
index 522146b3..37e46690 100644
--- a/tests/testthat/test-dataHash.R
+++ b/tests/testthat/test-dataHash.R
@@ -1,109 +1,10 @@
library(testthat)
-test_that("Compute data hash", {
- # Postgresql -----------------------------------------------------------------
- details <- createConnectionDetails(
- dbms = "postgresql",
- user = Sys.getenv("CDM5_POSTGRESQL_USER"),
- password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD")),
- server = Sys.getenv("CDM5_POSTGRESQL_SERVER")
- )
- connection <- connect(details)
- hash <- computeDataHash(connection, Sys.getenv("CDM5_POSTGRESQL_CDM_SCHEMA"))
- expect_true(is.character(hash))
-
- disconnect(connection)
-
- # SQL Server -----------------------------------------------------------------
- details <- createConnectionDetails(
- dbms = "sql server",
- user = Sys.getenv("CDM5_SQL_SERVER_USER"),
- password = URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD")),
- server = Sys.getenv("CDM5_SQL_SERVER_SERVER")
- )
- connection <- connect(details)
- hash <- computeDataHash(connection, Sys.getenv("CDM5_SQL_SERVER_CDM_SCHEMA"))
- expect_true(is.character(hash))
-
- disconnect(connection)
-
- # Oracle ---------------------------------------------------------------------
- details <- createConnectionDetails(
- dbms = "oracle",
- user = Sys.getenv("CDM5_ORACLE_USER"),
- password = URLdecode(Sys.getenv("CDM5_ORACLE_PASSWORD")),
- server = Sys.getenv("CDM5_ORACLE_SERVER")
- )
- connection <- connect(details)
- hash <- computeDataHash(connection, Sys.getenv("CDM5_ORACLE_CDM_SCHEMA"))
- expect_true(is.character(hash))
-
- disconnect(connection)
-
- # RedShift ------------------------------------------------------------------
- details <- createConnectionDetails(
- dbms = "redshift",
- user = Sys.getenv("CDM5_REDSHIFT_USER"),
- password = URLdecode(Sys.getenv("CDM5_REDSHIFT_PASSWORD")),
- server = Sys.getenv("CDM5_REDSHIFT_SERVER")
- )
- connection <- connect(details)
- hash <- computeDataHash(connection, Sys.getenv("CDM5_REDSHIFT_CDM_SCHEMA"))
- expect_true(is.character(hash))
-
- disconnect(connection)
-
- # RSQLite --------------------------------------------------------------------
- dbFile <- tempfile(fileext = "sqlite")
- details <- createConnectionDetails(
- dbms = "sqlite",
- server = dbFile
- )
- connection <- connect(details)
- DatabaseConnector::insertTable(
- connection = connection,
- databaseSchema = "main",
- tableName = "cars",
- data = cars,
- createTable = TRUE
- )
- DatabaseConnector::insertTable(
- connection = connection,
- databaseSchema = "main",
- tableName = "iris",
- data = iris,
- createTable = TRUE
- )
- hash <- computeDataHash(connection, "main")
- expect_true(is.character(hash))
-
- disconnect(connection)
- unlink(dbFile)
-
- # DuckDB --------------------------------------------------------------------
- dbFile <- tempfile(fileext = "duckdb")
- details <- createConnectionDetails(
- dbms = "duckdb",
- server = dbFile
- )
- connection <- connect(details)
- DatabaseConnector::insertTable(
- connection = connection,
- databaseSchema = "main",
- tableName = "cars",
- data = cars,
- createTable = TRUE
- )
- DatabaseConnector::insertTable(
- connection = connection,
- databaseSchema = "main",
- tableName = "iris",
- data = iris,
- createTable = TRUE
- )
- hash <- computeDataHash(connection, "main")
- expect_true(is.character(hash))
-
- disconnect(connection)
- unlink(dbFile)
-})
+for (testServer in testServers) {
+ test_that(addDbmsToLabel("Compute data hash", testServer), {
+ connection <- connect(testServer$connectionDetails)
+ on.exit(disconnect(connection))
+ hash <- computeDataHash(connection, testServer$cdmDatabaseSchema)
+ expect_true(is.character(hash))
+ })
+}
diff --git a/tests/testthat/test-dbplyr.R b/tests/testthat/test-dbplyr.R
index e473011f..27f92b70 100644
--- a/tests/testthat/test-dbplyr.R
+++ b/tests/testthat/test-dbplyr.R
@@ -2,135 +2,28 @@ library(testthat)
library(DatabaseConnector)
source("dbplyrTestFunction.R")
-test_that("Test dbplyr on Postgres", {
- # Postgres ----------------------------------------------------------
- connectionDetails <- createConnectionDetails(
- dbms = "postgresql",
- user = Sys.getenv("CDM5_POSTGRESQL_USER"),
- password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD")),
- server = Sys.getenv("CDM5_POSTGRESQL_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_POSTGRESQL_CDM_SCHEMA")
- testDbplyrFunctions(connectionDetails, cdmDatabaseSchema)
-})
-
-test_that("Test dbplyr on SQL Server", {
- # SQL Server --------------------------------------
- connectionDetails <- createConnectionDetails(
- dbms = "sql server",
- user = Sys.getenv("CDM5_SQL_SERVER_USER"),
- password = URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD")),
- server = Sys.getenv("CDM5_SQL_SERVER_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_SQL_SERVER_CDM_SCHEMA")
- testDbplyrFunctions(connectionDetails, cdmDatabaseSchema)
-})
-
-test_that("Test dbplyr on Oracle", {
- # Oracle ---------------------------------------
- connectionDetails <- createConnectionDetails(
- dbms = "oracle",
- user = Sys.getenv("CDM5_ORACLE_USER"),
- password = URLdecode(Sys.getenv("CDM5_ORACLE_PASSWORD")),
- server = Sys.getenv("CDM5_ORACLE_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_ORACLE_CDM_SCHEMA")
- options(sqlRenderTempEmulationSchema = Sys.getenv("CDM5_ORACLE_OHDSI_SCHEMA"))
- testDbplyrFunctions(connectionDetails, cdmDatabaseSchema)
-})
-
-test_that("Test dbplyr on RedShift", {
- # RedShift ----------------------------------------------
- connectionDetails <- createConnectionDetails(
- dbms = "redshift",
- user = Sys.getenv("CDM5_REDSHIFT_USER"),
- password = URLdecode(Sys.getenv("CDM5_REDSHIFT_PASSWORD")),
- server = Sys.getenv("CDM5_REDSHIFT_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_REDSHIFT_CDM_SCHEMA")
- testDbplyrFunctions(connectionDetails, cdmDatabaseSchema)
-})
-
-test_that("Test dbplyr on SQLite", {
- # SQLite -------------------------------------------------
- databaseFile <- tempfile(fileext = ".sqlite")
- cdmDatabaseSchema <- "main"
- connectionDetails <- createConnectionDetails(
- dbms = "sqlite",
- server = databaseFile
- )
- connection <- connect(connectionDetails)
- insertTable(
- connection = connection,
- databaseSchema = cdmDatabaseSchema,
- tableName = "person",
- data = data.frame(person_id = seq_len(100),
- year_of_birth = round(runif(100, 1900, 2000)),
- race_concept_id = as.numeric(NA),
- gender_concept_id = rep(c(8507, 8532), 50),
- care_site_id = round(runif(100, 1, 1e7)))
- )
- insertTable(
- connection = connection,
- databaseSchema = cdmDatabaseSchema,
- tableName = "observation_period",
- data = data.frame(person_id = seq_len(100),
- observation_period_start_date = rep(as.Date("2000-01-01"), 100),
- observation_period_end_date = rep(as.Date(c("2000-06-01", "2001-12-31")), 50),
- period_type_concept_id = rep(0, 100))
- )
- disconnect(connection)
- testDbplyrFunctions(connectionDetails, cdmDatabaseSchema)
- unlink(databaseFile)
-})
-
-test_that("Test dbplyr on DuckDB", {
- # DuckDb -------------------------------------------------
- databaseFile <- tempfile(fileext = ".duckdb")
- cdmDatabaseSchema <- "main"
- connectionDetails <- createConnectionDetails(
- dbms = "duckdb",
- server = databaseFile
- )
- connection <- connect(connectionDetails)
- insertTable(
- connection = connection,
- databaseSchema = cdmDatabaseSchema,
- tableName = "person",
- data = data.frame(person_id = seq_len(100),
- year_of_birth = round(runif(100, 1900, 2000)),
- race_concept_id = as.numeric(NA),
- gender_concept_id = rep(c(8507, 8532), 50),
- care_site_id = round(runif(100, 1, 1e7)))
- )
- insertTable(
- connection = connection,
- databaseSchema = cdmDatabaseSchema,
- tableName = "observation_period",
- data = data.frame(person_id = seq_len(100),
- observation_period_start_date = rep(as.Date("2000-01-01"), 100),
- observation_period_end_date = rep(as.Date(c("2000-06-01", "2001-12-31")), 50),
- period_type_concept_id = rep(0, 100))
- )
- disconnect(connection)
- testDbplyrFunctions(connectionDetails, cdmDatabaseSchema)
- unlink(databaseFile)
-})
+for (testServer in testServers) {
+ test_that(addDbmsToLabel("Test dbplyr", testServer), {
+ options(sqlRenderTempEmulationSchema = testServer$tempEmulationSchema)
+ testDbplyrFunctions(connectionDetails = testServer$connectionDetails,
+ cdmDatabaseSchema = testServer$cdmDatabaseSchema)
+ })
+}
test_that("Test dbplyr date functions on non-dbplyr data", {
date <- c(as.Date("2000-02-01"), as.Date("2000-12-31"), as.Date("2000-01-31"))
-
+
date2 <- c(as.Date("2000-02-05"), as.Date("2000-11-30"), as.Date("2002-01-31"))
expect_equal(dateDiff("day", date, date2), c(4, -31, 731))
expect_equal(eoMonth(date), c(as.Date("2000-02-29"), as.Date("2000-12-31"), as.Date("2000-01-31")))
-
+
expect_equal(dateAdd("day", 1, date), c(as.Date("2000-02-02"), as.Date("2001-01-01"), as.Date("2000-02-01")))
expect_equal(year(date), c(2000, 2000, 2000))
-
+
expect_equal(month(date), c(2, 12, 1))
-
+
expect_equal(day(date), c(1, 31, 31))
})
diff --git a/tests/testthat/test-duckdb.R b/tests/testthat/test-duckdb.R
deleted file mode 100644
index 5d958002..00000000
--- a/tests/testthat/test-duckdb.R
+++ /dev/null
@@ -1,53 +0,0 @@
-library(testthat)
-
-test_that("Open and close duckdb connection", {
- databaseFile <- tempfile()
- connection <- DatabaseConnector::connect(dbms = "duckdb", server = databaseFile)
- expect_s4_class(connection, "DatabaseConnectorDbiConnection")
-
- disconnect(connection)
- unlink(databaseFile)
-})
-
-test_that("Insert and retrieve dates from duckdb", {
- databaseFile <- tempfile()
- connection <- DatabaseConnector::connect(dbms = "duckdb", server = databaseFile)
- data <- data.frame(startDate = as.Date(c("2000-01-01", "2000-02-01")))
- insertTable(
- connection = connection,
- databaseSchema = "main",
- tableName = "test",
- data = data,
- createTable = TRUE,
- camelCaseToSnakeCase = TRUE
- )
- data2 <- renderTranslateQuerySql(
- connection = connection,
- sql = "SELECT * FROM main.test;",
- snakeCaseToCamelCase = TRUE)
- expect_equal(data, data2)
- disconnect(connection)
- unlink(databaseFile)
-})
-
-test_that("Insert using tibbles and retrieve dates from duckdb", {
- databaseFile <- tempfile()
- connection <- DatabaseConnector::connect(dbms = "duckdb", server = databaseFile)
-
- data <- dplyr::tibble(startDate = as.Date(c("2000-01-01", "2000-02-01")))
- insertTable(
- connection = connection,
- databaseSchema = "main",
- tableName = "test",
- data = data,
- createTable = TRUE,
- camelCaseToSnakeCase = TRUE
- )
- data2 <- renderTranslateQuerySql(
- connection = connection,
- sql = "SELECT * FROM main.test;",
- snakeCaseToCamelCase = TRUE)
- expect_equal(data, dplyr::as_tibble(data2))
- disconnect(connection)
- unlink(databaseFile)
-})
diff --git a/tests/testthat/test-fetchResults.R b/tests/testthat/test-fetchResults.R
index 8cfe2203..6c311226 100644
--- a/tests/testthat/test-fetchResults.R
+++ b/tests/testthat/test-fetchResults.R
@@ -6,280 +6,41 @@ if (DatabaseConnector:::is_installed("ParallelLogger")) {
ParallelLogger::addDefaultFileLogger(logFileName, name = "TEST_LOGGER")
}
-test_that("Fetch results", {
- # Postgres ----------------------------------------------------------
- connection <- connect(
- dbms = "postgresql",
- user = Sys.getenv("CDM5_POSTGRESQL_USER"),
- password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD")),
- server = Sys.getenv("CDM5_POSTGRESQL_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_POSTGRESQL_CDM_SCHEMA")
- sql <- "SELECT COUNT(*) AS row_count FROM @cdm_database_schema.vocabulary"
- renderedSql <- SqlRender::render(sql, cdm_database_schema = cdmDatabaseSchema)
-
- # Fetch data.frame:
- count <- querySql(connection, renderedSql)
- expect_equal(count[1, 1], 58)
- count <- renderTranslateQuerySql(connection, sql, cdm_database_schema = cdmDatabaseSchema)
- expect_equal(count[1, 1], 58)
-
- # Fetch Andromeda:
- andromeda <- Andromeda::andromeda()
- querySqlToAndromeda(connection, renderedSql, andromeda = andromeda, andromedaTableName = "test", snakeCaseToCamelCase = TRUE)
- expect_equivalent(dplyr::collect(andromeda$test)$rowCount[1], 58)
- renderTranslateQuerySqlToAndromeda(connection,
- sql,
- cdm_database_schema = cdmDatabaseSchema,
- andromeda = andromeda,
- andromedaTableName = "test2",
- snakeCaseToCamelCase = TRUE
- )
- expect_equivalent(dplyr::collect(andromeda$test2)$rowCount[1], 58)
- Andromeda::close(andromeda)
-
- disconnect(connection)
-
- # SQL Server --------------------------------------
- connection <- connect(
- dbms = "sql server",
- user = Sys.getenv("CDM5_SQL_SERVER_USER"),
- password = URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD")),
- server = Sys.getenv("CDM5_SQL_SERVER_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_SQL_SERVER_CDM_SCHEMA")
- sql <- "SELECT COUNT(*) AS row_count FROM @cdm_database_schema.vocabulary"
- renderedSql <- SqlRender::render(sql, cdm_database_schema = cdmDatabaseSchema)
-
- # Fetch data.frame:
- count <- querySql(connection, renderedSql)
- expect_equal(count[1, 1], 71)
- count <- renderTranslateQuerySql(connection, sql, cdm_database_schema = cdmDatabaseSchema)
- expect_equal(count[1, 1], 71)
-
- # Fetch Andromeda:
- andromeda <- Andromeda::andromeda()
- querySqlToAndromeda(connection, renderedSql, andromeda = andromeda, andromedaTableName = "test", snakeCaseToCamelCase = TRUE)
- expect_equivalent(dplyr::collect(andromeda$test)$rowCount[1], 71)
- renderTranslateQuerySqlToAndromeda(connection,
- sql,
- cdm_database_schema = cdmDatabaseSchema,
- andromeda = andromeda,
- andromedaTableName = "test2",
- snakeCaseToCamelCase = TRUE
- )
- expect_equivalent(dplyr::collect(andromeda$test2)$rowCount[1], 71)
- Andromeda::close(andromeda)
-
- disconnect(connection)
-
- # Oracle ---------------------------------------
- connection <- connect(
- dbms = "oracle",
- user = Sys.getenv("CDM5_ORACLE_USER"),
- password = URLdecode(Sys.getenv("CDM5_ORACLE_PASSWORD")),
- server = Sys.getenv("CDM5_ORACLE_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_ORACLE_CDM_SCHEMA")
- sql <- "SELECT COUNT(*) AS row_count FROM @cdm_database_schema.vocabulary"
- renderedSql <- SqlRender::render(sql, cdm_database_schema = cdmDatabaseSchema)
-
- # Fetch types correctly:
- x <- querySql(connection, "
- SELECT
- 1/10 as a,
- x1,
- x2,
- x1 / x2 AS b,
- CAST(1 AS INT) AS c,
- CAST(1.1 AS NUMBER(1,0)) AS d,
- CAST(1.1 AS FLOAT) AS e,
- 0.1 AS f,
- CAST(9223372036854775807 AS NUMBER(19)) AS g
- FROM (
- SELECT
- 1 AS x1,
- 10 AS x2
- FROM
- DUAL
- )
- ", integerAsNumeric = FALSE, integer64AsNumeric = FALSE)
-
- expect_identical(x, data.frame(
- A = 0.1,
- X1 = 1,
- X2 = 10,
- B = 0.1,
- C = as.integer(1),
- D = as.integer(1),
- E = 1.1,
- F = 0.1,
- G = bit64::as.integer64("9223372036854775807")
- ))
-
- # Fetch data.frame:
- count <- querySql(connection, renderedSql)
- expect_equal(count[1, 1], 71)
- count <- renderTranslateQuerySql(connection, sql, cdm_database_schema = cdmDatabaseSchema)
- expect_equal(count[1, 1], 71)
-
- # Fetch Andromeda:
- andromeda <- Andromeda::andromeda()
- querySqlToAndromeda(connection, renderedSql, andromeda = andromeda, andromedaTableName = "test", snakeCaseToCamelCase = TRUE)
- expect_equivalent(dplyr::collect(andromeda$test)$rowCount[1], 71)
- renderTranslateQuerySqlToAndromeda(connection,
- sql,
- cdm_database_schema = cdmDatabaseSchema,
- andromeda = andromeda,
- andromedaTableName = "test2",
- snakeCaseToCamelCase = TRUE
- )
- expect_equivalent(dplyr::collect(andromeda$test2)$rowCount[1], 71)
- Andromeda::close(andromeda)
-
- disconnect(connection)
-
- # RedShift ----------------------------------------------
- connection <- connect(
- dbms = "redshift",
- user = Sys.getenv("CDM5_REDSHIFT_USER"),
- password = URLdecode(Sys.getenv("CDM5_REDSHIFT_PASSWORD")),
- server = Sys.getenv("CDM5_REDSHIFT_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_REDSHIFT_CDM_SCHEMA")
- sql <- "SELECT COUNT(*) AS row_count FROM @cdm_database_schema.vocabulary"
- renderedSql <- SqlRender::render(sql, cdm_database_schema = cdmDatabaseSchema)
-
- # Fetch data.frame:
- count <- querySql(connection, renderedSql)
- expect_equal(count[1, 1], 91)
- count <- renderTranslateQuerySql(connection, sql, cdm_database_schema = cdmDatabaseSchema)
- expect_equal(count[1, 1], 91)
-
- # Fetch Andromeda:
- andromeda <- Andromeda::andromeda()
- querySqlToAndromeda(connection, renderedSql, andromeda = andromeda, andromedaTableName = "test", snakeCaseToCamelCase = TRUE)
- expect_equivalent(dplyr::collect(andromeda$test)$rowCount[1], 91)
- renderTranslateQuerySqlToAndromeda(connection,
- sql,
- cdm_database_schema = cdmDatabaseSchema,
- andromeda = andromeda,
- andromedaTableName = "test2",
- snakeCaseToCamelCase = TRUE
- )
- expect_equivalent(dplyr::collect(andromeda$test2)$rowCount[1], 91)
- Andromeda::close(andromeda)
-
- disconnect(connection)
-
- # SQLite --------------------------------------------------
- databaseFile <- tempfile(fileext = ".sqlite")
- cdmDatabaseSchema <- "main"
- connectionDetails <- createConnectionDetails(
- dbms = "sqlite",
- server = databaseFile
- )
- connection <- connect(connectionDetails)
- insertTable(
- connection = connection,
- databaseSchema = cdmDatabaseSchema,
- tableName = "person",
- data = data.frame(person_id = seq_len(100),
- year_of_birth = round(runif(100, 1900, 2000)),
- race_concept_id = as.numeric(NA),
- gender_concept_id = rep(c(8507, 8532), 50))
- )
- # Fetch data.frame:
- count <- querySql(connection, "SELECT COUNT(*) FROM main.person;")
- expect_equal(count[1, 1], 100)
- count <- renderTranslateQuerySql(connection, "SELECT COUNT(*) FROM @cdm.person;", cdm = cdmDatabaseSchema)
- expect_equal(count[1, 1], 100)
-
- # Fetch Andromeda:
- andromeda <- Andromeda::andromeda()
- querySqlToAndromeda(connection, "SELECT * FROM main.person;", andromeda = andromeda, andromedaTableName = "test", snakeCaseToCamelCase = TRUE)
- expect_equivalent(nrow(dplyr::collect(andromeda$test)), 100)
-
- Andromeda::close(andromeda)
-
- disconnect(connection)
- unlink(databaseFile)
-
-})
-
-test_that("dbFetch works", {
- connection <- connect(
- dbms = "postgresql",
- user = Sys.getenv("CDM5_POSTGRESQL_USER"),
- password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD")),
- server = Sys.getenv("CDM5_POSTGRESQL_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_POSTGRESQL_CDM_SCHEMA")
- sql <- "SELECT * FROM @cdm_database_schema.vocabulary LIMIT 10"
- renderedSql <- SqlRender::render(sql, cdm_database_schema = cdmDatabaseSchema)
-
- queryResult <- dbSendQuery(connection, renderedSql)
- df <- dbFetch(queryResult)
- dbClearResult(queryResult)
-
- expect_s3_class(df, "data.frame")
- expect_equal(nrow(df), 10)
- disconnect(connection)
-
- # Oracle ---------------------------------------
- connection <- connect(
- dbms = "oracle",
- user = Sys.getenv("CDM5_ORACLE_USER"),
- password = URLdecode(Sys.getenv("CDM5_ORACLE_PASSWORD")),
- server = Sys.getenv("CDM5_ORACLE_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_ORACLE_CDM_SCHEMA")
-
- sql <- "SELECT * FROM @cdm_database_schema.vocabulary FETCH FIRST 10 ROWS ONLY"
- renderedSql <- SqlRender::render(sql, cdm_database_schema = cdmDatabaseSchema)
-
- queryResult <- dbSendQuery(connection, renderedSql)
- df <- dbFetch(queryResult)
- dbClearResult(queryResult)
-
- disconnect(connection)
-
- # SQL Server --------------------------------------
- connection <- connect(
- dbms = "sql server",
- user = Sys.getenv("CDM5_SQL_SERVER_USER"),
- password = URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD")),
- server = Sys.getenv("CDM5_SQL_SERVER_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_SQL_SERVER_CDM_SCHEMA")
-
- sql <- "SELECT TOP 10 * FROM @cdm_database_schema.vocabulary"
- renderedSql <- SqlRender::render(sql, cdm_database_schema = cdmDatabaseSchema)
-
- queryResult <- dbSendQuery(connection, renderedSql)
- df <- dbFetch(queryResult)
- dbClearResult(queryResult)
-
- disconnect(connection)
-
- # RedShift ----------------------------------------------
- connection <- connect(
- dbms = "redshift",
- user = Sys.getenv("CDM5_REDSHIFT_USER"),
- password = URLdecode(Sys.getenv("CDM5_REDSHIFT_PASSWORD")),
- server = Sys.getenv("CDM5_REDSHIFT_SERVER")
- )
- cdmDatabaseSchema <- Sys.getenv("CDM5_REDSHIFT_CDM_SCHEMA")
-
- sql <- "SELECT TOP 10 * FROM @cdm_database_schema.vocabulary"
- renderedSql <- SqlRender::render(sql, cdm_database_schema = cdmDatabaseSchema)
-
- queryResult <- dbSendQuery(connection, renderedSql)
- df <- dbFetch(queryResult)
- dbClearResult(queryResult)
-
- disconnect(connection)
-})
+for (testServer in testServers) {
+ test_that(addDbmsToLabel("Fetch results", testServer), {
+ connection <- connect(testServer$connectionDetails)
+ on.exit(disconnect(connection))
+ sql <- "SELECT COUNT(*) AS row_count FROM @cdm_database_schema.vocabulary"
+ renderedSql <- SqlRender::render(sql = sql,
+ cdm_database_schema = testServer$cdmDatabaseSchema)
+
+ # Fetch data.frame:
+ count <- querySql(connection, renderedSql)
+ expect_gt(count[1, 1], 1)
+ count <- renderTranslateQuerySql(connection = connection,
+ sql = sql,
+ cdm_database_schema = testServer$cdmDatabaseSchema)
+ expect_gt(count[1, 1], 1)
+
+ # Fetch Andromeda:
+ andromeda <- Andromeda::andromeda()
+ querySqlToAndromeda(connection = connection,
+ sql = renderedSql,
+ andromeda = andromeda,
+ andromedaTableName = "test",
+ snakeCaseToCamelCase = TRUE)
+ expect_gt(dplyr::collect(andromeda$test)$rowCount[1], 1)
+ renderTranslateQuerySqlToAndromeda(connection,
+ sql,
+ cdm_database_schema = testServer$cdmDatabaseSchema,
+ andromeda = andromeda,
+ andromedaTableName = "test2",
+ snakeCaseToCamelCase = TRUE
+ )
+ expect_gt(dplyr::collect(andromeda$test2)$rowCount[1], 1)
+ Andromeda::close(andromeda)
+ })
+}
test_that("Logging query times", {
skip_if_not_installed("ParallelLogger")
diff --git a/tests/testthat/test-getTableNames.R b/tests/testthat/test-getTableNames.R
index 54925ee0..7a484e53 100644
--- a/tests/testthat/test-getTableNames.R
+++ b/tests/testthat/test-getTableNames.R
@@ -1,159 +1,15 @@
library(testthat)
-test_that("Get table names", {
- # Postgresql --------------------------------------------------
- details <- createConnectionDetails(
- dbms = "postgresql",
- user = Sys.getenv("CDM5_POSTGRESQL_USER"),
- password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD")),
- server = Sys.getenv("CDM5_POSTGRESQL_SERVER")
- )
- connection <- connect(details)
- tables <- getTableNames(connection, Sys.getenv("CDM5_POSTGRESQL_CDM_SCHEMA"))
- expect_true("person" %in% tables)
- expect_true(existsTable(connection, Sys.getenv("CDM5_POSTGRESQL_CDM_SCHEMA"), "person"))
- expect_true(DBI::dbExistsTable(connection, "person"))
- disconnect(connection)
-
- # SQL Server --------------------------------------------------
- details <- createConnectionDetails(
- dbms = "sql server",
- user = Sys.getenv("CDM5_SQL_SERVER_USER"),
- password = URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD")),
- server = Sys.getenv("CDM5_SQL_SERVER_SERVER")
- )
- connection <- connect(details)
- tables <- getTableNames(connection, Sys.getenv("CDM5_SQL_SERVER_CDM_SCHEMA"))
- expect_true("person" %in% tables)
- expect_true(existsTable(connection, Sys.getenv("CDM5_SQL_SERVER_CDM_SCHEMA"), "person"))
- # This does not work on SQL Server:
- # expect_true(DBI::dbExistsTable(connection, "person"))
- disconnect(connection)
-
- # Oracle --------------------------------------------------
- details <- createConnectionDetails(
- dbms = "oracle",
- user = Sys.getenv("CDM5_ORACLE_USER"),
- password = URLdecode(Sys.getenv("CDM5_ORACLE_PASSWORD")),
- server = Sys.getenv("CDM5_ORACLE_SERVER")
- )
- connection <- connect(details)
- tables <- getTableNames(connection, Sys.getenv("CDM5_ORACLE_CDM_SCHEMA"))
- expect_true("person" %in% tables)
- expect_true(existsTable(connection, Sys.getenv("CDM5_ORACLE_CDM_SCHEMA"), "person"))
- expect_true(DBI::dbExistsTable(connection, "person"))
- disconnect(connection)
-
- # Sqlite --------------------------------------------------
- dbFile <- tempfile()
- details <- createConnectionDetails(
- dbms = "sqlite",
- server = dbFile
- )
- connection <- connect(details)
- executeSql(connection, "CREATE TABLE person (x INT);")
- tables <- getTableNames(connection, "main")
- expect_true("person" %in% tables)
- expect_true(existsTable(connection, "main", "person"))
- expect_true(DBI::dbExistsTable(connection, "person"))
- disconnect(connection)
- unlink(dbFile)
-
- # RedShift --------------------------------------------------
- details <- createConnectionDetails(
- dbms = "redshift",
- user = Sys.getenv("CDM5_REDSHIFT_USER"),
- password = URLdecode(Sys.getenv("CDM5_REDSHIFT_PASSWORD")),
- server = Sys.getenv("CDM5_REDSHIFT_SERVER")
- )
- connection <- connect(details)
- tables <- getTableNames(connection, Sys.getenv("CDM5_REDSHIFT_CDM_SCHEMA"))
- expect_true("person" %in% tables)
- expect_true(existsTable(connection, Sys.getenv("CDM5_REDSHIFT_CDM_SCHEMA"), "person"))
- expect_true(DBI::dbExistsTable(connection, "person"))
- disconnect(connection)
-
- # DuckDB --------------------------------------------------
- dbFile <- tempfile()
- details <- createConnectionDetails(
- dbms = "duckdb",
- server = dbFile
- )
- connection <- connect(details)
- executeSql(connection, "CREATE TABLE person (x INT);")
- tables <- getTableNames(connection, "main")
- expect_true("person" %in% tables)
- expect_true(existsTable(connection, "main", "person"))
- expect_true(DBI::dbExistsTable(connection, "person"))
- disconnect(connection)
- unlink(dbFile)
-})
-
-test_that("Cleaning of database or schema name", {
- expect_equivalent(cleanSchemaName("[test\\name]"), "test\\\\name")
- expect_equivalent(cleanSchemaName("\"test\\name\""), "test\\\\name")
- expect_equivalent(cleanDatabaseName("test\\name"), "test\\name")
-})
-
-test_that("Get table names using DBI drivers", {
- skip_if_not(Sys.getenv("RUN_DATABASECONNECTOR_DBI_DRIVER_TESTS") == "TRUE")
-
- # Postgresql with RPostgres driver -----------------------------
- connection <- con <- DBI::dbConnect(RPostgres::Postgres(),
- dbname = Sys.getenv("CDM5_POSTGRESQL_DBNAME"),
- host = Sys.getenv("CDM5_POSTGRESQL_HOST"),
- user = Sys.getenv("CDM5_POSTGRESQL_USER"),
- password = Sys.getenv("CDM5_POSTGRESQL_PASSWORD"))
- tables <- getTableNames(connection, Sys.getenv("CDM5_POSTGRESQL_CDM_SCHEMA"))
- expect_true("person" %in% tables)
- expect_true(existsTable(connection, Sys.getenv("CDM5_POSTGRESQL_CDM_SCHEMA"), "person"))
- DBI::dbDisconnect(connection)
-
- # SQL Server with odbc driver ----------------------------------
- connection <- DBI::dbConnect(odbc::odbc(),
- Driver = "ODBC Driver 18 for SQL Server",
- Server = Sys.getenv("CDM5_SQL_SERVER_SERVER"),
- Database = Sys.getenv("CDM5_SQL_SERVER_CDM_DATABASE"),
- UID = Sys.getenv("CDM5_SQL_SERVER_USER"),
- PWD = Sys.getenv("CDM5_SQL_SERVER_PASSWORD"),
- TrustServerCertificate = "yes",
- Port = 1433)
- tables <- getTableNames(connection, Sys.getenv("CDM5_SQL_SERVER_CDM_SCHEMA"))
- expect_true("person" %in% tables)
- expect_true(existsTable(connection, Sys.getenv("CDM5_SQL_SERVER_CDM_SCHEMA"), "person"))
- DBI::dbDisconnect(connection)
-
- # Sqlite --------------------------------------------------
-
- dbFile <- tempfile()
- connection <- DBI::dbConnect(RSQLite::SQLite(), dbname = dbFile)
- DBI::dbExecute(connection, "CREATE TABLE person (x INT);")
- tables <- getTableNames(connection, "main")
- expect_true("person" %in% tables)
- expect_true(existsTable(connection, "main", "person"))
- DBI::dbDisconnect(connection)
- unlink(dbFile)
-
- # duckdb --------------------------------------------------
-
- connection <- DBI::dbConnect(duckdb::duckdb())
- DBI::dbExecute(connection, "CREATE SCHEMA test")
- DBI::dbExecute(connection, "CREATE TABLE test.person (x INT);")
- tables <- getTableNames(connection, "test")
- expect_true("person" %in% tables)
- expect_true(existsTable(connection, "test", "person"))
- DBI::dbDisconnect(connection)
-
- # RedShift --------------------------------------------------
- connection <- DBI::dbConnect(RPostgres::Redshift(),
- dbname = Sys.getenv("CDM5_REDSHIFT_DBNAME"),
- host = Sys.getenv("CDM5_REDSHIFT_HOST"),
- port = Sys.getenv("CDM5_REDSHIFT_PORT"),
- user = Sys.getenv("CDM5_REDSHIFT_USER"),
- password = Sys.getenv("CDM5_REDSHIFT_PASSWORD"))
-
- tables <- getTableNames(connection, Sys.getenv("CDM5_REDSHIFT_CDM_SCHEMA"))
- expect_true("person" %in% tables)
- expect_true(existsTable(connection, Sys.getenv("CDM5_REDSHIFT_CDM_SCHEMA"), "person"))
- DBI::dbDisconnect(connection)
-})
+for (testServer in testServers) {
+ test_that(addDbmsToLabel("Get table names", testServer), {
+ connection <- connect(testServer$connectionDetails)
+ on.exit(disconnect(connection))
+ tables <- getTableNames(connection, testServer$cdmDatabaseSchema)
+ expect_true("person" %in% tables)
+ expect_true(existsTable(connection, testServer$cdmDatabaseSchema, "person"))
+ # This does not work on SQL Server:
+ if (testServer$connectionDetails$dbms != "sql server") {
+ expect_true(DBI::dbExistsTable(connection, "person"))
+ }
+ })
+}
diff --git a/tests/testthat/test-insertTable.R b/tests/testthat/test-insertTable.R
index 9f07df57..fde69f64 100644
--- a/tests/testthat/test-insertTable.R
+++ b/tests/testthat/test-insertTable.R
@@ -6,263 +6,101 @@ if (DatabaseConnector:::is_installed("ParallelLogger")) {
ParallelLogger::addDefaultFileLogger(logFileName, name = "TEST_LOGGER")
}
-
-test_that("insertTable", {
- set.seed(0)
- day.start <- "1960/01/01"
- day.end <- "2000/12/31"
- time.start <- as.POSIXct("2018-11-12 09:04:07 CET")
- dayseq <- seq.Date(as.Date(day.start), as.Date(day.end), by = "week")
- timeSeq <- time.start + (1:length(dayseq)) * 60 * 60 * 24
- makeRandomStrings <- function(n = 1, lenght = 12) {
- randomString <- c(1:n)
- for (i in 1:n) {
- randomString[i] <- paste(sample(c(0:9, letters, LETTERS), lenght, replace = TRUE),
- collapse = ""
- )
- }
- return(randomString)
+set.seed(0)
+day.start <- "1960/01/01"
+day.end <- "2000/12/31"
+time.start <- as.POSIXct("2018-11-12 09:04:07")
+dayseq <- seq.Date(as.Date(day.start), as.Date(day.end), by = "week")
+timeSeq <- time.start + (1:length(dayseq)) * 60 * 60 * 24
+makeRandomStrings <- function(n = 1, lenght = 12) {
+ randomString <- c(1:n)
+ for (i in 1:n) {
+ randomString[i] <- paste(sample(c(0:9, letters, LETTERS), lenght, replace = TRUE),
+ collapse = ""
+ )
}
- bigInts <- bit64::runif64(length(dayseq))
- data <- data.frame(
- start_date = dayseq,
- some_datetime = timeSeq,
- person_id = as.integer(round(runif(length(dayseq), 1, 1e+07))),
- value = runif(length(dayseq)),
- id = makeRandomStrings(length(dayseq)),
- big_ints = bigInts,
- stringsAsFactors = FALSE
- )
-
- data$start_date[4] <- NA
- data$some_datetime[6] <- NA
- data$person_id[5] <- NA
- data$value[2] <- NA
- data$id[3] <- NA
- data$big_ints[7] <- NA
- data$big_ints[8] <- 3.3043e+10
-
- # Postgresql --------------------------------------
- details <- createConnectionDetails(
- dbms = "postgresql",
- user = Sys.getenv("CDM5_POSTGRESQL_USER"),
- password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD")),
- server = Sys.getenv("CDM5_POSTGRESQL_SERVER")
- )
- connection <- connect(details)
- insertTable(
- connection = connection,
- tableName = "temp",
- data = data,
- createTable = TRUE,
- tempTable = TRUE
- )
-
- # Check data on server is same as local
- data2 <- querySql(connection, "SELECT * FROM temp", integer64AsNumeric = FALSE)
- names(data2) <- tolower(names(data2))
- expect_equal(data, data2, check.attributes = FALSE)
-
- # Check data types
- res <- dbSendQuery(connection, "SELECT * FROM temp")
- columnInfo <- dbColumnInfo(res)
- dbClearResult(res)
- expect_equal(as.character(columnInfo$field.type), c("date", "timestamp", "int4", "numeric", "varchar", "int8"))
-
- disconnect(connection)
-
-
- # SQL Server ----------------------------------------------
- details <- createConnectionDetails(
- dbms = "sql server",
- user = Sys.getenv("CDM5_SQL_SERVER_USER"),
- password = URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD")),
- server = Sys.getenv("CDM5_SQL_SERVER_SERVER")
- )
- connection <- connect(details)
- insertTable(
- connection = connection,
- tableName = "#temp",
- data = data,
- createTable = TRUE,
- tempTable = TRUE
- )
-
- # Check data on server is same as local
- data2 <- querySql(connection, "SELECT * FROM #temp", integer64AsNumeric = FALSE)
- names(data2) <- tolower(names(data2))
- data <- data[order(data$person_id), ]
- data2 <- data2[order(data2$person_id), ]
- row.names(data) <- NULL
- row.names(data2) <- NULL
- expect_equal(data, data2, check.attributes = FALSE)
-
- # Check data types
- res <- dbSendQuery(connection, "SELECT * FROM #temp")
- columnInfo <- dbColumnInfo(res)
- dbClearResult(res)
- expect_equal(as.character(columnInfo$field.type), c("date", "datetime2", "int", "float", "varchar", "bigint"))
-
- disconnect(connection)
-
-
- # Oracle -----------------------------------------
- details <- createConnectionDetails(
- dbms = "oracle",
- user = Sys.getenv("CDM5_ORACLE_USER"),
- password = URLdecode(Sys.getenv("CDM5_ORACLE_PASSWORD")),
- server = Sys.getenv("CDM5_ORACLE_SERVER")
- )
- schema <- Sys.getenv("CDM5_ORACLE_OHDSI_SCHEMA")
- connection <- connect(details)
- insertTable(
- connection = connection,
- databaseSchema = schema,
- tableName = "temp",
- data = data,
- createTable = TRUE,
- tempTable = FALSE
- )
-
-
- # lowLevelQuerySql(connection, "SELECT * FROM all_tab_columns WHERE owner = 'OHDSI' AND table_name = 'TEMP'")
-
- # Check data on server is same as local
- sql <- SqlRender::render("SELECT * FROM @schema.temp", schema = schema)
- data2 <- querySql(connection, sql, integer64AsNumeric = FALSE)
- names(data2) <- tolower(names(data2))
- data <- data[order(data$person_id), ]
- data2 <- data2[order(data2$person_id), ]
- row.names(data) <- NULL
- row.names(data2) <- NULL
- expect_equal(data, data2, check.attributes = FALSE)
-
- # Check data types
- res <- dbSendQuery(connection, sprintf("SELECT * FROM %s.temp", schema))
- columnInfo <- dbColumnInfo(res)
- dbClearResult(res)
- expect_equal(as.character(columnInfo$field.type), c("DATE", "TIMESTAMP", "NUMBER", "NUMBER", "VARCHAR2", "NUMBER"))
-
- dropEmulatedTempTables(connection)
-
- disconnect(connection)
-
- # SQLite ---------------------------------------------------------------
- dbFile <- tempfile()
- details <- createConnectionDetails(
- dbms = "sqlite",
- server = dbFile
- )
- connection <- connect(details)
- insertTable(
- connection = connection,
- tableName = "temp",
- data = data,
- createTable = TRUE,
- tempTable = FALSE
- )
-
- # Check data on server is same as local
- data2 <- querySql(connection, "SELECT * FROM temp", integer64AsNumeric = FALSE)
- names(data2) <- tolower(names(data2))
- data <- data[order(data$person_id), ]
- data2 <- data2[order(data2$person_id), ]
- row.names(data) <- NULL
- row.names(data2) <- NULL
-
- attr(data$some_datetime, "tzone") <- NULL
- attr(data2$some_datetime, "tzone") <- NULL
- expect_equal(data, data2, check.attributes = FALSE)
-
- # Check data types
- res <- dbSendQuery(connection, "SELECT * FROM temp")
- columnInfo <- dbColumnInfo(res)
- dbClearResult(res)
- expect_equal(as.character(columnInfo$type), c("double", "double", "integer", "double", "character", "double"))
-
- disconnect(connection)
- unlink(dbFile)
-
- # RedShift --------------------------------------
- details <- createConnectionDetails(
- dbms = "redshift",
- user = Sys.getenv("CDM5_REDSHIFT_USER"),
- password = URLdecode(Sys.getenv("CDM5_REDSHIFT_PASSWORD")),
- server = Sys.getenv("CDM5_REDSHIFT_SERVER")
- )
- connection <- connect(details)
-
- # Use subset of data because inserts on RedShift are slow:
- subset <- data[1:10, ]
-
- insertTable(
- connection = connection,
- tableName = "temp",
- data = subset,
- createTable = TRUE,
- tempTable = TRUE
- )
-
- # Check data on server is same as local
- data2 <- querySql(connection, "SELECT * FROM temp", integer64AsNumeric = FALSE)
- names(data2) <- tolower(names(data2))
- subset <- subset[order(subset$person_id), ]
- data2 <- data2[order(data2$person_id), ]
- expect_equal(subset, data2, check.attributes = FALSE)
-
- # Check data types
- res <- dbSendQuery(connection, "SELECT * FROM temp")
- columnInfo <- dbColumnInfo(res)
- dbClearResult(res)
- expect_equal(as.character(columnInfo$field.type), c("date", "timestamp", "int4", "float8", "varchar", "int8"))
-
- disconnect(connection)
-
-
- # DuckDb ---------------------------------------------------------------
- dbFile <- tempfile()
- details <- createConnectionDetails(
- dbms = "duckdb",
- server = dbFile
- )
- connection <- connect(details)
- insertTable(
- connection = connection,
- tableName = "temp",
- data = data,
- createTable = TRUE,
- tempTable = FALSE
- )
-
- # Check data on server is same as local
- data2 <- querySql(connection, "SELECT * FROM temp", integer64AsNumeric = FALSE)
- names(data2) <- tolower(names(data2))
- data <- data[order(data$person_id), ]
- data2 <- data2[order(data2$person_id), ]
- row.names(data) <- NULL
- row.names(data2) <- NULL
- attr(data$some_datetime, "tzone") <- NULL
- attr(data2$some_datetime, "tzone") <- NULL
- expect_equal(data, data2, check.attributes = FALSE)
-
- # Check data types
- res <- dbSendQuery(connection, "SELECT * FROM temp")
- columnInfo <- dbColumnInfo(res)
- dbClearResult(res)
- expect_equal(as.character(columnInfo$type), c("Date", "POSIXct", "integer", "numeric", "character", "numeric"))
-
- disconnect(connection)
- unlink(dbFile)
-})
+ return(randomString)
+}
+bigInts <- bit64::runif64(length(dayseq))
+data <- data.frame(
+ start_date = dayseq,
+ some_datetime = timeSeq,
+ person_id = as.integer(round(runif(length(dayseq), 1, 1e+07))),
+ value = runif(length(dayseq)),
+ id = makeRandomStrings(length(dayseq)),
+ big_ints = bigInts,
+ stringsAsFactors = FALSE
+)
-test_that("Test temp emulation helper functions", {
- expect_true(requiresTempEmulation("bigquery"))
- expect_false(requiresTempEmulation("postgresql"))
-
- expect_error(assertTempEmulationSchemaSet("oracle", tempEmulationSchema = NULL), "emp emulation schema is not set")
- expect_no_error(assertTempEmulationSchemaSet("oracle", tempEmulationSchema = "some_schema"))
- expect_no_error(assertTempEmulationSchemaSet("sql server", tempEmulationSchema = NULL))
-})
+data$start_date[4] <- NA
+data$some_datetime[6] <- NA
+data$person_id[5] <- NA
+data$value[2] <- NA
+data$id[3] <- NA
+data$big_ints[7] <- NA
+data$big_ints[8] <- 3.3043e+10
+
+for (testServer in testServers) {
+ test_that(addDbmsToLabel("Insert data", testServer), {
+ if (testServer$connectionDetails$dbms %in% c("redshift", "bigquery")) {
+ # Inserting on RedShift or BigQuery is slow (Without bulk upload), so
+ # taking subset:
+ dataCopy1 <- data[1:10, ]
+ } else {
+ dataCopy1 <- data
+ }
+
+ connection <- connect(testServer$connectionDetails)
+ options(sqlRenderTempEmulationSchema = testServer$tempEmulationSchema)
+ on.exit(dropEmulatedTempTables(connection))
+ on.exit(disconnect(connection), add = TRUE)
+ insertTable(
+ connection = connection,
+ tableName = "#temp",
+ data = dataCopy1,
+ createTable = TRUE,
+ tempTable = TRUE
+ )
+
+ # Check data on server is same as local
+ dataCopy2 <- renderTranslateQuerySql(connection, "SELECT * FROM #temp;", integer64AsNumeric = FALSE)
+ names(dataCopy2) <- tolower(names(dataCopy2))
+ dataCopy1 <- data[order(dataCopy1$person_id), ]
+ dataCopy2 <- dataCopy2[order(dataCopy2$person_id), ]
+ row.names(dataCopy1) <- NULL
+ row.names(dataCopy2) <- NULL
+ attr(dataCopy1$some_datetime, "tzone") <- NULL
+ attr(dataCopy2$some_datetime, "tzone") <- NULL
+ expect_equal(dataCopy1, dataCopy2, check.attributes = FALSE, tolerance = 1e-7)
+
+ # Check data types
+ res <- dbSendQuery(connection, "SELECT * FROM #temp;")
+ columnInfo <- dbColumnInfo(res)
+ dbClearResult(res)
+ dbms <- testServer$connectionDetails$dbms
+ if (dbms == "postgresql") {
+ expect_equal(as.character(columnInfo$field.type), c("date", "timestamp", "int4", "numeric", "varchar", "int8"))
+ } else if (dbms == "sql server") {
+ expect_equal(as.character(columnInfo$field.type), c("date", "datetime2", "int", "float", "varchar", "bigint"))
+ } else if (dbms == "oracle") {
+ expect_equal(as.character(columnInfo$field.type), c("DATE", "TIMESTAMP", "NUMBER", "NUMBER", "VARCHAR2", "NUMBER"))
+ } else if (dbms == "redshift") {
+ expect_equal(as.character(columnInfo$field.type), c("date", "timestamp", "int4", "float8", "varchar", "int8" ))
+ } else if (dbms == "sqlite") {
+ expect_equal(as.character(columnInfo$type), c("double", "double", "integer", "double", "character", "double"))
+ } else if (dbms == "duckdb") {
+ expect_equal(as.character(columnInfo$type), c("Date", "POSIXct", "integer", "numeric", "character", "numeric"))
+ } else if (dbms == "snowflake") {
+ expect_equal(as.character(columnInfo$field.type), c("DATE", "TIMESTAMPNTZ", "NUMBER", "DOUBLE", "VARCHAR", "NUMBER"))
+ } else if (dbms == "spark") {
+ expect_equal(as.character(columnInfo$field.type), c("DATE", "TIMESTAMP", "INT", "FLOAT", "STRING", "BIGINT"))
+ } else if (dbms == "bigquery") {
+ expect_equal(as.character(columnInfo$field.type), c("DATE", "DATETIME", "INT64", "FLOAT64", "STRING", "INT64"))
+ } else {
+ warning("Unable to check column types for ", dbms)
+ }
+ })
+}
test_that("Logging insertTable times", {
skip_if_not_installed("ParallelLogger")
@@ -274,31 +112,30 @@ test_that("Logging insertTable times", {
unlink(logFileName)
})
-test_that("Converting logical to numeric in insertTable", {
- data <- data.frame(
- id = 1:3,
- isPrime = c(NA, FALSE, TRUE)
- )
- details <- createConnectionDetails(
- dbms = "postgresql",
- user = Sys.getenv("CDM5_POSTGRESQL_USER"),
- password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD")),
- server = Sys.getenv("CDM5_POSTGRESQL_SERVER")
- )
- connection <- connect(details)
- expect_warning(
- insertTable(
- connection = connection,
- tableName = "temp",
- data = data,
- createTable = TRUE,
- tempTable = TRUE
- ),
- "Column 'isPrime' is of type 'logical'")
-
- data2 <- querySql(connection, "SELECT * FROM temp")
- data$isPrime <- as.numeric(data$isPrime)
- names(data2) <- tolower(names(data2))
- expect_equal(data, data2, check.attributes = FALSE)
- disconnect(connection)
-})
+data <- data.frame(
+ id = 1:3,
+ isPrime = c(NA, FALSE, TRUE)
+)
+
+for (testServer in testServers) {
+ test_that(addDbmsToLabel("Converting logical to numeric in insertTable", testServer), {
+ connection <- connect(testServer$connectionDetails)
+ options(sqlRenderTempEmulationSchema = testServer$tempEmulationSchema)
+ on.exit(dropEmulatedTempTables(connection))
+ on.exit(disconnect(connection), add = TRUE)
+ expect_warning(
+ insertTable(
+ connection = connection,
+ tableName = "#temp",
+ data = data,
+ createTable = TRUE,
+ tempTable = TRUE
+ ),
+ "Column 'isPrime' is of type 'logical'")
+ data2 <- renderTranslateQuerySql(connection, "SELECT * FROM #temp;")
+ data$isPrime <- as.numeric(data$isPrime)
+ names(data2) <- tolower(names(data2))
+ data2 <- data2[order(data2$id), ]
+ expect_equal(data, data2, check.attributes = FALSE)
+ })
+}
diff --git a/tests/testthat/test-sendUpdates.R b/tests/testthat/test-sendUpdates.R
index ad5d8009..937b8a45 100644
--- a/tests/testthat/test-sendUpdates.R
+++ b/tests/testthat/test-sendUpdates.R
@@ -1,83 +1,20 @@
library(testthat)
-if (DatabaseConnector:::is_installed("ParallelLogger")) {
- logFileName <- tempfile(fileext = ".txt")
- ParallelLogger::addDefaultFileLogger(logFileName, name = "TEST_LOGGER")
-}
-
-test_that("Send updates to server", {
- sql <- "CREATE TABLE #temp (x INT);
+sql <- "CREATE TABLE #temp (x INT);
INSERT INTO #temp (x) SELECT 123;
DELETE FROM #temp WHERE x = 123;
DROP TABLE #temp;"
- # Postgresql --------------------------------------------------
- details <- createConnectionDetails(
- dbms = "postgresql",
- user = Sys.getenv("CDM5_POSTGRESQL_USER"),
- password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD")),
- server = Sys.getenv("CDM5_POSTGRESQL_SERVER")
- )
- connection <- connect(details)
-
- expect_null(renderTranslateExecuteSql(connection, sql))
-
- expect_true(sum(renderTranslateExecuteSql(connection, sql, runAsBatch = TRUE)) > 0)
-
- disconnect(connection)
-
- # SQL Server --------------------------------------------------
- details <- createConnectionDetails(
- dbms = "sql server",
- user = Sys.getenv("CDM5_SQL_SERVER_USER"),
- password = URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD")),
- server = Sys.getenv("CDM5_SQL_SERVER_SERVER")
- )
- connection <- connect(details)
-
- expect_null(renderTranslateExecuteSql(connection, sql))
-
- expect_true(sum(renderTranslateExecuteSql(connection, sql, runAsBatch = TRUE)) > 0)
-
- disconnect(connection)
-
- # Oracle --------------------------------------------------
- details <- createConnectionDetails(
- dbms = "oracle",
- user = Sys.getenv("CDM5_ORACLE_USER"),
- password = URLdecode(Sys.getenv("CDM5_ORACLE_PASSWORD")),
- server = Sys.getenv("CDM5_ORACLE_SERVER")
- )
- connection <- connect(details)
-
- expect_null(renderTranslateExecuteSql(connection, sql))
-
- expect_true(sum(renderTranslateExecuteSql(connection, sql, runAsBatch = TRUE)) > 0)
-
- disconnect(connection)
-
- # RedShift --------------------------------------------------
- details <- createConnectionDetails(
- dbms = "redshift",
- user = Sys.getenv("CDM5_REDSHIFT_USER"),
- password = URLdecode(Sys.getenv("CDM5_REDSHIFT_PASSWORD")),
- server = Sys.getenv("CDM5_REDSHIFT_SERVER")
- )
- connection <- connect(details)
-
- expect_null(renderTranslateExecuteSql(connection, sql))
-
- expect_true(sum(renderTranslateExecuteSql(connection, sql, runAsBatch = TRUE)) > 0)
-
- disconnect(connection)
-})
-
-test_that("Logging update times", {
- skip_if_not_installed("ParallelLogger")
- log <- readLines(logFileName)
- statementCount <- sum(grepl("Executing SQL:", log))
- expect_gt(statementCount, 19)
- # writeLines(log)
- ParallelLogger::unregisterLogger("TEST_LOGGER")
- unlink(logFileName)
-})
+for (testServer in testServers) {
+ test_that(addDbmsToLabel("Send updates", testServer), {
+ connection <- connect(testServer$connectionDetails)
+ options(sqlRenderTempEmulationSchema = testServer$tempEmulationSchema)
+ on.exit(dropEmulatedTempTables(connection))
+ on.exit(disconnect(connection), add = TRUE)
+ expect_equal(renderTranslateExecuteSql(connection, sql), c(0, 1, 1, 0))
+ expect_equal(renderTranslateExecuteSql(connection, sql, runAsBatch = TRUE), c(0, 1, 1, 0))
+ rowsAffected <- dbSendStatement(connection, sql)
+ expect_equal(dbGetRowsAffected(rowsAffected), 2)
+ dbClearResult(rowsAffected)
+ })
+}
diff --git a/tests/testthat/test-sqlite.R b/tests/testthat/test-sqlite.R
deleted file mode 100644
index a168d896..00000000
--- a/tests/testthat/test-sqlite.R
+++ /dev/null
@@ -1,54 +0,0 @@
-library(testthat)
-
-test_that("Open and close SQLite connection", {
- databaseFile <- tempfile()
- connection <- DatabaseConnector::connect(dbms = "sqlite", server = databaseFile)
- expect_s4_class(connection, "DatabaseConnectorDbiConnection")
-
- disconnect(connection)
- unlink(databaseFile)
-})
-
-test_that("Insert and retrieve dates from SQLite", {
- databaseFile <- tempfile()
- connection <- DatabaseConnector::connect(dbms = "sqlite", server = databaseFile)
-
- data <- data.frame(startDate = as.Date(c("2000-01-01", "2000-02-01")))
- insertTable(
- connection = connection,
- databaseSchema = "main",
- tableName = "test",
- data = data,
- createTable = TRUE,
- camelCaseToSnakeCase = TRUE
- )
- data2 <- renderTranslateQuerySql(
- connection = connection,
- sql = "SELECT * FROM main.test;",
- snakeCaseToCamelCase = TRUE)
- expect_equal(data, data2)
- disconnect(connection)
- unlink(databaseFile)
-})
-
-test_that("Insert using tibbles and retrieve dates from SQLite", {
- databaseFile <- tempfile()
- connection <- DatabaseConnector::connect(dbms = "sqlite", server = databaseFile)
-
- data <- dplyr::tibble(startDate = as.Date(c("2000-01-01", "2000-02-01")))
- insertTable(
- connection = connection,
- databaseSchema = "main",
- tableName = "test",
- data = data,
- createTable = TRUE,
- camelCaseToSnakeCase = TRUE
- )
- data2 <- renderTranslateQuerySql(
- connection = connection,
- sql = "SELECT * FROM main.test;",
- snakeCaseToCamelCase = TRUE)
- expect_equal(data, dplyr::as_tibble(data2))
- disconnect(connection)
- unlink(databaseFile)
-})