Commit 6b1970a
Force NLS_LANG to AL32UTF8 for Oracle (OCI) connections (tam#35892)
Multibyte data came back as literal question marks in the app. Measured against a
real database with a column of Japanese text:
NLS_LANG unset, or *.US7ASCII -> every non-ASCII character arrives as 0x3f
*.JA16SJIS -> Shift-JIS bytes, despite unicode_as_utf8=TRUE
*.AL32UTF8 -> correct UTF-8
The server converts before the data reaches the client, so the characters are
gone rather than merely mislabeled, and the design's assumption that the existing
NLS_LANG setting would simply carry over was wrong in both directions: an unset
value loses data, and a value a user set for the ODBC based Oracle data source
(where odbc handles encoding separately) actively breaks OCI.
The character set is therefore forced, not defaulted, keeping the user's language
and territory. NLS_LANG is set only around the connect and restored immediately
after: OCI fixes the client character set when it creates its environment on that
first connect, so later queries and connections in the session stay UTF-8 while
the ODBC path keeps the user's own setting. Verified with a pre-existing
JA16SJIS value present.
Fetched character columns are now also marked as UTF-8. ROracle leaves them
unmarked, which R reads in the session's native encoding - wrong on a machine
running an en_US locale, as this one does.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 0b13d29 commit 6b1970a
3 files changed
Lines changed: 68 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1034 | 1034 | | |
1035 | 1035 | | |
1036 | 1036 | | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
1037 | 1062 | | |
1038 | 1063 | | |
1039 | 1064 | | |
| |||
1990 | 2015 | | |
1991 | 2016 | | |
1992 | 2017 | | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
1993 | 2028 | | |
1994 | 2029 | | |
1995 | 2030 | | |
| |||
2311 | 2346 | | |
2312 | 2347 | | |
2313 | 2348 | | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
2314 | 2360 | | |
2315 | 2361 | | |
2316 | 2362 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1300 | 1300 | | |
1301 | 1301 | | |
1302 | 1302 | | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
0 commit comments