Skip to content

Commit

Permalink
drop temp table if exists at start of test
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeboe committed Oct 10, 2024
1 parent 026d0b3 commit e2b5986
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
50 changes: 50 additions & 0 deletions tests/testthat/test-bdb.R
Original file line number Diff line number Diff line change
@@ -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")
7 changes: 4 additions & 3 deletions tests/testthat/test-sendUpdates.R
Original file line number Diff line number Diff line change
@@ -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;"
Expand All @@ -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)
Expand Down

0 comments on commit e2b5986

Please sign in to comment.