Bug in ODBC driver doing UPDATES and DELETES
От | Tim Woodall |
---|---|
Тема | Bug in ODBC driver doing UPDATES and DELETES |
Дата | |
Msg-id | Pine.LNX.4.44.0305201147001.22492-100000@pauli.locofungus.org обсуждение исходный текст |
Ответы |
Re: Bug in ODBC driver doing UPDATES and DELETES
(Tim Woodall <pgsql-odbc@woodall.me.uk>)
|
Список | pgsql-odbc |
When doing an UPDATE or DELETE via ODBC, if no records are affected then SQLExecute should return SQL_NO_DATA_FOUND and not SQL_SUCCESS. I have included two patches below. The first is against RH7.2 latest update which is tested. The other is against the latest CVS source and isn't tested. Regards, Tim. diff -ur postgresql-7.1.3/src/interfaces/odbc/statement.c postgresql-7.1.3-patched/src/interfaces/odbc/statement.c --- postgresql-7.1.3/src/interfaces/odbc/statement.c Mon Apr 23 02:00:49 2001 +++ postgresql-7.1.3-patched/src/interfaces/odbc/statement.c Thu May 15 16:30:46 2003 @@ -864,6 +864,13 @@ Int2 oldstatus, numcols; QueryInfo qi; + char 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 and not SQL_SUCCESS. + * I'm not sure about the use of char rather than int but this is + * consistent with the other was_* variables above. + */ conn = SC_get_conn(self); @@ -998,6 +1005,13 @@ was_ok = QR_command_successful(self->result); was_nonfatal = QR_command_nonfatal(self->result); + if(self->result->command && + (strncmp(self->result->command, "UPDATE", 6) == 0 || + strncmp(self->result->command, "DELETE", 6) == 0) && + strtoul(self->result->command + 7, NULL, 0) == 0) + { + was_rows_affected = 0; + } if (was_ok) self->errornumber = STMT_OK; @@ -1055,7 +1069,10 @@ } if (self->errornumber == STMT_OK) - return SQL_SUCCESS; + if(was_rows_affected) + return SQL_SUCCESS; + else + return SQL_NO_DATA_FOUND; else { Index: statement.c =================================================================== RCS file: /usr/local/cvsroot/psqlodbc/psqlodbc/statement.c,v retrieving revision 1.77 diff -u -r1.77 statement.c --- statement.c 12 May 2003 15:44:08 -0000 1.77 +++ statement.c 20 May 2003 10:45:35 -0000 @@ -1024,7 +1024,14 @@ 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 and not SQL_SUCCESS. + * I'm not sure about the use of char rather than int but this is + * consistent with the other was_* variables above. + */ + QResultClass *res = NULL; Int2 oldstatus, numcols; @@ -1144,6 +1151,13 @@ { was_ok = QR_command_successful(res); was_nonfatal = QR_command_nonfatal(res); + if(self->result->command && + (strncmp(self->result->command, "UPDATE", 6) == 0 || + strncmp(self->result->command, "DELETE", 6) == 0) && + strtoul(self->result->command + 7, NULL, 0) == 0) + { + was_rows_affected = 0; + } if (was_ok) SC_set_errornumber(self, STMT_OK); @@ -1246,7 +1260,10 @@ } } 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 -- God said, "div D = rho, div B = 0, curl E = - @B/@t, curl H = J + @D/@t," and there was light. http://tjw.hn.org/ http://www.locofungus.btinternet.co.uk/
В списке pgsql-odbc по дате отправления: