R/queryDB.R

Defines functions queryDB

Documented in queryDB

#' @title A function to query the database
#'
#' @description A queryDB function to perform self-defined queries on the PROFOUND database.
#' @param queryItem a character string providing the query
#' @export
#' @example /inst/examples/queryDBHelp.R
#' @note To report errors in the package or the data, please use the issue tracker
#' in the GitHub repository of ProfoundData \url{https://github.com/COST-FP1304-PROFOUND/ProfoundData}
queryDB <- function(queryItem) {
  # check the item, check if site is list or
  #run.function <- TRUE
  # now start the function itself
  # make connection
  conn <- makeConnection()
  # build query
  # send the query
  queried <- try(RSQLite::dbGetQuery(conn, queryItem))
  result <- NULL
  if ('try-error' %in% class(queried)) {
    #result[[item]] <- dbGetException(conn) # do something about this
    stop("Error when querying:",queryItem, sep = " ") # do something about this
    RSQLite::dbDisconnect(conn)
  }else if (length(queried[,1]) < 1){
    stop("Error when querying:", queryItem, sep = " ") # do something about this
  }else{
    result <- queried
    RSQLite::dbDisconnect(conn)
  }
  return (result)
}

Try the ProfoundData package in your browser

Any scripts or data that you put into this service are public.

ProfoundData documentation built on March 31, 2020, 5:24 p.m.