Thread: [PATCH] fix for wrong error code returned

[PATCH] fix for wrong error code returned

From
"Scot Loach"
Date:
This patch corrects the previous fix for returning 08S01 error code for the server disconnecting.
The previous patch sent this error code for any error on the statement (such as a primary key collision).

--- statement.c.old     2005-09-17 13:03:28.000000000 -0400
+++ statement.c 2005-09-17 12:54:31.000000000 -0400
@@ -1093,7 +1093,7 @@
        CSTR func = "SC_execute";
        ConnectionClass *conn;
        IPDFields       *ipdopts;
-       char            was_ok, was_nonfatal,was_fatal;
+       char            was_ok, was_nonfatal;
        QResultClass    *res = NULL;
        Int2            oldstatus,
                                numcols;
@@ -1221,15 +1221,19 @@
        {
                was_ok = QR_command_successful(res);
                was_nonfatal = QR_command_nonfatal(res);
-               was_fatal = QR_command_fatal(res);

                if (was_ok)
                        SC_set_errornumber(self, STMT_OK);
-               else if (was_fatal)
-                       SC_set_errornumber(self,STMT_BAD_ERROR);
                else
                        SC_set_errornumber(self, was_nonfatal ? STMT_INFO_ONLY : STMT_ERROR_TAKEN_FROM_BACKEND);

+#ifdef USE_LIBPQ
+               if (QR_command_fatal(res) && PQstatus(conn->pgconn) == CONNECTION_BAD)
+               {
+                   SC_set_errornumber(self, STMT_BAD_ERROR);
+               }
+#endif /* USE_LIBPQ */
+
                /* set cursor before the first tuple in the list */
                self->currTuple = -1;
                SC_set_current_col(self, -1);

Re: [PATCH] fix for wrong error code returned

From
"Dave Page"
Date:
Thanks, patch applied.

/D

> -----Original Message-----
> From: Scot Loach [mailto:sloach@sandvine.com]
> Sent: 17 September 2005 18:05
> To: pgsql-odbc@postgresql.org; Dave Page
> Subject: [PATCH] fix for wrong error code returned
>
> This patch corrects the previous fix for returning 08S01
> error code for the server disconnecting.
> The previous patch sent this error code for any error on the
> statement (such as a primary key collision).
>
> --- statement.c.old     2005-09-17 13:03:28.000000000 -0400
> +++ statement.c 2005-09-17 12:54:31.000000000 -0400
> @@ -1093,7 +1093,7 @@
>         CSTR func = "SC_execute";
>         ConnectionClass *conn;
>         IPDFields       *ipdopts;
> -       char            was_ok, was_nonfatal,was_fatal;
> +       char            was_ok, was_nonfatal;
>         QResultClass    *res = NULL;
>         Int2            oldstatus,
>                                 numcols;
> @@ -1221,15 +1221,19 @@
>         {
>                 was_ok = QR_command_successful(res);
>                 was_nonfatal = QR_command_nonfatal(res);
> -               was_fatal = QR_command_fatal(res);
>
>                 if (was_ok)
>                         SC_set_errornumber(self, STMT_OK);
> -               else if (was_fatal)
> -                       SC_set_errornumber(self,STMT_BAD_ERROR);
>                 else
>                         SC_set_errornumber(self, was_nonfatal
> ? STMT_INFO_ONLY : STMT_ERROR_TAKEN_FROM_BACKEND);
>
> +#ifdef USE_LIBPQ
> +               if (QR_command_fatal(res) &&
> PQstatus(conn->pgconn) == CONNECTION_BAD)
> +               {
> +                   SC_set_errornumber(self, STMT_BAD_ERROR);
> +               }
> +#endif /* USE_LIBPQ */
> +
>                 /* set cursor before the first tuple in the list */
>                 self->currTuple = -1;
>                 SC_set_current_col(self, -1);
>