Skip to content

Commit

Permalink
Support schemas via Id objects in DBI 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jimhester committed Mar 20, 2018
1 parent dcdc665 commit 536ee60
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 64 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ URL: https://github.com/r-dbi/odbc
BugReports: https://github.com/r-dbi/odbc/issues
SystemRequirements: C++11, GNU make, An ODBC3 driver manager and drivers.
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.0.1.9000
RoxygenNote: 6.0.1
LazyData: true
ByteCompile: true
Depends: R (>= 3.2.0)
Imports:
DBI (>= 0.3.0),
DBI (>= 0.8.0),
methods,
Rcpp (>= 0.12.11),
blob (>= 1.1.0),
Expand All @@ -45,3 +45,5 @@ Collate:
'hidden.R'
'utils.R'
'zzz.R'
Remotes:
r-dbi/DBI#233
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ S3method(odbcDataType,default)
S3method(odbcListObjectTypes,default)
S3method(odbcListObjects,OdbcConnection)
S3method(odbcPreviewObject,OdbcConnection)
export(dbUnQuoteIdentifier)
export(odbc)
export(odbcConnectionActions)
export(odbcConnectionIcon)
Expand Down Expand Up @@ -56,7 +55,6 @@ exportMethods(dbRemoveTable)
exportMethods(dbRollback)
exportMethods(dbSendQuery)
exportMethods(dbSendStatement)
exportMethods(dbUnQuoteIdentifier)
exportMethods(dbWriteTable)
exportMethods(show)
exportMethods(sqlCreateTable)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# odbc 1.1.5.9000

* Full schema support using Id objects available in DBI 8.0 (#91, #120)

# odbc 1.1.5

* Fix the return value for `dbQuoteIdentifier()` when given a length 0 input
Expand Down
34 changes: 3 additions & 31 deletions R/Connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,40 +176,12 @@ setMethod(
DBI::SQL(paste(conn@quote, encodeString(x), conn@quote, sep = ""))
})


#' Un-Quote identifiers
#'
#' Call this method to generate a string that is unquoted. This is the inverse
#' of `DBI::dbQuoteIdentifier`.
#'
#' @param x A character vector to un-quote.
#' @inheritParams DBI::dbQuoteIdentifier
#' @export
setGeneric(
"dbUnQuoteIdentifier",
function(conn, x, ...) standardGeneric("dbUnQuoteIdentifier")
)

#' @rdname dbUnQuoteIdentifier
#' @inheritParams DBI::dbQuoteIdentifier
#' @export
setMethod(
"dbUnQuoteIdentifier", c("OdbcConnection", "SQL"),
function(conn, x) {
x <- as.character(x)
x <- gsub(paste0("^", conn@quote), "", x)
x <- gsub(paste0(conn@quote, "$"), "", x)
x
})

#' @rdname dbUnQuoteIdentifier
#' @rdname OdbcConnection
#' @inheritParams DBI::dbQuoteIdentifier
#' @export
setMethod(
"dbUnQuoteIdentifier", c("OdbcConnection", "character"),
function(conn, x) {
x
})
"dbQuoteIdentifier", c("OdbcConnection", "SQL"),
getMethod("dbQuoteIdentifier", c("DBIConnection", "SQL"), asNamespace("DBI")))

#' @rdname OdbcConnection
#' @inheritParams DBI::dbListTables
Expand Down
22 changes: 22 additions & 0 deletions R/Table.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,25 @@ createFields <- function(con, fields, field.types, row.names) {
field_types <- unname(fields)
paste0(field_names, " ", field_types)
}

#' @rdname OdbcConnection
#' @inheritParams DBI::dbExistsTable
#' @export
setMethod(
"dbExistsTable", c("OdbcConnection", "Id"),
function(conn, name, ...) {
name@name[["table"]] %in% connection_sql_tables(conn@ptr,
catalog_name = if ("catalog" %in% names(name@name)) name@name[["catalog"]] else "%",
schema_name = if ("schema" %in% names(name@name)) name@name[["schema"]] else "%",
table_name = if ("table" %in% names(name@name)) name@name[["table"]] else "%"
)
})

#' @rdname OdbcConnection
#' @inheritParams DBI::dbExistsTable
#' @export
setMethod(
"dbExistsTable", c("OdbcConnection", "SQL"),
function(conn, name, ...) {
dbExistsTable(conn, dbUnquoteIdentifier(conn, name)[[1]], ...)
})
13 changes: 11 additions & 2 deletions man/OdbcConnection.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 0 additions & 27 deletions man/dbUnQuoteIdentifier.Rd

This file was deleted.

0 comments on commit 536ee60

Please sign in to comment.