odbc icon indicating copy to clipboard operation
odbc copied to clipboard

SQL Server: On Windows, dbListTable shows garbled Japanese table names.

Open hidekoji opened this issue 4 years ago • 2 comments

Issue Description and Expected Result

dbListTable shows garbled Japanese table names.

Database

SQL Server 2014 RTM SQL Azure 12.0.2000.8

Reproducible Example

With odbc package version 1.3.2, The below R script result shows garbled "繝輔Λ繧、繝\x88" as a table name where it should be "フライト"

Sys.setlocale(category="LC_CTYPE", locale="English_United States.932"); 
#> [1] "English_United States.932"
conn <- DBI::dbConnect(odbc::odbc(),
                       Driver = "ODBC Driver 17 for SQL Server",
                       Server = "server",
                       Database = "database",
                       UID = "user",
                       PWD = "password",
                       Port = 1433,
                       bigint = "numeric")
odbc::dbListTables(conn, schema = "dbo")
#>  [1] "airline_2013_10_tricky_v5_ja" "airline_2013_6"              
#>  [3] "BuildVersion"                 "Datetime2_Test"              
#>  [5] "ErrorLog"                     "Global_Sales"                
#>  [7] "Japanese_name_test"           "Japanese_Test"               
#>  [9] "Japanese_test_utf8"           "sysdiagrams"                 
#> [11] "繝輔Λ繧、繝\x88"

Created on 2021-09-06 by the reprex package (v2.0.1)

hidekoji avatar Sep 06 '21 18:09 hidekoji

Directly querying from information_schema.tables works like below.

Sys.setlocale(category="LC_CTYPE", locale="English_United States.932"); 
#> [1] "English_United States.932"
# stringi::stri_enc_set("windows-932")
conn <- DBI::dbConnect(odbc::odbc(),
                       Driver = "ODBC Driver 17 for SQL Server",
                       Server = "server",
                       Database = "database",
                       UID = "user",
                       PWD = "password",
                       Port = 1433,
                       bigint = "numeric")
#odbc::dbListTables(conn, schema = "dbo")
df <- DBI::dbGetQuery(conn, "SELECT table_schema as schema_name, table_name FROM information_schema.tables WHERE table_schema='dbo'");
df
#>    schema_name                   table_name
#> 1          dbo               Datetime2_Test
#> 2          dbo                     フライト
#> 3          dbo                  sysdiagrams
#> 4          dbo               airline_2013_6
#> 5          dbo                 Global_Sales
#> 6          dbo airline_2013_10_tricky_v5_ja
#> 7          dbo                 BuildVersion
#> 8          dbo                     ErrorLog
#> 9          dbo           Japanese_name_test
#> 10         dbo                Japanese_Test
#> 11         dbo           Japanese_test_utf8

Created on 2021-09-06 by the reprex package (v2.0.1)

hidekoji avatar Sep 06 '21 18:09 hidekoji

Looks like a duplicate of #432 and #430. PR #431 should fix this, but hasn't been merged yet.

hongooi73 avatar Sep 11 '21 23:09 hongooi73