From 9c000da4a3196446927850fb0369d4c507c3d771 Mon Sep 17 00:00:00 2001 From: Jamie Gilbert Date: Fri, 4 Oct 2024 09:57:18 -0700 Subject: [PATCH 1/2] Postgres bulk load when using connection string parameter --- R/BulkLoad.R | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/R/BulkLoad.R b/R/BulkLoad.R index e441ecee..c6a7f5b5 100644 --- a/R/BulkLoad.R +++ b/R/BulkLoad.R @@ -299,7 +299,19 @@ bulkLoadPostgres <- function(connection, sqlTableName, sqlFieldNames, sqlDataTyp readr::write_excel_csv(data, csvFileName, na = "") on.exit(unlink(csvFileName)) - hostServerDb <- strsplit(attr(connection, "server")(), "/")[[1]] + server <- attr(connection, "server")() + if (is.null(server)) { + # taken directly from DatabaseConnector R/RStudio.R - getServer.default, could an attr too? + databaseMetaData <- rJava::.jcall( + connection@jConnection, + "Ljava/sql/DatabaseMetaData;", + "getMetaData" + ) + server <- rJava::.jcall(databaseMetaData, "Ljava/lang/String;", "getURL") + server <- strsplit(server, "//")[[2]] + } + + hostServerDb <- strsplit(server, "/")[[1]] port <- attr(connection, "port")() user <- attr(connection, "user")() password <- attr(connection, "password")() From 928ad9d89b2832f54c8ecaf5329136b684bc3923 Mon Sep 17 00:00:00 2001 From: Jamie Gilbert Date: Fri, 4 Oct 2024 10:02:29 -0700 Subject: [PATCH 2/2] Update BulkLoad.R --- R/BulkLoad.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/BulkLoad.R b/R/BulkLoad.R index c6a7f5b5..c448b50a 100644 --- a/R/BulkLoad.R +++ b/R/BulkLoad.R @@ -308,7 +308,7 @@ bulkLoadPostgres <- function(connection, sqlTableName, sqlFieldNames, sqlDataTyp "getMetaData" ) server <- rJava::.jcall(databaseMetaData, "Ljava/lang/String;", "getURL") - server <- strsplit(server, "//")[[2]] + server <- strsplit(server, "//")[[1]][2] } hostServerDb <- strsplit(server, "/")[[1]]