From 69a9d18f927b799c329f9934f965c1c32ff02d40 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Fri, 4 Nov 2005 15:37:55 +0000 Subject: [PATCH] 1) QR_get_fields() gets called when SC_fetch() is entered. However, the QR 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 | 1 + statement.c | 36 ++++++++++++++++++------------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/results.c b/results.c index b462d2d..3afc1c6 100644 --- 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) { diff --git a/statement.c b/statement.c index 9d04fa7..df65dd2 100644 --- a/statement.c +++ b/statement.c @@ -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); - - /* Cleanup the QR. We need to kill off the cursor first, or this will crash */ - if (self->result->cursor) - { - free(self->result->cursor); - self->result->cursor = NULL; - } - - if (self->result) - { - QR_Destructor(self->result); - self->result = NULL; - } - + 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 */ - + 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) -- 2.39.5