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

should mark UTF-8 on the non-ASCII colnames #276

Merged
merged 2 commits into from Dec 30, 2018
Merged

Conversation

@shrektan
Copy link
Contributor

shrektan commented Dec 29, 2018

Without the UTF8 marking, DBI::dbListFields() returns garbage strings on Windows.

Furthermore, DBI::dbWriteTable(..., append = TRUE) will fail, if the table fields contain non-ASCII strings, since it depends on DBI::dbListFields().

RSQLite/R/table.R

Lines 115 to 116 in 33d3631

col_names <- dbListFields(conn, name)
value <- match_col(value, col_names)

This PR will fix the issue.

Example

con <- DBI::dbConnect(RSQLite::SQLite())
tbl <- data.frame("中文" = 'a')
DBI::dbWriteTable(con, name = 'test', value = tbl)
got <- DBI::dbListFields(con, 'test')
got
#> [1] "涓枃"
Encoding(got)
#> [1] "unknown"
Encoding(got) <- 'UTF-8'
got
#> [1] "中文"

Created on 2018-12-30 by the reprex package (v0.2.1)

Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                                              
#>  version  R version 3.5.1 (2018-07-02)                       
#>  system   x86_64, mingw32                                    
#>  ui       RTerm                                              
#>  language (EN)                                               
#>  collate  Chinese (Simplified)_People's Republic of China.936
#>  tz       Asia/Taipei                                        
#>  date     2018-12-30
#> Packages -----------------------------------------------------------------
#>  package   * version date       source        
#>  backports   1.1.2   2017-12-13 CRAN (R 3.5.0)
#>  base      * 3.5.1   2018-07-02 local         
#>  bit         1.1-14  2018-05-29 CRAN (R 3.5.2)
#>  bit64       0.9-7   2017-05-08 CRAN (R 3.5.2)
#>  blob        1.1.1   2018-03-25 CRAN (R 3.5.2)
#>  compiler    3.5.1   2018-07-02 local         
#>  datasets  * 3.5.1   2018-07-02 local         
#>  DBI         1.0.0   2018-05-02 CRAN (R 3.5.2)
#>  devtools    1.13.6  2018-06-27 CRAN (R 3.5.1)
#>  digest      0.6.17  2018-09-12 CRAN (R 3.5.1)
#>  evaluate    0.11    2018-07-17 CRAN (R 3.5.1)
#>  graphics  * 3.5.1   2018-07-02 local         
#>  grDevices * 3.5.1   2018-07-02 local         
#>  htmltools   0.3.6   2017-04-28 CRAN (R 3.5.1)
#>  knitr       1.20    2018-02-20 CRAN (R 3.5.1)
#>  magrittr    1.5     2014-11-22 CRAN (R 3.5.1)
#>  memoise     1.1.0   2017-04-21 CRAN (R 3.5.1)
#>  methods   * 3.5.1   2018-07-02 local         
#>  pkgconfig   2.0.2   2018-08-16 CRAN (R 3.5.2)
#>  Rcpp        1.0.0   2018-11-07 CRAN (R 3.5.1)
#>  rmarkdown   1.10    2018-06-11 CRAN (R 3.5.1)
#>  rprojroot   1.3-2   2018-01-03 CRAN (R 3.5.1)
#>  RSQLite     2.1.1   2018-05-06 CRAN (R 3.5.2)
#>  stats     * 3.5.1   2018-07-02 local         
#>  stringi     1.1.7   2018-03-12 CRAN (R 3.5.0)
#>  stringr     1.3.1   2018-05-10 CRAN (R 3.5.1)
#>  tools       3.5.1   2018-07-02 local         
#>  utils     * 3.5.1   2018-07-02 local         
#>  withr       2.1.2   2018-03-15 CRAN (R 3.5.1)
#>  yaml        2.2.0   2018-07-25 CRAN (R 3.5.1)
shrektan added 2 commits Dec 29, 2018
Otherwise, it leads to garbage colnames on Windows
@krlmlr krlmlr merged commit cdbf3b9 into r-dbi:master Dec 30, 2018
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
deploy/netlify Deploy preview ready!
Details
@krlmlr

This comment has been minimized.

Copy link
Member

krlmlr commented Dec 30, 2018

Thanks!

@shrektan shrektan deleted the shrektan:utf8-colnames branch Dec 30, 2018
wush978 added a commit to wush978/RSQLite that referenced this pull request Dec 30, 2018
wush978 added a commit to wush978/RSQLite that referenced this pull request Dec 30, 2018
wush978 added a commit to wush978/RSQLite that referenced this pull request Dec 30, 2018
Revert "r-dbi#276"
wush978 added a commit to wush978/RSQLite that referenced this pull request Dec 30, 2018
wush978 added a commit to wush978/RSQLite that referenced this pull request Dec 30, 2018
Revert "Revert "r-dbi#276""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.