A question about this R code:
library(RODBC)
ch <- tryCatch(odbcConnect("RTEST"),
warning=function(w){print("FAIL! (warning)");return(NA)},
error=function(e){print(paste("ERROR:",geterrmessage()));return(NA)})
df <- tryCatch(sqlQuery(ch,"SELECT Test from tblTest"),
warning=function(w){print("FAIL! (warning)");return(NA)},
error=function(e){print(paste("ERROR:",geterrmessage()));return(NA)})
odbcClose(ch)
Code works fine for errors (forced by omitting the required paramaters in the code) in both cases (warning- and error part are almost exactly the same): I get a NA value and an errormessage.
Also for an error with sqlQuery (give an invalid DSN): NA value and an errormessage.
But not for warnings with sqlQuery. No message output, but df
contains the message (so no NA). Why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…