F.sql.error.check | R Documentation |
Check if a SQL statement executed correctly.
F.sql.error.check(obj)
obj |
The results from an Access query. See Details. |
Function F.sql_error_check
is used immediately after the
use of RODBC
function sqlQuery
, which queries an Access database via a text
string formatted as a SQL query. Function sqlQuery
, if successful, results in
a dataframe, possibly with zero rows. Otherwise, a character vector with
error messsages is returned. Function F.sql.error.check
examines if an error
message is returned, and if found, stops execution and prints an error
message to the R_run.out
text file or the R Console.
FALSE
, assuming successful completion of a SQL query. Otherwise, an
error message to either the Console window, if running directly via R, or
to the run_R.out
file, if running via the Platform.
WEST Inc.
sqlQuery
## Not run: # ---- Set up an Access mdb in R. db.file <- "C:/yourPath/CAMP.mdb" # The location of CAMP.mdb db <- get( "db.file", envir=.GlobalEnv ) # Assign the mdb string. ch <- odbcConnectAccess(db) # Connect R and Access. # ---- Conduct a good query. ans <- sqlQuery( ch, "SELECT * FROM luRun" ) # Select all rows. F.sql.error.check(ans) # Check for validity. # --> Results in FALSE. # ---- Conduct a bad query. ans <- sqlQuery( ch, "SELECT * FROM fakeTable" ) # Select all rows. F.sql.error.check(ans) # Check for validity. # --> Results in error message. ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.