When doing an UPDATE or DELETE via ODBC, if no records are affected then SQLExecute...
authorDave Page <dpage@pgadmin.org>
Thu, 19 Jun 2003 16:10:20 +0000 (16:10 +0000)
committerDave Page <dpage@pgadmin.org>
Thu, 19 Jun 2003 16:10:20 +0000 (16:10 +0000)
The following patch to RH9 applies to the version in CVS (with an offset). This patch has been tested on RH9.
[Tim Woodall]

statement.c

index 23d097f4c040d973c2f9614e5e97fa34dd393a7c..43871cdfc1f221b144a5a51c88da845b17685db7 100644 (file)
@@ -1022,7 +1022,12 @@ SC_execute(StatementClass *self)
    static char *func = "SC_execute";
    ConnectionClass *conn;
    APDFields   *apdopts;
-   char        was_ok, was_nonfatal;
+   char        was_ok, was_nonfatal, was_rows_affected = 1;
+   /* was_rows_affected is set to 0 iff an UPDATE or DELETE affects 
+    * no rows. In this instance the driver should return
+    * SQL_NO_DATA_FOUND instead of SQL_SUCCESS.
+    */
    QResultClass    *res = NULL;
    Int2        oldstatus,
                numcols;
@@ -1142,6 +1147,13 @@ SC_execute(StatementClass *self)
    {
        was_ok = QR_command_successful(res);
        was_nonfatal = QR_command_nonfatal(res);
+       if (res->command &&
+           (strncmp(res->command, "UPDATE", 6) == 0 ||
+           strncmp(res->command, "DELETE", 6) == 0) &&
+           strtoul(res->command + 7, NULL, 0) == 0)
+       {
+           was_rows_affected = 0;
+       }
 
        if (was_ok)
            SC_set_errornumber(self, STMT_OK);
@@ -1244,7 +1256,10 @@ SC_execute(StatementClass *self)
        }
    }
    if (SC_get_errornumber(self) == STMT_OK)
-       return SQL_SUCCESS;
+       if (was_rows_affected)
+           return SQL_SUCCESS;
+       else
+           return SQL_NO_DATA_FOUND;
    else if (SC_get_errornumber(self) == STMT_INFO_ONLY)
        return SQL_SUCCESS_WITH_INFO;
    else