1) QR_get_fields() gets called when SC_fetch() is entered. However, the QR
authorDave Page <dpage@pgadmin.org>
Fri, 4 Nov 2005 15:37:55 +0000 (15:37 +0000)
committerDave Page <dpage@pgadmin.org>
Fri, 4 Nov 2005 15:37:55 +0000 (15:37 +0000)
cleanup will free the QResultClass object. And the pointer "coli" is no longer
valid when CI_get_oid() gets called further down.
I have fixed this by calling QR_get_fields() after the first if-statement.

2) This is basically the same "cache" bug: PGAPI_ExtendedFetch() caches the
stored QResultClass object when the function is entered. But after SC_fetch()
was called, the pointer is no longer valid.
I have fixed this by calling SC_get_Curres() again after the call to
SC_fetch().
[Rainer Bauer]

results.c
statement.c

index b462d2d8ac777d8a0bbe33d16538b61bc12e36cd..3afc1c63765f0ac665450e758de6afeaf80692ab 100644 (file)
--- a/results.c
+++ b/results.c
@@ -1482,6 +1482,7 @@ PGAPI_ExtendedFetch(
    {
        stmt->bind_row = i;     /* set the binding location */
        result = SC_fetch(stmt);
+       res = SC_get_Curres(stmt);
 #ifdef DRIVER_CURSOR_IMPLEMENT
        if (SQL_SUCCESS_WITH_INFO == result && 0 == stmt->last_fetch_count && res->keyset)
        {
index 9d04fa702370aab6506548c97deca977f837da72..df65dd2d744e4cd0503981ca4f5f8e40bd277ffd 100644 (file)
@@ -922,7 +922,6 @@ SC_fetch(StatementClass *self)
    ConnInfo   *ci = &(SC_get_conn(self)->connInfo);
 
    self->last_fetch_count = self->last_fetch_count_include_ommitted = 0;
-   coli = QR_get_fields(res);  /* the column info */
 
    /* Issue the fetch query here in case of declare fetch for subsequent rows */
    if (SC_is_fetchcursor(self) && ((self->currTuple % ci->drivers.fetch_max) >= QR_get_num_total_tuples(res) - 1))
@@ -930,28 +929,29 @@ SC_fetch(StatementClass *self)
        qi.result_in = NULL;
        qi.cursor = self->cursor_name;
        qi.row_size = ci->drivers.fetch_max;
-       sprintf(fetch, "fetch %d in %s",ci->drivers.fetch_max , self->cursor_name);\r
-\r
-        /* Cleanup the QR. We need to kill off the cursor first, or this will crash */\r
-        if (self->result->cursor)\r
-       {\r
-           free(self->result->cursor);\r
-           self->result->cursor = NULL;\r
-       }\r
-\r
-        if (self->result)\r
-        {\r
-            QR_Destructor(self->result);\r
-            self->result = NULL;\r
-        }\r
-\r
+       sprintf(fetch, "fetch %d in %s",ci->drivers.fetch_max ,self->cursor_name);
+
+        /* Cleanup the QR. We need to kill off the cursor first, or this willcrash */
+
+        if (self->result->cursor)
+        {
+            free(self->result->cursor);
+            self->result->cursor = NULL;
+        }
+
+        if (self->result)
+        {
+            QR_Destructor(self->result);
+            self->result = NULL;
+        }
+
         /* Finished cleanup */
-\r
+
         res = CC_send_query(self->hdbc, fetch, &qi, qflag);
-       
        SC_set_Result(self,res);
    }
 
+    coli = QR_get_fields(res); /* the column info */
    mylog("manual_result = %d, use_declarefetch = %d\n", self->manual_result, ci->drivers.use_declarefetch);
 
    if (self->manual_result)