Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dbDataType() for AsIs object #198

Merged
merged 2 commits into from
Nov 27, 2017

Conversation

yutannihilation
Copy link
Contributor

Current implementation of dbiDataType() for AsIs fails to restore the original class attributes. (I found this when I was trying to cheat DBItest with ANSI()...)

library(DBI)
library(DBItest)

dbObj <- structure(list(), class = "DBIDriver")
testthat::expect_equal(
  dbDataType(dbObj, I(structure(17455, class = "Date"))),
  dbDataType(dbObj, structure(17455, class = "Date"))
)
#> Error: dbDataType(dbObj, I(structure(17455, class = "Date"))) not equal to dbDataType(dbObj, structure(17455, class = "Date")).
#> 1/1 mismatches
#> x[1]: "DOUBLE"
#> y[1]: "DATE"

unclass() is OK for implicit classes (e.g. numeric and integer), but Date needs to be set as class attribute explicitly. I believe oldClass(x) <- oldClass(x)[-1] is the reverse of what I() does.

body(selectMethod("dbiDataType", "AsIs"))
#> {
#>     .local <- function (x) 
#>     {
#>         dbiDataType(unclass(x))
#>     }
#>     .local(x, ...)
#> }

body(I)
#> {
#>     structure(x, class = unique(c("AsIs", oldClass(x))))
#> }

@codecov-io
Copy link

codecov-io commented Oct 16, 2017

Codecov Report

Merging #198 into master will increase coverage by 0.54%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #198      +/-   ##
==========================================
+ Coverage   42.97%   43.52%   +0.54%     
==========================================
  Files          16       16              
  Lines         470      471       +1     
==========================================
+ Hits          202      205       +3     
+ Misses        268      266       -2
Impacted Files Coverage Δ
R/data-types.R 41.17% <100%> (+16.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f8c97f2...c47c98a. Read the comment docs.

@yutannihilation
Copy link
Contributor Author

I expected the first commit should fail, but maybe I pushed the second commit too early...

https://travis-ci.org/rstats-db/DBI/jobs/288387072

@krlmlr krlmlr merged commit 74261d3 into r-dbi:master Nov 27, 2017
@krlmlr
Copy link
Member

krlmlr commented Nov 27, 2017

Thanks!

@yutannihilation yutannihilation deleted the fix-dbiDataType-AsIs branch November 27, 2017 08:40
krlmlr added a commit that referenced this pull request Nov 27, 2017
- The deprecated `print.list.pairs()` has been removed.
- Fix `dbDataType()` for `AsIs` object (#198, @yutannihilation).
- Point to db.rstudio.com (@wibeasley, #209).
- Reflect new 'r-dbi' organization in `DESCRIPTION` (@wibeasley, #207).
- Using switchpatch on the second argument for default implementations of `dbQuoteString()` and `dbQuoteIdentifier()`.
- New `dbQuoteLiteral()` generic. The default implementation uses switchpatch to avoid dispatch ambiguities, and forwards to `dbQuoteString()` for character vectors. Backends may override methods that also dispatch on the second argument, but in this case also an override for the `"SQL"` class is necessary (#172).
- Fix `dbQuoteString()` and `dbQuoteIdentifier()` to ignore invalid UTF-8 strings (r-dbi/DBItest#156).
krlmlr added a commit that referenced this pull request Mar 9, 2018
…ps the names from the output if the `names` argument is unset. - The `dbReadTable()`, `dbWriteTable()`, `dbExistsTable()`, `dbRemoveTable()`, and `dbListFields()` generics now specialize over the first two arguments to support implementations with the `Id` S4 class as type for the second argument. Some packages may need to update their documentation to satisfy R CMD check again. New generics ------------ - Schema support: Export `Id()`, new generics `dbListObjects()` and `dbUnquoteIdentifier()`, methods for `Id` that call `dbQuoteIdentifier()` and then forward (#220). - New `dbQuoteLiteral()` generic. The default implementation uses switchpatch to avoid dispatch ambiguities, and forwards to `dbQuoteString()` for character vectors. Backends may override methods that also dispatch on the second argument, but in this case also an override for the `"SQL"` class is necessary (#172). Default implementations ----------------------- - Default implementations of `dbQuoteIdentifier()` and `dbQuoteLiteral()` preserve names, default implementation of `dbQuoteString()` strips names (#173). - Specialized methods for `dbQuoteString()` and `dbQuoteIdentifier()` are available again, for compatibility with clients that use `getMethod()` to access them (#218). - Add default implementation of `dbListFields()`. - The default implementation of `dbReadTable()` now has `row.names = FALSE` as default and also supports `row.names = NULL` (#186). API changes ----------- - The `SQL()` function gains an optional `names` argument which can be used to assign names to SQL strings. Deprecated generics ------------------- - `dbListConnections()` is soft-deprecated by documentation. - `dbListResults()` is deprecated by documentation (#58). - `dbGetException()` is soft-deprecated by documentation (#51). - The deprecated `print.list.pairs()` has been removed. Bug fixes --------- - Fix `dbDataType()` for `AsIs` object (#198, @yutannihilation). - Fix `dbQuoteString()` and `dbQuoteIdentifier()` to ignore invalid UTF-8 strings (r-dbi/DBItest#156). Documentation ------------- - Help pages for generics now contain a dynamic list of methods implemented by DBI backends (#162). - `sqlInterpolate()` now supports both named and positional variables (#216, @hannesmuehleisen). - Point to db.rstudio.com (@wibeasley, #209). - Reflect new 'r-dbi' organization in `DESCRIPTION` (@wibeasley, #207). Internal -------- - Using switchpatch on the second argument for default implementations of `dbQuoteString()` and `dbQuoteIdentifier()`.
@github-actions github-actions bot locked and limited conversation to collaborators Oct 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants