| 123456789101112131415161718192021222324252627282930313233343536 |
- #' PostgreSQL - Delete postgresql database table
- #' @details PostgreSql andmebaasi tabeli kustutamine.
- #' @param con An PostgreSQLConnection object as produced by dbConnect.
- #' @param tbl The database table name.
- #' @return eturn message.
- #' @seealso \code{\link{myPostgresConnect}}, \code{\link{myPostgresDropTable}},
- #' \code{\link{myPostgresCreateGisDb}}, \code{\link{myPostgresImprotShp}}
- #' @examples \dontrun{
- #' con <- myPostgresConnect(host = '192.168.255.26', port = 5432,
- #' user = 'osm', password = 'osm', dbname = 'shp')
- #' myPostgresDropTable(con = con, tbl = "xxx")
- #'
- #' }
- #'
- #' @export
- #'
- myPostgresDropTable <- function(con = NULL, tbl) {
- # Check is connection valid
- if(is.null(con) || !DBI::dbIsValid(con)){
- message(paste0("DB connection is not valid!"))
- return()
- }
- # Check if db exists
- if(!DBI::dbExistsTable(con, tolower(tbl))){
- DBI::dbDisconnect(con)
- message(paste0("Tabel ", tbl, " doesn't exist."))
- return()
- }
- # Drop table
- q <- paste("drop table if exists ", tbl, ";")
- res <- DBI::dbSendQuery(con, q)
- DBI::dbHasCompleted(res)
- DBI::dbClearResult(res)
- DBI::dbDisconnect(con)
- }
|