R/dbUnquoteIdentifier_MariaDBConnection_SQL.R

Defines functions dbUnquoteIdentifier_MariaDBConnection_SQL

Documented in dbUnquoteIdentifier_MariaDBConnection_SQL

#' @rdname mariadb-quoting
#' @usage NULL
dbUnquoteIdentifier_MariaDBConnection_SQL <- function(conn, x, ...) {
  id_rx <- "(?:`((?:[^`]|``)+)`|([^`. ]+))"

  rx <- paste0(
    "^",
    "(?:|", id_rx, "[.])",
    "(?:|", id_rx, ")",
    "$"
  )

  bad <- grep(rx, x, invert = TRUE)
  if (length(bad) > 0) {
    stop("Can't unquote ", x[bad[[1]]], call. = FALSE)
  }
  schema <- gsub(rx, "\\1\\2", x)
  schema <- gsub("``", "`", schema)
  table <- gsub(rx, "\\3\\4", x)
  table <- gsub("``", "`", table)

  ret <- Map(schema, table, f = as_table)
  names(ret) <- names(x)
  ret
}

#' @rdname mariadb-quoting
#' @export
setMethod("dbUnquoteIdentifier", c("MariaDBConnection", "SQL"), dbUnquoteIdentifier_MariaDBConnection_SQL)

Try the RMariaDB package in your browser

Any scripts or data that you put into this service are public.

RMariaDB documentation built on Dec. 20, 2021, 9:06 a.m.