From bfd15af1c6a38f789a36a7a73c57cbdf433dcc6d Mon Sep 17 00:00:00 2001 From: Lee Mendelowitz Date: Sat, 26 Feb 2022 13:01:34 -0500 Subject: [PATCH 1/5] Use string as default for unknown column type --- DESCRIPTION | 2 +- src/MariaTypes.cpp | 4 +++- tests/testthat/test-dbWriteTable.R | 9 +++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 33fc6619..2485bb17 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: RMariaDB Title: Database Interface and MariaDB Driver -Version: 1.2.1.9000 +Version: 1.2.1.9001 Authors@R: c(person(given = "Kirill", family = "M\u00fcller", diff --git a/src/MariaTypes.cpp b/src/MariaTypes.cpp index dd0df652..fa0c6910 100644 --- a/src/MariaTypes.cpp +++ b/src/MariaTypes.cpp @@ -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: @@ -51,7 +52,8 @@ MariaFieldType variable_type_from_field_type(enum_field_types type, bool binary, case MYSQL_TYPE_NULL: return MY_INT32; default: - throw std::runtime_error("Unimplemented MAX_NO_FIELD_TYPES"); + warning("unrecognized field type %i imported as character", type); + return MY_STR; } } diff --git a/tests/testthat/test-dbWriteTable.R b/tests/testthat/test-dbWriteTable.R index 6e48b3db..840e0c4d 100644 --- a/tests/testthat/test-dbWriteTable.R +++ b/tests/testthat/test-dbWriteTable.R @@ -79,7 +79,12 @@ 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(dbReadTable(con, "t1"), x) + 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) + }) From 511289500e584b6d6fdb2deae5b1e232493fed39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 18 Jun 2022 03:21:32 +0200 Subject: [PATCH 2/5] Apply suggestions from code review --- DESCRIPTION | 2 +- tests/testthat/test-dbWriteTable.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2485bb17..33fc6619 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: RMariaDB Title: Database Interface and MariaDB Driver -Version: 1.2.1.9001 +Version: 1.2.1.9000 Authors@R: c(person(given = "Kirill", family = "M\u00fcller", diff --git a/tests/testthat/test-dbWriteTable.R b/tests/testthat/test-dbWriteTable.R index 840e0c4d..0453e25f 100644 --- a/tests/testthat/test-dbWriteTable.R +++ b/tests/testthat/test-dbWriteTable.R @@ -80,7 +80,7 @@ test_that("writing and reading JSON (#127)", { dbWriteTable(con, "t1", x, field.types = c(col1 = "json"), overwrite = TRUE, temporary = TRUE) - d <- dbReadTable(con, "t1") + expect_warning(d <- dbReadTable(con, "t1")) # MySQL 8 returns "[1, 2, 3]", while MariaDB returns "[1,2,3]" d$col1 <- gsub('\\s', '', d$col1) From 38273d961a492bbdbff3ae861ff3ec648347a355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Thu, 16 Mar 2023 04:40:50 +0100 Subject: [PATCH 3/5] Qualify warning call --- src/MariaTypes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MariaTypes.cpp b/src/MariaTypes.cpp index 8a2392e1..b6756e57 100644 --- a/src/MariaTypes.cpp +++ b/src/MariaTypes.cpp @@ -52,7 +52,7 @@ MariaFieldType variable_type_from_field_type(enum_field_types type, bool binary, case MYSQL_TYPE_NULL: return MY_INT32; default: - warning("unrecognized field type %i imported as character", type); + cpp11::warning("unrecognized field type %i imported as character", type); return MY_STR; } } From 47d921a26d0e445a7c68176382945394830ba30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Thu, 16 Mar 2023 06:10:31 +0100 Subject: [PATCH 4/5] Don't test warning --- tests/testthat/test-dbWriteTable.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-dbWriteTable.R b/tests/testthat/test-dbWriteTable.R index 9ae44a46..e60e4507 100644 --- a/tests/testthat/test-dbWriteTable.R +++ b/tests/testthat/test-dbWriteTable.R @@ -86,7 +86,8 @@ test_that("writing and reading JSON (#127)", { dbWriteTable(con, "t1", x, field.types = c(col1 = "json"), overwrite = TRUE, temporary = TRUE) - expect_warning(d <- dbReadTable(con, "t1")) + # FIXME: warning conditional on database version + expect_warning(d <- dbReadTable(con, "t1"), NA) # MySQL 8 returns "[1, 2, 3]", while MariaDB returns "[1,2,3]" d$col1 <- gsub('\\s', '', d$col1) From ff2aec49c75a910ff3d9d25320641ce9c8573d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Fri, 6 Oct 2023 15:52:48 +0200 Subject: [PATCH 5/5] Oops --- tests/testthat/test-dbWriteTable.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-dbWriteTable.R b/tests/testthat/test-dbWriteTable.R index 87658545..f3b6a5cf 100644 --- a/tests/testthat/test-dbWriteTable.R +++ b/tests/testthat/test-dbWriteTable.R @@ -86,7 +86,7 @@ test_that("writing and reading JSON (#127)", { dbWriteTable(con, "t1", x, field.types = c(col1 = "json"), overwrite = TRUE, temporary = TRUE) - suppressWarnings(d <- dbReadTable(con, "t1"), NA) + suppressWarnings(d <- dbReadTable(con, "t1")) # MySQL 8 returns "[1, 2, 3]", while MariaDB returns "[1,2,3]" d$col1 <- gsub('\\s', '', d$col1)