Skip to content

Commit

Permalink
Merge pull request #2148 from cynkra/b-dbi
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr authored Dec 21, 2023
2 parents 16549e1 + 973f093 commit 3c8d712
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion R/build_copy_queries.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ build_copy_queries <- function(dest, dm, set_key_constraints = TRUE, temporary =
name = child_table,
index_name = map_chr(child_fk_cols, paste, collapse = "_"),
remote_name = purrr::map_chr(table_names[name], ~ DBI::dbQuoteIdentifier(con, .x)),
remote_name_unquoted = map_chr(DBI::dbUnquoteIdentifier(con, DBI::SQL(remote_name)), ~ .x@name[["table"]]),
remote_name_unquoted = map_chr(DBI::dbUnquoteIdentifier(con, DBI::SQL(remote_name)), ~ .x@name[[length(.x@name)]]),
index_name = make.unique(paste0(remote_name_unquoted, "__", index_name), sep = "__")
) %>%
group_by(name) %>%
Expand Down
7 changes: 4 additions & 3 deletions R/dm_from_con.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ dm_from_con <- function(
src_tbl_names <- get_src_tbl_names(src, ..., names = .names)
} else {
src_tbl_names <- table_names
if (is.null(names(src_tbl_names))) {
names(src_tbl_names) <- src_tbl_names
}
}

nms <- purrr::map_chr(src_tbl_names, ~ .x@name[["table"]])

tbls <-
set_names(src_tbl_names, nms) %>%
src_tbl_names %>%
quote_ids(con) %>%
map(possibly(tbl, NULL), src = src)

Expand Down
2 changes: 1 addition & 1 deletion R/dm_sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ ddl_get_index_defs <- function(fks, con, table_names) {
name = child_table,
index_name = map_chr(child_fk_cols, paste, collapse = "_"),
remote_name = table_names[name],
remote_name_unquoted = map_chr(DBI::dbUnquoteIdentifier(con, DBI::SQL(remote_name)), ~ .x@name[["table"]]),
remote_name_unquoted = map_chr(DBI::dbUnquoteIdentifier(con, DBI::SQL(remote_name)), ~ .x@name[[length(.x@name)]]),
index_name = make.unique(paste0(remote_name_unquoted, "__", index_name), sep = "__")
) %>%
group_by(name) %>%
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-learn.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test_that("Standard learning from MSSQL (schema 'dbo') or Postgres (schema 'publ
) %>%
DBI::SQL() %>%
DBI::dbUnquoteIdentifier(conn = con_db) %>%
map_chr(~ .x@name[["table"]])
map_chr(~ .x@name[[length(.x@name)]])

remote_tbl_map <- set_names(remote_tbl_names, gsub("^(tf_.).*$", "\\1", remote_tbl_names))

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_dm_from_con.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test_that("table identifiers are quoted", {
suppress_mssql_warning(dm_from_con(con_db, learn_keys = FALSE)) %>%
dm_select_tbl(!!!map(
DBI::dbUnquoteIdentifier(con_db, DBI::SQL(remote_tbl_names_copied)),
~ .x@name[["table"]]
~ .x@name[[length(.x@name)]]
))

remote_tbl_names_learned <-
Expand Down

0 comments on commit 3c8d712

Please sign in to comment.