Skip to content

Commit

Permalink
Merge pull request #260 from LeeMendelowitz/mysql8_json_support
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr authored Oct 6, 2023
2 parents 345df73 + ff2aec4 commit 647fd2b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/MariaTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
bool all_raw(SEXP x);

MariaFieldType variable_type_from_field_type(enum_field_types type, bool binary, bool length1) {

switch (type) {
case MYSQL_TYPE_TINY:
case MYSQL_TYPE_SHORT:
Expand Down Expand Up @@ -53,7 +54,8 @@ MariaFieldType variable_type_from_field_type(enum_field_types type, bool binary,
case MYSQL_TYPE_NULL:
return MY_INT32;
default:
cpp11::stop("Unimplemented MAX_NO_FIELD_TYPES: %d", type);
cpp11::warning("unrecognized field type %i imported as character", type);
return MY_STR;
}
}

Expand Down
11 changes: 6 additions & 5 deletions tests/testthat/test-dbWriteTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ test_that("writing and reading JSON (#127)", {
x <- data.frame(col1 = "[1,2,3]", stringsAsFactors = FALSE)

dbWriteTable(con, "t1", x, field.types = c(col1 = "json"), overwrite = TRUE, temporary = TRUE)
dbReadTable(con, "t1")

expect_equal(
gsub(" ", "", dbReadTable(con, "t1")$col1),
x$col1
)
suppressWarnings(d <- dbReadTable(con, "t1"))

# MySQL 8 returns "[1, 2, 3]", while MariaDB returns "[1,2,3]"
d$col1 <- gsub('\\s', '', d$col1)

expect_equal(d, x)
})

0 comments on commit 647fd2b

Please sign in to comment.