From alistair.gee at gmail.com  Fri Dec 21 21:17:53 2007
From: alistair.gee at gmail.com (Alistair Gee)
Date: Fri, 21 Dec 2007 12:17:53 -0800
Subject: [Rd] RODBC 1.2.2 patch for queries that return 0 rows
Message-ID: <e63850350712211217j16758b89q76f6e4a0c2288873@mail.gmail.com>

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);



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