[Rd] RODBC 1.2.2 patch for queries that return 0 rows

Alistair Gee alistair.gee at gmail.com
Fri Dec 21 21:17:53 CET 2007


When using RODBC 1.2.2 on R 2.6, I would sometimes get errors with
sqlQuery() whenever the query returned 0 rows. Using gdb, I found
that the SQLExecDirect () call can return SQL_NO_DATA when using
the ODBC 3.x API. The following patch makes RODBC ignore the
SQL_NO_DATA result:

--- RODBC.orig/src/RODBC.c   2007-07-27 00:26:45.000000000 -0700
+++ RODBC/src/RODBC.c        2007-12-21 10:59:05.198998652 -0800
@@ -349,7 +349,9 @@
    res = SQLExecDirect(thisHandle->hStmt,
                       (SQLCHAR *) CHAR(STRING_ELT(query, 0)),
                       SQL_NTS);
-    if( res != SQL_SUCCESS && res != SQL_SUCCESS_WITH_INFO ) {
+    if( res != SQL_SUCCESS && res != SQL_SUCCESS_WITH_INFO
+      /* ODBC 3.x returns SQL_NO_DATA when no rows affected. */
+      && res != SQL_NO_DATA) {
       errlistAppend(thisHandle, _(err_SQLExecDirect));
       geterr(thisHandle);
       (void)SQLFreeHandle(SQL_HANDLE_STMT, thisHandle->hStmt);



More information about the R-devel mailing list