Skip to content

Commit

Permalink
Merge branch 'r-0.7-15' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Feb 10, 2018
2 parents 77e100d + 11ead33 commit 24156e8
Show file tree
Hide file tree
Showing 128 changed files with 18,449 additions and 192 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ inst\/doc\/DBI\.b..$
^_pkgdown\.yml$
^revdep/
^API$
^docs$
48 changes: 22 additions & 26 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
# Default configuration for use with tic package
# Usually you shouldn't need to change the first part of the file

# DO NOT CHANGE THE CODE BELOW
before_install: R -q -e 'install.packages(c("remotes", "curl")); remotes::install_github("ropenscilabs/tic"); tic::prepare_all_stages(); tic::before_install()'
install: R -q -e 'tic::install()'
after_install: R -q -e 'tic::after_install()'
before_script: R -q -e 'tic::before_script()'
script: R -q -e 'tic::script()'
after_success: R -q -e 'tic::after_success()'
after_failure: R -q -e 'tic::after_failure()'
before_deploy: R -q -e 'tic::before_deploy()'
deploy:
provider: script
script: R -q -e 'tic::deploy()'
on:
all_branches: true
after_deploy: R -q -e 'tic::after_deploy()'
after_script: R -q -e 'tic::after_script()'
# DO NOT CHANGE THE CODE ABOVE

# Custom parts:

# Header
language: r
sudo: false
cache: packages
latex: false
warnings_are_errors: true

#env
env:
Expand Down Expand Up @@ -35,32 +56,7 @@ notifications:
on_success: change
on_failure: change

#before_script
before_script:
- R -q -e 'devtools::install_github("ropenscilabs/tic"); tic::prepare_all_stages()'

#after_success
after_success:
- R -q -e 'tic::after_success()'

#deploy // https://github.com/travis-ci/travis-build/blob/85ef7108/lib/travis/build/addons/deploy/script.rb#L100-L107
deploy:
provider: script
script: R -q -e 'tic::deploy()'
on:
all_branches: true

# Custom parts:

#r_github_packages
r_github_packages:
- krlmlr/roxygen@b-%23521-subsection

#r_packages
r_packages:

#services
services:

#before_install
before_install:
9 changes: 9 additions & 0 deletions API
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Exported functions

ANSI()
Id(...)
SQL(x, ..., names = NULL)
SQLKeywords(dbObj, ...)
dbBegin(conn, ...)
Expand Down Expand Up @@ -30,6 +31,7 @@ dbHasCompleted(res, ...)
dbIsValid(dbObj, ...)
dbListConnections(drv, ...)
dbListFields(conn, name, ...)
dbListObjects(conn, prefix = NULL, ...)
dbListResults(conn, ...)
dbListTables(conn, ...)
dbQuoteIdentifier(conn, x, ...)
Expand All @@ -42,6 +44,7 @@ dbSendQuery(conn, statement, ...)
dbSendStatement(conn, statement, ...)
dbSetDataMappings(res, flds, ...)
dbUnloadDriver(drv, ...)
dbUnquoteIdentifier(conn, x, ...)
dbWithTransaction(conn, code, ...)
dbWriteTable(conn, name, value, ...)
fetch(res, n = -1, ...)
Expand All @@ -61,6 +64,12 @@ sqlParseVariablesImpl(sql, quotes, comments)
sqlQuoteSpec(start, end, escape, doubleEscape = TRUE)
sqlRownamesToColumn(df, row.names = NA)

## Foreign S3 methods

[.SQL(x, ...)
[[.SQL(x, ...)
toString.Id(x, ...)

## Exported data

.SQL92Keywords: character (character[220])
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: DBI
Version: 0.7-14
Date: 2018-01-27
Version: 0.7-15
Date: 2018-02-10
Title: R Database Interface
Description: A database interface definition for communication
between R and relational database management systems. All
Expand Down Expand Up @@ -33,6 +33,7 @@ BugReports: https://github.com/r-dbi/DBI/issues
Collate:
'DBObject.R'
'DBDriver.R'
'table.R'
'DBConnection.R'
'ANSI.R'
'DBI-package.R'
Expand All @@ -47,8 +48,7 @@ Collate:
'rownames.R'
'table-create.R'
'table-insert.R'
'table.R'
'transactions.R'
VignetteBuilder: knitr
Roxygen: list(markdown = TRUE, roclets = c("collate", "namespace", "rd", "pkgapi::api_roclet"))
RoxygenNote: 6.0.1
RoxygenNote: 6.0.1.9000
11 changes: 11 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Generated by roxygen2: do not edit by hand

S3method("[",SQL)
S3method("[[",SQL)
S3method(toString,Id)
export(.SQL92Keywords)
export(ANSI)
export(Id)
export(SQL)
export(SQLKeywords)
export(dbBegin)
Expand Down Expand Up @@ -29,6 +33,7 @@ export(dbHasCompleted)
export(dbIsValid)
export(dbListConnections)
export(dbListFields)
export(dbListObjects)
export(dbListResults)
export(dbListTables)
export(dbQuoteIdentifier)
Expand All @@ -41,6 +46,7 @@ export(dbSendQuery)
export(dbSendStatement)
export(dbSetDataMappings)
export(dbUnloadDriver)
export(dbUnquoteIdentifier)
export(dbWithTransaction)
export(dbWriteTable)
export(fetch)
Expand All @@ -66,15 +72,20 @@ exportClasses(DBIResult)
exportClasses(SQL)
exportMethods(dbDataType)
exportMethods(dbExecute)
exportMethods(dbExistsTable)
exportMethods(dbFetch)
exportMethods(dbGetQuery)
exportMethods(dbListFields)
exportMethods(dbListObjects)
exportMethods(dbQuoteIdentifier)
exportMethods(dbQuoteLiteral)
exportMethods(dbQuoteString)
exportMethods(dbReadTable)
exportMethods(dbRemoveTable)
exportMethods(dbSendStatement)
exportMethods(dbUnquoteIdentifier)
exportMethods(dbWithTransaction)
exportMethods(dbWriteTable)
exportMethods(show)
exportMethods(sqlAppendTable)
exportMethods(sqlCreateTable)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## DBI 0.7-15 (2018-02-10)

- Schema support: Export `Id()`, new generics `dbListObjects()` and `dbUnquoteIdentifier()`, methods for `Id` that call `dbQuoteIdentifier()` and then forward (#220).
- `dbListConnections()` is soft-deprecated by documentation.
- Default implementations of `dbQuoteIdentifier()` and `dbQuoteLiteral()` preserve names, default implementation of `dbQuoteString()` strips names (#173).
- Breaking change: If the `names` argument is unset, `SQL()` strips the names from the output.


## DBI 0.7-14 (2018-01-27)

- The `SQL()` function gains a `names` argument which can be used to assign names to SQL strings.
Expand Down
92 changes: 90 additions & 2 deletions R/DBConnection.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#' @include table.R
NULL

#' DBIConnection class
#'
#' This virtual class encapsulates the connection to a DBMS, and it provides
Expand Down Expand Up @@ -338,7 +341,8 @@ setMethod("dbListFields", signature("DBIConnection", "character"),
#'
#' Returns the unquoted names of remote tables accessible through this
#' connection.
#' This should, where possible, include temporary tables, and views.
#' This should include views and temporary objects, but not all database backends
#' (in particular \pkg{RMariaDB} and \pkg{RMySQL}) support this.
#'
#' @template methods
#' @templateVar method_name dbListTables
Expand All @@ -362,6 +366,58 @@ setGeneric("dbListTables",
valueClass = "character"
)

#' List remote objects
#'
#' Returns the names of remote objects accessible through this connection
#' as a data frame.
#' This should include temporary objects, but not all database backends
#' (in particular \pkg{RMariaDB} and \pkg{RMySQL}) support this.
#' Compared to [dbListTables()], this method also enumerates tables and views
#' in schemas, and returns fully qualified identifiers to access these objects.
#' This allows exploration of all database objects available to the current
#' user, including those that can only be accessed by giving the full
#' namespace.
#'
#' @template methods
#' @templateVar method_name dbListObjects
#'
#' @inherit DBItest::spec_sql_list_objects return
#' @inheritSection DBItest::spec_sql_list_objects Additional arguments
#'
#' @inheritParams dbGetQuery
#' @param prefix A fully qualified path in the database's namespace, or `NULL`.
#' will be passed to [dbUnquoteIdentifier()].
#' If given the method will return all objects accessible through this prefix.
#' @family DBIConnection generics
#' @export
#' @examples
#' con <- dbConnect(RSQLite::SQLite(), ":memory:")
#'
#' dbListObjects(con)
#' dbWriteTable(con, "mtcars", mtcars)
#' dbListObjects(con)
#'
#' dbDisconnect(con)
setGeneric("dbListObjects",
def = function(conn, prefix = NULL, ...) standardGeneric("dbListObjects"),
valueClass = "data.frame"
)

#' @rdname hidden_aliases
#' @export
setMethod("dbListObjects", signature("DBIConnection", "ANY"),
function(conn, prefix = NULL, ...) {
names <- dbListTables(conn)
tables <- lapply(names, function(x) Id(table = x))
ret <- data.frame(
table = I(unname(tables)),
stringsAsFactors = FALSE
)
ret$is_prefix <- rep_len(FALSE, nrow(ret))
ret
}
)

#' Copy data frames from database tables
#'
#' Reads a database table to a data frame, optionally converting
Expand Down Expand Up @@ -394,7 +450,7 @@ setGeneric("dbReadTable",

#' @rdname hidden_aliases
#' @export
setMethod("dbReadTable", c("DBIConnection", "character"),
setMethod("dbReadTable", signature("DBIConnection", "character"),
function(conn, name, ..., row.names = FALSE, check.names = TRUE) {
sql_name <- dbQuoteIdentifier(conn, x = name, ...)
if (length(sql_name) != 1L) {
Expand All @@ -417,6 +473,14 @@ setMethod("dbReadTable", c("DBIConnection", "character"),
}
)

#' @rdname hidden_aliases
#' @export
setMethod("dbReadTable", signature("DBIConnection", "Id"),
function(conn, name, ...) {
dbReadTable(conn, dbQuoteIdentifier(conn, name), ...)
}
)

#' Copy data frames to database tables
#'
#' Writes, overwrites or appends a data frame to a database table, optionally
Expand Down Expand Up @@ -455,6 +519,14 @@ setGeneric("dbWriteTable",
def = function(conn, name, value, ...) standardGeneric("dbWriteTable")
)

#' @rdname hidden_aliases
#' @export
setMethod("dbWriteTable", signature("DBIConnection", "Id"),
function(conn, name, ...) {
dbWriteTable(conn, dbQuoteIdentifier(conn, name), ...)
}
)

#' Does a table exist?
#'
#' Returns if a table given by name exists in the database.
Expand Down Expand Up @@ -483,6 +555,14 @@ setGeneric("dbExistsTable",
valueClass = "logical"
)

#' @rdname hidden_aliases
#' @export
setMethod("dbExistsTable", signature("DBIConnection", "Id"),
function(conn, name, ...) {
dbExistsTable(conn, dbQuoteIdentifier(conn, name), ...)
}
)

#' Remove a table from the database
#'
#' Remove a remote table (e.g., created by [dbWriteTable()])
Expand Down Expand Up @@ -511,3 +591,11 @@ setGeneric("dbExistsTable",
setGeneric("dbRemoveTable",
def = function(conn, name, ...) standardGeneric("dbRemoveTable")
)

#' @rdname hidden_aliases
#' @export
setMethod("dbRemoveTable", signature("DBIConnection", "Id"),
function(conn, name, ...) {
dbRemoveTable(conn, dbQuoteIdentifier(conn, name), ...)
}
)
9 changes: 4 additions & 5 deletions R/DBDriver.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ setMethod("dbDriver", signature("character"),
#' @rdname hidden_aliases
#' @param object Object to display
#' @export
setMethod("show", "DBIDriver", function(object) {
setMethod("show", signature("DBIDriver"), function(object) {
tryCatch(
# to protect drivers that fail to implement the required methods (e.g.,
# RPostgreSQL)
Expand Down Expand Up @@ -170,9 +170,8 @@ setGeneric("dbConnect",

#' List currently open connections
#'
#' Drivers that implement only a single connections MUST return a list
#' containing a single element. If no connection are open, methods MUST
#' return an empty list.
#' DEPRECATED, drivers are no longer required to implement this method.
#' Keep track of the connections you opened if you require a list.
#'
#' @param drv A object inheriting from [DBIDriver-class]
#' @param ... Other arguments passed on to methods.
Expand Down Expand Up @@ -252,6 +251,6 @@ setGeneric("dbDataType",

#' @rdname hidden_aliases
#' @export
setMethod("dbDataType", "DBIObject", function(dbObj, obj, ...) {
setMethod("dbDataType", signature("DBIObject"), function(dbObj, obj, ...) {
dbiDataType(obj)
})
6 changes: 3 additions & 3 deletions R/DBResult.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ setClass("DBIResult", contains = c("DBIObject", "VIRTUAL"))
#' @rdname hidden_aliases
#' @param object Object to display
#' @export
setMethod("show", "DBIResult", function(object) {
setMethod("show", signature("DBIResult"), function(object) {
# to protect drivers that fail to implement the required methods (e.g.,
# RPostgreSQL)
tryCatch(
Expand Down Expand Up @@ -101,7 +101,7 @@ setGeneric("dbFetch",

#' @rdname hidden_aliases
#' @export
setMethod("dbFetch", "DBIResult", function(res, n = -1, ...) {
setMethod("dbFetch", signature("DBIResult"), function(res, n = -1, ...) {
fetch(res, n = n, ...)
})

Expand Down Expand Up @@ -303,7 +303,7 @@ setGeneric("dbGetRowCount",
#' [dbGetRowsAffected()], and [dbHasCompleted()].
NULL
#' @rdname hidden_aliases
setMethod("dbGetInfo", "DBIResult", function(dbObj, ...) {
setMethod("dbGetInfo", signature("DBIResult"), function(dbObj, ...) {
list(
statement = dbGetStatement(dbObj),
row.count = dbGetRowCount(dbObj),
Expand Down
Loading

0 comments on commit 24156e8

Please sign in to comment.