diff --git a/R/Andromeda.R b/R/Andromeda.R index 5f348820..83480b52 100644 --- a/R/Andromeda.R +++ b/R/Andromeda.R @@ -80,7 +80,7 @@ lowLevelQuerySqlToAndromeda.default <- function(connection, connection@jConnection, query, dbms(connection), - FALSE + TRUE ) on.exit(rJava::.jcall(batchedQuery, "V", "clear")) @@ -241,7 +241,6 @@ querySqlToAndromeda <- function(connection, if (packageVersion("Andromeda") < "0.6.0") { stop(sprintf("Andromeda version 0.6.0 or higher required, but version %s found", packageVersion("Andromeda"))) } - # Calling splitSql, because this will also strip trailing semicolons (which cause Oracle to crash). sqlStatements <- SqlRender::splitSql(sql) if (length(sqlStatements) > 1) { diff --git a/R/DBI.R b/R/DBI.R index 9b7a4ca0..5e4633cd 100644 --- a/R/DBI.R +++ b/R/DBI.R @@ -230,7 +230,7 @@ setMethod( conn@jConnection, statement, dbms, - FALSE + TRUE ), error = function(error) { # Rethrowing error to avoid 'no field, method or inner class called 'use_cli_format'' diff --git a/R/InsertTable.R b/R/InsertTable.R index 9e996695..4356e8c1 100644 --- a/R/InsertTable.R +++ b/R/InsertTable.R @@ -198,6 +198,7 @@ insertTable.default <- function(connection, useMppBulkLoad = Sys.getenv("USE_MPP_BULK_LOAD"), progressBar = FALSE, camelCaseToSnakeCase = FALSE) { + if (is(connection, "Pool")) { connection <- pool::poolCheckout(connection) on.exit(pool::poolReturn(connection)) @@ -334,7 +335,6 @@ insertTable.default <- function(connection, tempEmulationSchema = tempEmulationSchema ) batchSize <- 10000 - if (nrow(data) > 0) { if (progressBar) { pb <- txtProgressBar(style = 3) @@ -368,7 +368,8 @@ insertTable.default <- function(connection, } else if (is(column, "Date")) { rJava::.jcall(batchedInsert, "V", "setDate", i, as.character(column)) } else { - rJava::.jcall(batchedInsert, "V", "setString", i, as.character(column)) + column <- escapeJson(column) + rJava::.jcall(batchedInsert, "V", "setString", i, column) } return(NULL) } @@ -401,6 +402,7 @@ insertTable.DatabaseConnectorDbiConnection <- function(connection, useMppBulkLoad = Sys.getenv("USE_MPP_BULK_LOAD"), progressBar = FALSE, camelCaseToSnakeCase = FALSE) { + if (!is.null(oracleTempSchema) && oracleTempSchema != "") { warn("The 'oracleTempSchema' argument is deprecated. Use 'tempEmulationSchema' instead.", .frequency = "regularly", @@ -484,3 +486,9 @@ convertLogicalFields <- function(data) { } return(data) } + +escapeJson <- function(json) { + json <- gsub("'", "''", json, fixed = TRUE) # Escape single quotes + json <- gsub(";", "", json, fixed = TRUE) # Remove semicolons + return(json) +} \ No newline at end of file diff --git a/inst/java/DatabaseConnector.jar b/inst/java/DatabaseConnector.jar index 55c9ee86..d1711d51 100644 Binary files a/inst/java/DatabaseConnector.jar and b/inst/java/DatabaseConnector.jar differ diff --git a/java/org/ohdsi/databaseConnector/BatchedInsert.java b/java/org/ohdsi/databaseConnector/BatchedInsert.java index 987d4feb..74685fc4 100644 --- a/java/org/ohdsi/databaseConnector/BatchedInsert.java +++ b/java/org/ohdsi/databaseConnector/BatchedInsert.java @@ -156,7 +156,7 @@ public boolean executeBatch() throws SQLException, ParseException { private boolean executeBigQueryBatch() throws SQLException, ParseException { checkColumns(); try { - trySettingAutoCommit(false); + trySettingAutoCommit(true); int offset = 0; while (offset < rowCount) {