Skip to content

Commit

Permalink
Now also dynamic class def for DBI
Browse files Browse the repository at this point in the history
  • Loading branch information
Admin_mschuemi authored and Admin_mschuemi committed Aug 9, 2023
1 parent 181676d commit 7333a35
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
50 changes: 33 additions & 17 deletions R/Connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -760,30 +760,14 @@ 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",
contains = "DatabaseConnectorConnection",
slots = list(jConnection = "jobjRef"),
where = class_cache)
}

connection <- new("DatabaseConnectorJdbcConnection",
jConnection = jConnection,
identifierQuote = "",
Expand All @@ -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,
Expand Down
9 changes: 0 additions & 9 deletions R/DBI.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7333a35

Please sign in to comment.