Skip to content

Commit

Permalink
Added Id method for dbExistsTable to address issue #498
Browse files Browse the repository at this point in the history
  • Loading branch information
kjellpk authored and bpvgoncalves committed Apr 10, 2024
1 parent 919a5cf commit da0771e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Collate:
'dbDataType_SQLiteConnection.R'
'dbDataType_SQLiteDriver.R'
'dbDisconnect_SQLiteConnection.R'
'dbExistsTable_SQLiteConnection_Id.R'
'dbExistsTable_SQLiteConnection_character.R'
'dbFetch_SQLiteResult.R'
'dbGetException_SQLiteConnection.R'
Expand Down
27 changes: 27 additions & 0 deletions R/dbExistsTable_SQLiteConnection_Id.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#' @rdname SQLiteConnection-class
#' @usage NULL
dbExistsTable_SQLiteConnection_Id <- function(conn, name, ...) {
stopifnot(is(name, "Id"))

id <- as.list(dbUnquoteIdentifier(conn, dbQuoteIdentifier(conn, name))[[1]]@name)
schema <- id$schema
table <- id$table

if (!is.null(schema)) {
schemas <- dbGetQuery(conn, "SELECT name FROM pragma_database_list;")$name

if (!(schema %in% schemas)) {
return(FALSE)
}
}

sql <- sqliteListTablesQuery(conn, schema, SQL("$name"))
rs <- dbSendQuery(conn, sql)
dbBind(rs, list(name = tolower(table)))
on.exit(dbClearResult(rs), add = TRUE)

nrow(dbFetch(rs, 1L)) > 0
}
#' @rdname SQLiteConnection-class
#' @export
setMethod("dbExistsTable", c("SQLiteConnection", "Id"), dbExistsTable_SQLiteConnection_Id)
5 changes: 5 additions & 0 deletions man/SQLiteConnection-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit da0771e

Please sign in to comment.