From 50d9958f1ab8e752d4e0f66b54f031e964db83e6 Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Thu, 18 Feb 2016 11:51:04 +0900 Subject: [PATCH] Correct the detection of eof in useDeclare/fetch mode. This change fixes the bug about fetching prior after scrolling next until eof reported by BenS. --- qresult.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/qresult.c b/qresult.c index 98a9972..a09b2da 100644 --- a/qresult.c +++ b/qresult.c @@ -591,6 +591,7 @@ QR_from_PGresult(QResultClass *self, StatementClass *stmt, ConnectionClass *conn char *new_field_name; Int2 dummy1, dummy2; int cidx; + BOOL reached_eof_now = FALSE; if (NULL != conn) /* First, get column information */ @@ -668,8 +669,15 @@ inolog("!![%d].PGType %u->%u\n", i, PIC_get_pgtype(ipdopts->parameters[i]), CI_g return FALSE; inolog("!!%p->cursTup=%d total_read=%d\n", self, self->cursTuple, self->num_total_read); + if (self->num_cached_rows < self->cache_size) + { + reached_eof_now = TRUE; + QR_set_reached_eof(self); + } if (!QR_once_reached_eof(self) && self->cursTuple >= (Int4) self->num_total_read) self->num_total_read = self->cursTuple + 1; + if (reached_eof_now && self->cursTuple < (Int4) self->num_total_read) + self->cursTuple++; if (NULL != conn) { @@ -1186,10 +1194,7 @@ inolog("clear obsolete %d tuples\n", num_backend_rows); self->tupleField = NULL; num_rows_in = self->num_cached_rows; - if (curr_eof) - reached_eof_now = curr_eof; - else - curr_eof = reached_eof_now = (QR_once_reached_eof(self) && self->cursTuple >= (Int4)self->num_total_read); + curr_eof = reached_eof_now = (QR_once_reached_eof(self) && self->cursTuple >= (Int4)self->num_total_read); inolog("reached_eof_now=%d\n", reached_eof_now); mylog("_%s: PGresult: fetch_total = %d & this_fetch = %d\n", func, self->num_total_read, self->num_cached_rows); @@ -1206,12 +1211,6 @@ inolog("reached_eof_now=%d\n", reached_eof_now); { mylog("%s: reached eof now\n", func); QR_set_reached_eof(self); - if (self->cursTuple >= (Int4) self->num_total_read) - { - self->num_total_read = self->cursTuple + 1; -inolog("mayumi setting total_read to %d\n", self->num_total_read); - } - self->cursTuple++; if (self->ad_count > 0 && cur_fetch < fetch_size) { /* We have to append the tuples(keys) info from the added tuples(keys) here */ -- 2.39.5