Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import_all_flobs() failing to import with primary keys that include "." #22

Open
joethorley opened this issue Nov 20, 2020 · 0 comments

Comments

@joethorley
Copy link
Member

test_that("import_all_flobs works with .", {

  conn <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
  teardown(DBI::dbDisconnect(conn))

  # 2 column pk
  DBI::dbExecute(conn,
                 "CREATE TABLE df (
                char TEXT NOT NULL,
                num REAL NOT NULL,
                PRIMARY KEY (char, num))")

  # one column pk with empty
  DBI::dbExecute(conn,
                 "CREATE TABLE df2 (
                char TEXT PRIMARY KEY NOT NULL)")

  # one column pk with two blob cols
  DBI::dbWriteTable(conn, "df",
                    data.frame(char = c("a", "a", "b"), num = c(1, 2.1, 1)),
                    append = TRUE)
  DBI::dbWriteTable(conn, "df2", data.frame(char = c("a", "b")), append = TRUE)

  flob <- flobr::flob_obj
  write_flob(flob, "New", "df", key = data.frame(char = "a", num = 1), conn)
  write_flob(flob, "New2", "df", key = data.frame(char = "a", num = 2.1), conn)
  write_flob(flob, "New", "df", key = data.frame(char = "b"), conn)
  write_flob(flob, "New", "df2", key = data.frame(char = "b"), conn)

  path <- file.path(tempdir(), "dbflobr")
  unlink(path, recursive = TRUE)
  dir.create(path)

  save_all_flobs(conn = conn, dir = path, sub = NA)

  expect_identical(import_all_flobs(conn, path, exists = TRUE, sub = TRUE),
                   list(`df/New` = c(`a_-_1` = FALSE, `b_-_1` = FALSE), `df/New2` = c(`a_-_2.1` = FALSE),
                        `df2/New` = c(b = FALSE)))

  # why is it false for a_-_2.1!! (should be true)
  expect_identical(import_all_flobs(conn, path, exists = TRUE, replace = TRUE, sub = TRUE),
                   list(`df/New` = c(`a_-_1` = TRUE, `b_-_1` = TRUE), `df/New2` = c(`a_-_2.1` = FALSE),
                        `df2/New` = c(b = TRUE)))

  list.files(path, recursive = TRUE, include.dirs = TRUE)

  import_flobs("New2", "df", conn = conn, dir = file.path(path, "df", "New2"), sub = TRUE, exists = TRUE, replace = TRUE)

  expect_identical(import_all_flobs(conn, path, exists = TRUE, sub = NA),
                   list(`df/New` = c(`a_-_1` = FALSE, `a_-_2.1` = TRUE, `b_-_1` = FALSE
                   ), `df/New2` = c(`a_-_1` = TRUE, `a_-_2.1` = FALSE, `b_-_1` = TRUE
                   ), `df2/New` = c(a = TRUE, b = FALSE)))

  # why is it false for second a_-_2.1!! (should be true)
  expect_identical(import_all_flobs(conn, path, exists = TRUE, replace = TRUE, sub = NA),
                   list(`df/New` = c(`a_-_1` = TRUE, `a_-_2.1` = TRUE, `b_-_1` = TRUE
                   ), `df/New2` = c(`a_-_1` = TRUE, `a_-_2.1` = FALSE, `b_-_1` = TRUE
                   ), `df2/New` = c(a = TRUE, b = TRUE)))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants