diff --git a/tests/testthat/test-bdb.R b/tests/testthat/test-bdb.R new file mode 100644 index 00000000..3d4f4f05 --- /dev/null +++ b/tests/testthat/test-bdb.R @@ -0,0 +1,50 @@ +library(usethis) +library(devtools) +#library(ParallelLogger) +#load_all("C:/Users/bdeboe/Github/intersystems-community/OHDSI-SqlRender", TRUE, TRUE, TRUE, TRUE, TRUE) +#.jaddClassPath("C:/Users/bdeboe/Github/intersystems-community/OHDSI-SqlRender/target/SqlRender-1.19.0-SNAPSHOT.jar") +load_all("C:/Users/bdeboe/Github/intersystems-community/OHDSI-DatabaseConnector", TRUE, TRUE, TRUE, TRUE, TRUE) + +#Sys.setenv(DATABASECONNECTOR_JAR = "C:\\InterSystems\\SQLML\\dev\\java\\lib\\1.8") +#options(LOG_DATABASECONNECTOR_SQL = TRUE) +# assign("noLogging", FALSE, envir = globalVars) +# logger<-createLogger(name="SIMPLE", threshold="TRACE", appenders=list(createConsoleAppender(layout=layoutTimestamp))) + +# ParallelLogger::logTrace("Trace this!") + +Sys.setenv("DATABASECONNECTOR_JAR_FOLDER" = "C:\\tmp\\ohdsi") +downloadJdbcDrivers("iris") + +connectionDetails <- createConnectionDetails( + dbms = "iris", + server = "localhost", + port = 51774, + database = "OMOP2", + user = "_SYSTEM", + password = "SYS" +) + +connection <- DatabaseConnector::connect(NULL, "iris", "_SYSTEM", "SYS", "localhost", 51774) +# connection <- DatabaseConnector::connect(NULL, "iris", "_SYSTEM", "SYS", "localhost", 51774, NULL, NULL, NULL, Sys.getenv("DATABASECONNECTOR_JAR")) +# connection <- DatabaseConnector::connect(connectionDetails) +# ParallelLogger::logTrace("connection succesfull!") + +# connection <- DatabaseConnector::connect(NULL, "iris", "SQLAdmin", "Welcome123!", NULL, NULL, NULL, NULL, "jdbc:IRIS://k8s-7dde6a84-a8a08f1d-624d64b975-b5e7efc5c79fe489.elb.us-east-1.amazonaws.com:443/USER/iris-jdbc.log:::true", Sys.getenv("DATABASECONNECTOR_JAR")) + +DatabaseConnector::renderTranslateQuerySql(connection, "SELECT 124 as \"test\"") + +# ParallelLogger::logTrace("so far so good!") + +DatabaseConnector::renderTranslateQuerySql(connection, "WITH x (abx) AS (SELECT 124 as ABX) SELECT * FROM x") + +sql <- "WITH rawData (x) AS (SELECT 123 AS x), summ AS (SELECT SUM(x) as s FROM rawData) CREATE TABLE ohdsi.t AS SELECT * FROM summ;" +SqlRender::translate(sql, "iris") +DatabaseConnector::renderTranslateExecuteSql(connection, sql) + + + +Sys.setenv("CDM_IRIS_USER" = "_SYSTEM") +Sys.setenv("CDM_IRIS_PASSWORD" = "SYS") +Sys.setenv("CDM_IRIS_CONNECTION_STRING" = "jdbc:IRIS://localhost:51774/OMOP") +Sys.setenv("CDM_IRIS_CDM53_SCHEMA" = "OMOP_CDM") +Sys.setenv("CDM_IRIS_OHDSI_SCHEMA" = "OMOP_Results") diff --git a/tests/testthat/test-sendUpdates.R b/tests/testthat/test-sendUpdates.R index 937b8a45..29109aa6 100644 --- a/tests/testthat/test-sendUpdates.R +++ b/tests/testthat/test-sendUpdates.R @@ -1,6 +1,7 @@ library(testthat) -sql <- "CREATE TABLE #temp (x INT); +sql <- "IF OBJECT_ID('tempdb..#temp', 'U') IS NOT NULL DROP TABLE #temp; + CREATE TABLE #temp (x INT); INSERT INTO #temp (x) SELECT 123; DELETE FROM #temp WHERE x = 123; DROP TABLE #temp;" @@ -11,8 +12,8 @@ for (testServer in testServers) { 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)) + expect_equal(renderTranslateExecuteSql(connection, sql), c(0, 0, 1, 1, 0)) + expect_equal(renderTranslateExecuteSql(connection, sql, runAsBatch = TRUE), c(0, 0, 1, 1, 0)) rowsAffected <- dbSendStatement(connection, sql) expect_equal(dbGetRowsAffected(rowsAffected), 2) dbClearResult(rowsAffected)