Rodbc Error Handling For Sqlquery
I did not find any good error testing function for the results of an sqlQuery and that surprises me. In the documentation (http://www.inside-r.org/packages/cran/rodbc/docs/sqlQuery
Solution 1:
Yes, the situation seems horrendous, but in practise it isn't as bad as it might be. The documentation is vague and convoluted because RODBC handles connections to any sort of database and different databases return different things in the event of problems.
I've done a fair amount of work using ROBDC to connect R to SQL Server, and in general SELECT queries were easy enough to deal with: they return a data frame is they work, and a character vector if not. So code like
records <- sqlQuery(channel, "SELECT blah FROM somewhere")
if(is.character(records))
{
stop(paste(records, collapse = "\n"))
}
works well enough.
For absolute certainty, you'll need to be more thorough, but if you are connecting to only one type of database, it will hopefully be consistent about how it fails.
Post a Comment for "Rodbc Error Handling For Sqlquery"