Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- Fix time zone interpretation in `DATETIMEOFFSET` data; now follows
ISO 8061 convention where positive offset denotes time zone east of Greenwich. (#946)

* `varchar()` helper now returns number of bytes not characters (#960)

# odbc 1.6.3

* Addressed a compiler warning on `r-devel-linux-x86_64-fedora-clang` (#941).
Expand Down
2 changes: 1 addition & 1 deletion R/aaa-odbc-data-type.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ is_blob <- function(obj) {

varchar <- function(x, type = "varchar") {
# at least 255 characters, use max if more than 8000:
max_length <- max(c(255, nchar(as.character(x))), na.rm = TRUE)
max_length <- max(c(255, nchar(as.character(x), type = "bytes")), na.rm = TRUE)

if (max_length > 8000) {
max_length <- "max"
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,9 @@ test_that("configure_unixodbc_simba() writes reasonable entries", {
action = "warn"
))
})

test_that("varchar() uses byte length (avoids truncation with multibyte)", {
# U+2019 RIGHT SINGLE QUOTATION MARK in UTF-8 is 3 bytes
string <- paste0("\xe2\x80\x99", paste(rep("a", 255), collapse = ""))
expect_equal(varchar(string, type = "varchar"), "varchar(258)")
})
Loading