1

I have a function that catches errors resulting from odbcQuery. How would one make it so that attempting to drop tables that don't exist does not throw an error?

The function:

runQuery <- function(script, channel, errors = T) {
  run <- odbcQuery(channel, script)

  # if the function has returned an error
  if (run == -1L) {
    if (errors) {
      err <- odbcGetErrMsg(channel)

      cat("\nobdcQuery() encountered an error running the following SQL ")
      cat("query:\n\n", script, "\n\nError from Oracle server:\n")

      return(err)

    } else {
      err <- invisible(run)
    }
  }
}
Lorcán
  • 555
  • 3
  • 15
  • 1
    see [here](https://stackoverflow.com/questions/1799128/oracle-if-table-exists) maybe? – OldProgrammer Jan 23 '19 at 17:24
  • What does your code do now that does not work for you? Do you need the `DROP TABLE` line skipped inside of *script*? Or no error raised at all? – Parfait Jan 23 '19 at 18:32
  • I would like their to be no error at all for dropping the table, as not dropping a table may prevent the creation of a new version of said table. – Lorcán Jan 24 '19 at 10:08
  • @OldProgrammer thank you, but I would like the fix to be within the R code as I am using this as a debugging tool for automated table updates via an R server. – Lorcán Jan 24 '19 at 10:57

0 Answers0