diff --git a/R/Connect.R b/R/Connect.R index 9e330e82..7e4dc406 100644 --- a/R/Connect.R +++ b/R/Connect.R @@ -760,22 +760,7 @@ connectUsingJdbcDriver <- function(jdbcDriver, abort(paste0("Unable to connect JDBC to ", url, " (", rJava::.jcall(x, "S", "getMessage"), ")")) } } - class <- getClassDef("Microsoft SQL Server", where = class_cache, inherits = FALSE) - if (is.null(class) || methods::isVirtualClass(class)) { - setClass("Microsoft SQL Server", - contains = "DBIConnection", - where = class_cache) - } - class <- getClassDef("DatabaseConnectorConnection", where = class_cache, inherits = FALSE) - if (is.null(class) || methods::isVirtualClass(class)) { - setClass("DatabaseConnectorConnection", - contains = "Microsoft SQL Server", - slots = list( - identifierQuote = "character", - stringQuote = "character", dbms = "character", uuid = "character" - ), - where = class_cache) - } + ensureDatabaseConnectorConnectionClassExists() class <- getClassDef("DatabaseConnectorJdbcConnection", where = class_cache, inherits = FALSE) if (is.null(class) || methods::isVirtualClass(class)) { setClass("DatabaseConnectorJdbcConnection", @@ -783,7 +768,6 @@ connectUsingJdbcDriver <- function(jdbcDriver, slots = list(jConnection = "jobjRef"), where = class_cache) } - connection <- new("DatabaseConnectorJdbcConnection", jConnection = jConnection, identifierQuote = "", @@ -796,10 +780,42 @@ connectUsingJdbcDriver <- function(jdbcDriver, return(connection) } +ensureDatabaseConnectorConnectionClassExists <- function() { + class <- getClassDef("Microsoft SQL Server", where = class_cache, inherits = FALSE) + if (is.null(class) || methods::isVirtualClass(class)) { + setClass("Microsoft SQL Server", + contains = "DBIConnection", + where = class_cache) + } + class <- getClassDef("DatabaseConnectorConnection", where = class_cache, inherits = FALSE) + if (is.null(class) || methods::isVirtualClass(class)) { + setClass("DatabaseConnectorConnection", + contains = "Microsoft SQL Server", + slots = list( + identifierQuote = "character", + stringQuote = "character", + dbms = "character", + uuid = "character" + ), + where = class_cache) + } +} + connectUsingDbi <- function(dbiConnectionDetails) { dbms <- dbiConnectionDetails$dbms dbiConnectionDetails$dbms <- NULL dbiConnection <- do.call(DBI::dbConnect, dbiConnectionDetails) + ensureDatabaseConnectorConnectionClassExists() + class <- getClassDef("DatabaseConnectorDbiConnection", where = class_cache, inherits = FALSE) + if (is.null(class) || methods::isVirtualClass(class)) { + setClass("DatabaseConnectorDbiConnection", + contains = "DatabaseConnectorConnection", + slots = list( + dbiConnection = "DBIConnection", + server = "character" + ), + where = class_cache) + } connection <- new("DatabaseConnectorDbiConnection", server = dbms, dbiConnection = dbiConnection, diff --git a/R/DBI.R b/R/DBI.R index 95de7f29..3044c0e4 100644 --- a/R/DBI.R +++ b/R/DBI.R @@ -72,15 +72,6 @@ setClass("DatabaseConnectorJdbcConnection", where = class_cache) setClass("DatabaseConnectorDbiConnection", where = class_cache) - -# setClass("DatabaseConnectorDbiConnection", -# contains = "DatabaseConnectorConnection", -# slots = list( -# dbiConnection = "DBIConnection", -# server = "character" -# ) -# ) - #' Create a connection to a DBMS #' #' @description