Skip to content

Commit 3957ee6

Browse files
Merge pull request #462 from r-dbi/f-list-fields
chore: Refactor `list_fields()`
2 parents e93306e + 1894174 commit 3957ee6

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

R/dbListFields_PqConnection_Id.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' @rdname postgres-tables
22
#' @usage NULL
33
dbListFields_PqConnection_Id <- function(conn, name, ...) {
4-
list_fields(conn, name@name)
4+
list_fields(conn, name)
55
}
66

77
#' @rdname postgres-tables

R/dbListFields_PqConnection_character.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#' @usage NULL
33
dbListFields_PqConnection_character <- function(conn, name, ...) {
44
quoted <- dbQuoteIdentifier(conn, name)
5-
id <- dbUnquoteIdentifier(conn, quoted)[[1]]@name
5+
id <- dbUnquoteIdentifier(conn, quoted)[[1]]
66

77
list_fields(conn, id)
88
}

R/tables.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,17 @@ find_temp_schema <- function(conn, fail_if_missing = TRUE) {
216216
}
217217

218218
list_fields <- function(conn, id) {
219-
query <- find_table(conn, id, "columns", only_first = TRUE)
219+
name <- id@name
220+
221+
query <- find_table(conn, name, "columns", only_first = TRUE)
220222
query <- paste0(
221223
"SELECT column_name FROM ",
222224
query, " ",
223225
"ORDER BY ordinal_position"
224226
)
225227
fields <- dbGetQuery(conn, query)[[1]]
226228
if (length(fields) == 0) {
227-
stop("Table ", dbQuoteIdentifier(conn, id), " not found.", call. = FALSE)
229+
stop("Table ", dbQuoteIdentifier(conn, name), " not found.", call. = FALSE)
228230
}
229231
fields
230232
}

0 commit comments

Comments
 (0)