
if (FALSE) {

  getSnowflakeDB <- function(showWarnings=TRUE) {

    dbname <- getOption("snowflake_dbname")
    if (is.null(dbname) && showWarnings)
      warning("The snowflake DB is not set. HINT:    setSnowflakeDB()")
    return(dbname)
  }

  setSnowflakeDB <- function(dbname, schema=NULL, verbose=TRUE, verbose.qry=verbose) {
    is.char_of_length1(dbname, fail=TRUE)
    current <- getSnowflakeDB(showWarnings=FALSE)
    ## TODO: verbose to include current
    if (!is.null(current) && (current != dbname))
      verboseMsg(verbose, "Changing the snowflake DB from '", current, "' to '", dbname, "'")
    else 
      verboseMsg(verbose, "Setting the snowflake DB to '", dbname, "'")

    sfQry(paste0("USE DATABASE ", dbname), verbose=verbose.qry)
    if (!is.null(schema))
      sfQry(paste0("USE SCHEMA ", schema), verbose=verbose.qry)


    options("snowflake_dbname" = dbname)
    return(invisible(dbname))
  }


  sfGetCurrentWH <- function(warehouse=getOption("snowflake_defaultwh"), connex=sfGetCon(), refresh=TRUE, justname=FALSE, verbose=TRUE) {
    prev_opt <- getOption("snowflake_currentwh")

    if (refresh || is.null(prev_opt)) {
      current <- sqlQuery(connex, 'SELECT CURRENT_WAREHOUSE() AS WH', stringsAsFactors=FALSE)[, 'WH']
      if (length(current) > 1) {
        ## Only one warehouse expected.  Thus throwing error in the event of multiple results
        stop ("More than one warehouse returned:", paste(c("", current), collapse="\n\t"))
        current <- current[[1]]
      }
      current_opt <- list(name=toupper(current), last_checked=now())
      options("snowflake_currentwh"=current_opt)    
    } else
      current_opt <- prev_opt


    if (verbose) {
      prev <- if (is.null(prev_opt)) "There was no previously set warehouse\n" else sprintf ("Previous warehouse was '%s', last checked at %s\n", prev_opt$name, prev_opt$last_checked)
      curr <- sprintf ("Current warehouse is '%s', updated at %s", current_opt$name, current_opt$last_checked)
      cat(if (!identical(current_opt, prev_opt)) prev, curr, sep="", fill=TRUE) 
    }
    if (justname)
      return(current_opt$name)
    return(invisible(current_opt))
  }


  sfSetCurrentWH <- function(warehouse=getOption("snowflake_defaultwh"), connex=sfGetCon(), check_if_valid=TRUE, dbname=NULL, verbose="auto") {
  ## verbose :: auto = only verbose if warehouse was changed. 

    if (!is.character(warehouse) || is.na(warehouse))
      stop ("Invalid warehouse value")

    .DBlib("snowflake")

    warehouse <- toupper(warehouse)
    prev <- sfGetCurrentWH(verbose=FALSE, refresh=TRUE, justname=TRUE)

    if (prev != warehouse) {

      ## Check if valid warehouse name
      if (check_if_valid) {
        if (!(warehouse %in% toupper(sfShowWarehouses(warehouse=NULL, justname=TRUE))))
          warning ("warehouse '", warehouse,"' was not in the results of sfShowWarehouses()")
      }

      sqlQuery(connex, sprintf("USE WAREHOUSE %s", warehouse), stringsAsFactors=FALSE)
      ## Confirm change took place
      current <- sfGetCurrentWH(verbose=FALSE, refresh=TRUE, justname=TRUE)
      if (current != warehouse)
        warning ("current warehouse (", current, ") is not the same as 'warehouse' (", warehouse, ")")
      else if (isTRUE(verbose) || identical(verbose, "auto"))
        cat("warehouse succesfully changed to '", warehouse, "'\n", sep="")
    } else {
      current <- warehouse
      if (isTRUE(verbose))
          cat("warehouse did not need to be changed. Already set to '", warehouse, "'\n", sep="")
    }

    options("snowflake_currentwh"=current)

    if (!is.null(dbname))
      .sf_useDB(dbname=dbname, wh=NULL, verbose=isTRUE(verbose) || verbose == "auto")

    return(invisible(current))
  }


  sfSetWarehouseDetails <- function(name, ..., size=NULL, type=NULL, time_started=now() - 30, last_ran=NA, showWarnings=TRUE) {
    force(time_started)

    "REMINDER TO SELF:   This just sets local meta on LAST_RAN for the WH "
    "                    You probably want sfSetCurrentWH()               "

    if (missing(name))
      stop ("Argument 'name' cannot be missing from sfSetWarehouseDetails(name, ...)", call.=FALSE)
    name <- .sf_clean_name(name = name)



    ## Confirm all of these expected inputs are of length one
    if (!is.null(time_started)) is.char_of_length1(as.character(time_started), fail=TRUE)
    if (!is.null(last_ran))     is.char_of_length1(as.character(last_ran),     fail=TRUE)


    ## convert dots to list. Taking their names as the substituted value, if names is blank
    dots <- list(...)
    nms_dots <- substitute(list(...)) %>% as.list %>% .[-1] %>% as.character
    setnamesIfBlank_(dots, nms_dots)

    ## Put together the list of options.  Wrapping time_started in list to (a) ensure the whole vector gets coerced and (b) to keep it as POSIX
    ## Also cleaning 
    opts <- c(    .sf_clean_wh_input(name=name, size=size, type=type)
                , dots
                , time_started=list(time_started[[1]])
                , last_ran=list(last_ran)
                , this_last_updated=list(now())
             )

    list_name <- .sf.make_list_name(name, size, type)

    current_options <- getOption("sf_warehouses", default=list())
    
    if (showWarnings && !is.null(current_options[[list_name]]))
      warning ("Option '", list_name, "' already exists and will be overwritten in\n    options('sf_warehouses')", call.=FALSE)

    current_options[[list_name]] <- opts
    
    options(sf_warehouses = current_options)

    return (invisible(current_options))
  }

}
