pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedBug in ODBC driver doing UPDATES and DELETES
2+ messages / 2 participants
[nested] [flat]
* Bug in ODBC driver doing UPDATES and DELETES
@ 2003-05-15 16:23 Tim Woodall <pgsql-interfaces@woodall.me.uk>
2003-06-02 16:08 ` Re: Bug in ODBC driver doing UPDATES and DELETES Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Tim Woodall @ 2003-05-15 16:23 UTC (permalink / raw)
To: pgsql-interfaces
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.
The following patch fixes this problem.
Regards,
Tim.
inline patch 1: postgresql-7.1.3-patched/src/interfaces/odbc/statement.c (+0/-0 lines) download inline-1.patch
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
{
--
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/
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Bug in ODBC driver doing UPDATES and DELETES
2003-05-15 16:23 Bug in ODBC driver doing UPDATES and DELETES Tim Woodall <pgsql-interfaces@woodall.me.uk>
@ 2003-06-02 16:08 ` Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Bruce Momjian @ 2003-06-02 16:08 UTC (permalink / raw)
To: Tim Woodall <pgsql-interfaces@woodall.me.uk>; +Cc: pgsql-interfaces
Got it and will apply shortly. Thanks.
---------------------------------------------------------------------------
Tim Woodall wrote:
> 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.
>
> The following patch fixes this problem.
>
> 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
> {
>
> --
> 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/
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-06-02 16:08 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-05-15 16:23 Bug in ODBC driver doing UPDATES and DELETES Tim Woodall <pgsql-interfaces@woodall.me.uk>
2003-06-02 16:08 ` Bruce Momjian <pgman@candle.pha.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox