Correct the detection of eof in useDeclare/fetch mode. This change fixes the bug...
authorHiroshi Inoue <h-inoue@dream.email.ne.jp>
Thu, 18 Feb 2016 02:51:04 +0000 (11:51 +0900)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Wed, 2 Mar 2016 13:12:36 +0000 (22:12 +0900)
qresult.c

index 98a9972a39d472dea974bf5b591a4702e629ec38..a09b2da2df2be0d190b8c8e87559ff66c0e2d1aa 100644 (file)
--- 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 */