From d09922c57a1b4afabeafe83189a7672dc3d7049f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Fri, 6 Oct 2023 16:29:44 +0200 Subject: [PATCH 1/9] Add mysql argument to MariaDB() --- NAMESPACE | 2 ++ R/MariaDBConnection.R | 6 ++++++ R/MariaDBDriver.R | 6 ++++++ R/connect.R | 13 +++++++++++-- R/dbConnect_MariaDBDriver.R | 8 +++++++- man/dbConnect-MariaDBDriver-method.Rd | 7 ++++++- 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 3a989db3..60b793a9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,6 +27,8 @@ export(mariadbHasDefault) exportClasses(MariaDBConnection) exportClasses(MariaDBDriver) exportClasses(MariaDBResult) +exportClasses(MySQLConnection) +exportClasses(MySQLDriver) exportMethods(dbAppendTable) exportMethods(dbBegin) exportMethods(dbBind) diff --git a/R/MariaDBConnection.R b/R/MariaDBConnection.R index 7c4b627f..ac5efb3b 100644 --- a/R/MariaDBConnection.R +++ b/R/MariaDBConnection.R @@ -18,6 +18,12 @@ setClass("MariaDBConnection", ) ) +#' @export +#' @keywords internal +setClass("MySQLConnection", + contains = "MariaDBConnection" +) + # format() #' @export #' @rdname MariaDBConnection-class diff --git a/R/MariaDBDriver.R b/R/MariaDBDriver.R index cb677d5b..de3005c5 100644 --- a/R/MariaDBDriver.R +++ b/R/MariaDBDriver.R @@ -10,6 +10,12 @@ setClass("MariaDBDriver", contains = "DBIDriver", ) +#' @export +#' @keywords internal +setClass("MySQLDriver", + contains = "MariaDBDriver", +) + #' MariaDB Check for Compiled Versus Loaded Client Library Versions #' #' This function prints out the compiled and loaded client library versions. diff --git a/R/connect.R b/R/connect.R index 0791e71b..2aa379dd 100644 --- a/R/connect.R +++ b/R/connect.R @@ -26,6 +26,11 @@ check_tz <- function(timezone) { } #' @export +#' @param mysql Set to `TRUE` to indicate the intent to connect to a MySQL server. +#' The \pkg{RMariaDB} package supports both MariaDB and MySQL servers, but the SQL dialect +#' and other details vary. +#' The default is to assume a MariaDB server. +#' #' @import methods DBI #' @importFrom hms hms #' @importFrom bit64 integer64 is.integer64 @@ -48,8 +53,12 @@ check_tz <- function(timezone) { #' # clean up #' dbDisconnect(con) #' } -MariaDB <- function() { - new("MariaDBDriver") +MariaDB <- function(mysql = FALSE) { + if (isTRUE(mysql)) { + new("MySQLDriver") + } else { + new("MariaDBDriver") + } } #' Client flags diff --git a/R/dbConnect_MariaDBDriver.R b/R/dbConnect_MariaDBDriver.R index c0911889..bcc5ef57 100644 --- a/R/dbConnect_MariaDBDriver.R +++ b/R/dbConnect_MariaDBDriver.R @@ -157,7 +157,13 @@ dbConnect_MariaDBDriver <- function(drv, dbname = NULL, username = NULL, passwor info <- connection_info(ptr) - conn <- new("MariaDBConnection", + if (is(drv, "MySQLDriver")) { + class <- "MySQLConnection" + } else { + class <- "MariaDBConnection" + } + + conn <- new(class, ptr = ptr, host = info$host, db = info$dbname, diff --git a/man/dbConnect-MariaDBDriver-method.Rd b/man/dbConnect-MariaDBDriver-method.Rd index 5271afa7..5a7f779d 100644 --- a/man/dbConnect-MariaDBDriver-method.Rd +++ b/man/dbConnect-MariaDBDriver-method.Rd @@ -6,7 +6,7 @@ \alias{dbConnect,MariaDBDriver-method} \title{Connect/disconnect to a MariaDB DBMS} \usage{ -MariaDB() +MariaDB(mysql = FALSE) \S4method{dbConnect}{MariaDBDriver}( drv, @@ -34,6 +34,11 @@ MariaDB() ) } \arguments{ +\item{mysql}{Set to \code{TRUE} to indicate the intent to connect to a MySQL server. +The \pkg{RMariaDB} package supports both MariaDB and MySQL servers, but the SQL dialect +and other details vary. +The default is to assume a MariaDB server.} + \item{drv}{an object of class \linkS4class{MariaDBDriver} or \linkS4class{MariaDBConnection}.} From dbdd65f1c207740957e9412faf62b23b10ac232c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Fri, 6 Oct 2023 16:32:52 +0200 Subject: [PATCH 2/9] Add mysql argument to mariadb_default() --- R/default.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/default.R b/R/default.R index f848e1fe..913b3bbe 100644 --- a/R/default.R +++ b/R/default.R @@ -41,8 +41,8 @@ mariadbDefault <- function() { }) } -mariadb_default <- function(...) { - rlang::inject(dbConnect(MariaDB(), !!!mariadb_default_args, ...)) +mariadb_default <- function(..., mysql = FALSE) { + rlang::inject(dbConnect(MariaDB(mysql), !!!mariadb_default_args, ...)) } mariadb_default_args <- as.list(c( From 5353eb2151a0aafc8b9313523e9de5f0495a2fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Fri, 6 Oct 2023 16:38:42 +0200 Subject: [PATCH 3/9] Add mysqlDefault() --- R/default.R | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/R/default.R b/R/default.R index 913b3bbe..4aeb589e 100644 --- a/R/default.R +++ b/R/default.R @@ -38,7 +38,19 @@ mariadbDefault <- function() { }, error = function(...) { testthat::skip("Test database not available") - }) + } + ) +} + +mysqlDefault <- function() { + tryCatch( + { + mariadb_default(mysql = TRUE) + }, + error = function(...) { + testthat::skip("Test database not available") + } + ) } mariadb_default <- function(..., mysql = FALSE) { From cc70833cf2072ab27786749e782a4e0f40ecdc64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Fri, 6 Oct 2023 16:39:02 +0200 Subject: [PATCH 4/9] Add test --- tests/testthat/test-dbConnect.R | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/testthat/test-dbConnect.R diff --git a/tests/testthat/test-dbConnect.R b/tests/testthat/test-dbConnect.R new file mode 100644 index 00000000..c747dbef --- /dev/null +++ b/tests/testthat/test-dbConnect.R @@ -0,0 +1,15 @@ +test_that("Connecting with mysql = FALSE", { + con <- mariadbDefault() + on.exit(dbDisconnect(con)) + + expect_s4_class(con, "MariaDBConnection") + expect_false(is(con, "MySQLConnection")) +}) + +test_that("Connecting with mysql = TRUE", { + con <- mysqlDefault() + on.exit(dbDisconnect(con)) + + expect_s4_class(con, "MariaDBConnection") + expect_s4_class(con, "MySQLConnection") +}) From 6acb44a4846eb16c1b45fa2b42e25561366d885d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Fri, 6 Oct 2023 16:45:54 +0200 Subject: [PATCH 5/9] Document --- R/MariaDBConnection.R | 16 ++++++++++++++-- R/MariaDBDriver.R | 11 +++++++++++ man/MariaDBConnection-class.Rd | 17 +++++++++++++++-- man/MariaDBDriver-class.Rd | 12 ++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/R/MariaDBConnection.R b/R/MariaDBConnection.R index ac5efb3b..005ca322 100644 --- a/R/MariaDBConnection.R +++ b/R/MariaDBConnection.R @@ -1,7 +1,18 @@ #' Class MariaDBConnection. #' -#' `MariaDBConnection` objects are usually created by -#' [DBI::dbConnect()] +#' `"MariaDBConnection"` objects are usually created by [DBI::dbConnect()]. +#' They represent a connection to a MariaDB or MySQL database. +#' +#' The `"MySQLConnection"` class is a subclass of `"MariaDBConnection"`. +#' Objects of that class are created by `dbConnect(MariaDB(mysql = TRUE), ...)` to indicate +#' that the server is a MySQL server. +#' The \pkg{RMariaDB} package supports both MariaDB and MySQL servers, but the SQL dialect +#' and other details vary. +#' The default is to assume a MariaDB server. +#' +#' The older \pkg{RMySQL} package also implements the `"MySQLConnection"` class. +#' If both packages are loaded, the class of the connection object is determined by the +#' package that was loaded first. #' #' @export #' @keywords internal @@ -20,6 +31,7 @@ setClass("MariaDBConnection", #' @export #' @keywords internal +#' @rdname MariaDBConnection-class setClass("MySQLConnection", contains = "MariaDBConnection" ) diff --git a/R/MariaDBDriver.R b/R/MariaDBDriver.R index de3005c5..18a229b2 100644 --- a/R/MariaDBDriver.R +++ b/R/MariaDBDriver.R @@ -4,6 +4,16 @@ #' This class should always be initialized with the [MariaDB()] function. #' It returns a singleton that allows you to connect to MariaDB. #' +#' The `"MySQLDriver"` class is a subclass of `"MariaDBDriver"`. +#' It is created by `MariaDB(mysql = TRUE)` to indicate intent to connect to a MySQL server. +#' The \pkg{RMariaDB} package supports both MariaDB and MySQL servers, but the SQL dialect +#' and other details vary. +#' The default is to assume a MariaDB server. +#' +#' The older \pkg{RMySQL} package also implements the `"MySQLDriver"` class. +#' If both packages are loaded, the class of the connection object is determined by the +#' package that was loaded first. +#' #' @export #' @keywords internal setClass("MariaDBDriver", @@ -12,6 +22,7 @@ setClass("MariaDBDriver", #' @export #' @keywords internal +#' @rdname MariaDBDriver-class setClass("MySQLDriver", contains = "MariaDBDriver", ) diff --git a/man/MariaDBConnection-class.Rd b/man/MariaDBConnection-class.Rd index 57d8f274..5a30a939 100644 --- a/man/MariaDBConnection-class.Rd +++ b/man/MariaDBConnection-class.Rd @@ -5,6 +5,7 @@ \docType{class} \name{MariaDBConnection-class} \alias{MariaDBConnection-class} +\alias{MySQLConnection-class} \alias{format.MariaDBConnection} \alias{dbDisconnect_MariaDBConnection} \alias{dbDisconnect,MariaDBConnection-method} @@ -27,7 +28,19 @@ \S4method{show}{MariaDBConnection}(object) } \description{ -\code{MariaDBConnection} objects are usually created by -\code{\link[DBI:dbConnect]{DBI::dbConnect()}} +\code{"MariaDBConnection"} objects are usually created by \code{\link[DBI:dbConnect]{DBI::dbConnect()}}. +They represent a connection to a MariaDB or MySQL database. +} +\details{ +The \code{"MySQLConnection"} class is a subclass of \code{"MariaDBConnection"}. +Objects of that class are created by \code{dbConnect(MariaDB(mysql = TRUE), ...)} to indicate +that the server is a MySQL server. +The \pkg{RMariaDB} package supports both MariaDB and MySQL servers, but the SQL dialect +and other details vary. +The default is to assume a MariaDB server. + +The older \pkg{RMySQL} package also implements the \code{"MySQLConnection"} class. +If both packages are loaded, the class of the connection object is determined by the +package that was loaded first. } \keyword{internal} diff --git a/man/MariaDBDriver-class.Rd b/man/MariaDBDriver-class.Rd index 5b619382..0faf780f 100644 --- a/man/MariaDBDriver-class.Rd +++ b/man/MariaDBDriver-class.Rd @@ -4,6 +4,7 @@ \docType{class} \name{MariaDBDriver-class} \alias{MariaDBDriver-class} +\alias{MySQLDriver-class} \alias{dbGetInfo_MariaDBDriver} \alias{dbGetInfo,MariaDBDriver-method} \alias{dbIsValid_MariaDBDriver} @@ -23,4 +24,15 @@ An MariaDB driver implementing the R database (DBI) API. This class should always be initialized with the \code{\link[=MariaDB]{MariaDB()}} function. It returns a singleton that allows you to connect to MariaDB. } +\details{ +The \code{"MySQLDriver"} class is a subclass of \code{"MariaDBDriver"}. +It is created by \code{MariaDB(mysql = TRUE)} to indicate intent to connect to a MySQL server. +The \pkg{RMariaDB} package supports both MariaDB and MySQL servers, but the SQL dialect +and other details vary. +The default is to assume a MariaDB server. + +The older \pkg{RMySQL} package also implements the \code{"MySQLDriver"} class. +If both packages are loaded, the class of the connection object is determined by the +package that was loaded first. +} \keyword{internal} From 4e7348e41abe6ac1fda36afcf96aa18095b94256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 7 Oct 2023 19:12:53 +0200 Subject: [PATCH 6/9] Autodetect --- NAMESPACE | 1 - R/MariaDBConnection.R | 21 ++++++----- R/MariaDBDriver.R | 17 --------- R/connect.R | 13 ++----- R/dbConnect_MariaDBDriver.R | 50 +++++++++++++++++++++------ R/default.R | 15 ++++++-- man/MariaDBConnection-class.Rd | 8 +++-- man/MariaDBDriver-class.Rd | 12 ------- man/dbConnect-MariaDBDriver-method.Rd | 16 +++++---- src/DbConnection.cpp | 1 + tests/testthat/test-dbConnect.R | 10 +++++- 11 files changed, 91 insertions(+), 73 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 60b793a9..bea1797f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -28,7 +28,6 @@ exportClasses(MariaDBConnection) exportClasses(MariaDBDriver) exportClasses(MariaDBResult) exportClasses(MySQLConnection) -exportClasses(MySQLDriver) exportMethods(dbAppendTable) exportMethods(dbBegin) exportMethods(dbBind) diff --git a/R/MariaDBConnection.R b/R/MariaDBConnection.R index 005ca322..3de152b3 100644 --- a/R/MariaDBConnection.R +++ b/R/MariaDBConnection.R @@ -4,19 +4,18 @@ #' They represent a connection to a MariaDB or MySQL database. #' #' The `"MySQLConnection"` class is a subclass of `"MariaDBConnection"`. -#' Objects of that class are created by `dbConnect(MariaDB(mysql = TRUE), ...)` to indicate -#' that the server is a MySQL server. +#' Objects of that class are created by `dbConnect(MariaDB(), ..., mysql = TRUE)` +#' to indicate that the server is a MySQL server. #' The \pkg{RMariaDB} package supports both MariaDB and MySQL servers, but the SQL dialect #' and other details vary. -#' The default is to assume a MariaDB server. +#' The default is to detect the server type based on the version number. #' #' The older \pkg{RMySQL} package also implements the `"MySQLConnection"` class. #' If both packages are loaded, the class of the connection object is determined by the #' package that was loaded first. #' -#' @export #' @keywords internal -setClass("MariaDBConnection", +MariaDBConnection <- setClass("MariaDBConnection", contains = "DBIConnection", slots = list( ptr = "externalptr", @@ -29,13 +28,19 @@ setClass("MariaDBConnection", ) ) -#' @export +#' @exportClass MariaDBConnection +NULL + #' @keywords internal -#' @rdname MariaDBConnection-class -setClass("MySQLConnection", +#' @name MariaDBConnection-class +#' @aliases MySQLConnection-class +MySQLConnection <- setClass("MySQLConnection", contains = "MariaDBConnection" ) +#' @exportClass MySQLConnection +NULL + # format() #' @export #' @rdname MariaDBConnection-class diff --git a/R/MariaDBDriver.R b/R/MariaDBDriver.R index 18a229b2..cb677d5b 100644 --- a/R/MariaDBDriver.R +++ b/R/MariaDBDriver.R @@ -4,29 +4,12 @@ #' This class should always be initialized with the [MariaDB()] function. #' It returns a singleton that allows you to connect to MariaDB. #' -#' The `"MySQLDriver"` class is a subclass of `"MariaDBDriver"`. -#' It is created by `MariaDB(mysql = TRUE)` to indicate intent to connect to a MySQL server. -#' The \pkg{RMariaDB} package supports both MariaDB and MySQL servers, but the SQL dialect -#' and other details vary. -#' The default is to assume a MariaDB server. -#' -#' The older \pkg{RMySQL} package also implements the `"MySQLDriver"` class. -#' If both packages are loaded, the class of the connection object is determined by the -#' package that was loaded first. -#' #' @export #' @keywords internal setClass("MariaDBDriver", contains = "DBIDriver", ) -#' @export -#' @keywords internal -#' @rdname MariaDBDriver-class -setClass("MySQLDriver", - contains = "MariaDBDriver", -) - #' MariaDB Check for Compiled Versus Loaded Client Library Versions #' #' This function prints out the compiled and loaded client library versions. diff --git a/R/connect.R b/R/connect.R index 2aa379dd..0791e71b 100644 --- a/R/connect.R +++ b/R/connect.R @@ -26,11 +26,6 @@ check_tz <- function(timezone) { } #' @export -#' @param mysql Set to `TRUE` to indicate the intent to connect to a MySQL server. -#' The \pkg{RMariaDB} package supports both MariaDB and MySQL servers, but the SQL dialect -#' and other details vary. -#' The default is to assume a MariaDB server. -#' #' @import methods DBI #' @importFrom hms hms #' @importFrom bit64 integer64 is.integer64 @@ -53,12 +48,8 @@ check_tz <- function(timezone) { #' # clean up #' dbDisconnect(con) #' } -MariaDB <- function(mysql = FALSE) { - if (isTRUE(mysql)) { - new("MySQLDriver") - } else { - new("MariaDBDriver") - } +MariaDB <- function() { + new("MariaDBDriver") } #' Client flags diff --git a/R/dbConnect_MariaDBDriver.R b/R/dbConnect_MariaDBDriver.R index bcc5ef57..dfa2ac44 100644 --- a/R/dbConnect_MariaDBDriver.R +++ b/R/dbConnect_MariaDBDriver.R @@ -80,6 +80,12 @@ #' @param reconnect (experimental) Set to `TRUE` to use `MYSQL_OPT_RECONNECT` to enable #' automatic reconnection. This is experimental and could be dangerous if the connection #' is lost in the middle of a transaction. +#' @param mysql Set to `TRUE`/`FALSE` to connect to a MySQL server or to a MariaDB server, +#' respectively. +#' The \pkg{RMariaDB} package supports both MariaDB and MySQL servers, but the SQL dialect +#' and other details vary. +#' The default is to assume MariaDB if the version is >= 10.0.0, and MySQL otherwise. +#' #' @references #' Configuration files: https://mariadb.com/kb/en/library/configuring-mariadb-with-mycnf/ #' @examples @@ -108,13 +114,31 @@ #' } #' @usage NULL #' @rdname dbConnect-MariaDBDriver-method -dbConnect_MariaDBDriver <- function(drv, dbname = NULL, username = NULL, password = NULL, host = NULL, - unix.socket = NULL, port = 0, client.flag = 0, - groups = "rs-dbi", default.file = NULL, ssl.key = NULL, ssl.cert = NULL, - ssl.ca = NULL, ssl.capath = NULL, ssl.cipher = NULL, ..., - load_data_local_infile = FALSE, - bigint = c("integer64", "integer", "numeric", "character"), - timeout = 10, timezone = "+00:00", timezone_out = NULL, reconnect = FALSE) { +dbConnect_MariaDBDriver <- function( + drv, + dbname = NULL, + username = NULL, + password = NULL, + host = NULL, + unix.socket = NULL, + port = 0, + client.flag = 0, + groups = "rs-dbi", + default.file = NULL, + ssl.key = NULL, + ssl.cert = NULL, + ssl.ca = NULL, + ssl.capath = NULL, + ssl.cipher = NULL, + ..., + load_data_local_infile = FALSE, + bigint = c("integer64", "integer", "numeric", "character"), + timeout = 10, + timezone = "+00:00", + timezone_out = NULL, + reconnect = FALSE, + mysql = NULL) { + # bigint <- match.arg(bigint) if (is.infinite(timeout)) { @@ -157,13 +181,17 @@ dbConnect_MariaDBDriver <- function(drv, dbname = NULL, username = NULL, passwor info <- connection_info(ptr) - if (is(drv, "MySQLDriver")) { - class <- "MySQLConnection" + if (is.null(mysql)) { + mysql <- (info$db.version.int < 100000) + } + + if (isTRUE(mysql)) { + new <- MySQLConnection } else { - class <- "MariaDBConnection" + new <- MariaDBConnection } - conn <- new(class, + conn <- new( ptr = ptr, host = info$host, db = info$dbname, diff --git a/R/default.R b/R/default.R index 4aeb589e..fb9577fa 100644 --- a/R/default.R +++ b/R/default.R @@ -53,8 +53,19 @@ mysqlDefault <- function() { ) } -mariadb_default <- function(..., mysql = FALSE) { - rlang::inject(dbConnect(MariaDB(mysql), !!!mariadb_default_args, ...)) +mariadbForceDefault <- function() { + tryCatch( + { + mariadb_default(mysql = FALSE) + }, + error = function(...) { + testthat::skip("Test database not available") + } + ) +} + +mariadb_default <- function(...) { + rlang::inject(dbConnect(MariaDB(), !!!mariadb_default_args, ...)) } mariadb_default_args <- as.list(c( diff --git a/man/MariaDBConnection-class.Rd b/man/MariaDBConnection-class.Rd index 5a30a939..3fcbbb27 100644 --- a/man/MariaDBConnection-class.Rd +++ b/man/MariaDBConnection-class.Rd @@ -5,6 +5,8 @@ \docType{class} \name{MariaDBConnection-class} \alias{MariaDBConnection-class} +\alias{MariaDBConnection} +\alias{MySQLConnection} \alias{MySQLConnection-class} \alias{format.MariaDBConnection} \alias{dbDisconnect_MariaDBConnection} @@ -33,11 +35,11 @@ They represent a connection to a MariaDB or MySQL database. } \details{ The \code{"MySQLConnection"} class is a subclass of \code{"MariaDBConnection"}. -Objects of that class are created by \code{dbConnect(MariaDB(mysql = TRUE), ...)} to indicate -that the server is a MySQL server. +Objects of that class are created by \code{dbConnect(MariaDB(), ..., mysql = TRUE)} +to indicate that the server is a MySQL server. The \pkg{RMariaDB} package supports both MariaDB and MySQL servers, but the SQL dialect and other details vary. -The default is to assume a MariaDB server. +The default is to detect the server type based on the version number. The older \pkg{RMySQL} package also implements the \code{"MySQLConnection"} class. If both packages are loaded, the class of the connection object is determined by the diff --git a/man/MariaDBDriver-class.Rd b/man/MariaDBDriver-class.Rd index 0faf780f..5b619382 100644 --- a/man/MariaDBDriver-class.Rd +++ b/man/MariaDBDriver-class.Rd @@ -4,7 +4,6 @@ \docType{class} \name{MariaDBDriver-class} \alias{MariaDBDriver-class} -\alias{MySQLDriver-class} \alias{dbGetInfo_MariaDBDriver} \alias{dbGetInfo,MariaDBDriver-method} \alias{dbIsValid_MariaDBDriver} @@ -24,15 +23,4 @@ An MariaDB driver implementing the R database (DBI) API. This class should always be initialized with the \code{\link[=MariaDB]{MariaDB()}} function. It returns a singleton that allows you to connect to MariaDB. } -\details{ -The \code{"MySQLDriver"} class is a subclass of \code{"MariaDBDriver"}. -It is created by \code{MariaDB(mysql = TRUE)} to indicate intent to connect to a MySQL server. -The \pkg{RMariaDB} package supports both MariaDB and MySQL servers, but the SQL dialect -and other details vary. -The default is to assume a MariaDB server. - -The older \pkg{RMySQL} package also implements the \code{"MySQLDriver"} class. -If both packages are loaded, the class of the connection object is determined by the -package that was loaded first. -} \keyword{internal} diff --git a/man/dbConnect-MariaDBDriver-method.Rd b/man/dbConnect-MariaDBDriver-method.Rd index 5a7f779d..cdf7cdbf 100644 --- a/man/dbConnect-MariaDBDriver-method.Rd +++ b/man/dbConnect-MariaDBDriver-method.Rd @@ -6,7 +6,7 @@ \alias{dbConnect,MariaDBDriver-method} \title{Connect/disconnect to a MariaDB DBMS} \usage{ -MariaDB(mysql = FALSE) +MariaDB() \S4method{dbConnect}{MariaDBDriver}( drv, @@ -30,15 +30,11 @@ MariaDB(mysql = FALSE) timeout = 10, timezone = "+00:00", timezone_out = NULL, - reconnect = FALSE + reconnect = FALSE, + mysql = NULL ) } \arguments{ -\item{mysql}{Set to \code{TRUE} to indicate the intent to connect to a MySQL server. -The \pkg{RMariaDB} package supports both MariaDB and MySQL servers, but the SQL dialect -and other details vary. -The default is to assume a MariaDB server.} - \item{drv}{an object of class \linkS4class{MariaDBDriver} or \linkS4class{MariaDBConnection}.} @@ -114,6 +110,12 @@ This setting does not change the time values returned, only their display.} \item{reconnect}{(experimental) Set to \code{TRUE} to use \code{MYSQL_OPT_RECONNECT} to enable automatic reconnection. This is experimental and could be dangerous if the connection is lost in the middle of a transaction.} + +\item{mysql}{Set to \code{TRUE}/\code{FALSE} to connect to a MySQL server or to a MariaDB server, +respectively. +The \pkg{RMariaDB} package supports both MariaDB and MySQL servers, but the SQL dialect +and other details vary. +The default is to assume MariaDB if the version is >= 10.0.0, and MySQL otherwise.} } \description{ These methods are straight-forward implementations of the corresponding diff --git a/src/DbConnection.cpp b/src/DbConnection.cpp index cc738a7d..74602e6d 100644 --- a/src/DbConnection.cpp +++ b/src/DbConnection.cpp @@ -115,6 +115,7 @@ cpp11::list DbConnection::info() { "dbname"_nm = std::string(pConn_->db ? pConn_->db : ""), "con.type"_nm = std::string(mysql_get_host_info(pConn_)), "db.version"_nm = std::string(mysql_get_server_info(pConn_)), + "db.version.int"_nm = (int) mysql_get_server_version(pConn_), "port"_nm = NA_INTEGER, "protocol.version"_nm = (int) mysql_get_proto_info(pConn_), "thread.id"_nm = (int) mysql_thread_id(pConn_) diff --git a/tests/testthat/test-dbConnect.R b/tests/testthat/test-dbConnect.R index c747dbef..fa92642b 100644 --- a/tests/testthat/test-dbConnect.R +++ b/tests/testthat/test-dbConnect.R @@ -1,5 +1,5 @@ test_that("Connecting with mysql = FALSE", { - con <- mariadbDefault() + con <- mariadbForceDefault() on.exit(dbDisconnect(con)) expect_s4_class(con, "MariaDBConnection") @@ -13,3 +13,11 @@ test_that("Connecting with mysql = TRUE", { expect_s4_class(con, "MariaDBConnection") expect_s4_class(con, "MySQLConnection") }) + +test_that("Connecting with mysql unset", { + con <- mariadbDefault() + on.exit(dbDisconnect(con)) + + expect_s4_class(con, "MariaDBConnection") +}) + From 47900b99769e027eb5504a6ba8602e8211d26bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 7 Oct 2023 19:36:33 +0200 Subject: [PATCH 7/9] Unrelated: Docker creds --- R/default.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/default.R b/R/default.R index fb9577fa..1cbc9760 100644 --- a/R/default.R +++ b/R/default.R @@ -70,5 +70,8 @@ mariadb_default <- function(...) { mariadb_default_args <- as.list(c( dbname = "test", + # host = "192.168.64.2", + # user = "compose", + # password = "YourStrong!Passw0rd", NULL )) From cb4cbcb09386af688bc954d78ced10631fb94316 Mon Sep 17 00:00:00 2001 From: krlmlr Date: Sat, 7 Oct 2023 18:02:09 +0000 Subject: [PATCH 8/9] Auto-update from GitHub Actions Run: https://github.com/r-dbi/RMariaDB/actions/runs/6442664608 --- tests/testthat/test-dbConnect.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-dbConnect.R b/tests/testthat/test-dbConnect.R index fa92642b..f0dde1f3 100644 --- a/tests/testthat/test-dbConnect.R +++ b/tests/testthat/test-dbConnect.R @@ -20,4 +20,3 @@ test_that("Connecting with mysql unset", { expect_s4_class(con, "MariaDBConnection") }) - From 8da6abf2aa6c5b8b59d8e80a14ffc9e5b7877139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 7 Oct 2023 20:13:13 +0200 Subject: [PATCH 9/9] Tweak docs --- R/MariaDBConnection.R | 4 ++-- man/MariaDBConnection-class.Rd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/MariaDBConnection.R b/R/MariaDBConnection.R index 3de152b3..b531764c 100644 --- a/R/MariaDBConnection.R +++ b/R/MariaDBConnection.R @@ -11,8 +11,8 @@ #' The default is to detect the server type based on the version number. #' #' The older \pkg{RMySQL} package also implements the `"MySQLConnection"` class. -#' If both packages are loaded, the class of the connection object is determined by the -#' package that was loaded first. +#' The S4 system is able to distinguish between \pkg{RMariaDB} and \pkg{RMySQL} objects +#' even if both packages are loaded. #' #' @keywords internal MariaDBConnection <- setClass("MariaDBConnection", diff --git a/man/MariaDBConnection-class.Rd b/man/MariaDBConnection-class.Rd index 3fcbbb27..866109d4 100644 --- a/man/MariaDBConnection-class.Rd +++ b/man/MariaDBConnection-class.Rd @@ -42,7 +42,7 @@ and other details vary. The default is to detect the server type based on the version number. The older \pkg{RMySQL} package also implements the \code{"MySQLConnection"} class. -If both packages are loaded, the class of the connection object is determined by the -package that was loaded first. +The S4 system is able to distinguish between \pkg{RMariaDB} and \pkg{RMySQL} objects +even if both packages are loaded. } \keyword{internal}