From ec0d2f880e9d2440d25283525417b3d0e4a01c8d Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Fri, 11 Nov 2011 12:11:30 +0000 Subject: [PATCH] Adjust the operations after closing eof-detected cursors. --- results.c | 13 +++++++------ statement.c | 22 ++++++++++++++++------ version.h | 2 +- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/results.c b/results.c index 14c2cb2..777c2c8 100644 --- a/results.c +++ b/results.c @@ -81,7 +81,7 @@ inolog("returning RowCount=%d\n", *pcrow); } else if (QR_NumResultCols(res) > 0) { - *pcrow = SC_is_fetchcursor(stmt) ? -1 : QR_get_num_total_tuples(res) - res->dl_count; + *pcrow = QR_get_cursor(res) ? -1 : QR_get_num_total_tuples(res) - res->dl_count; mylog("RowCount=%d\n", *pcrow); return SQL_SUCCESS; } @@ -1417,7 +1417,7 @@ PGAPI_ExtendedFetch( ConnInfo *ci; SQLLEN currp; UWORD pstatus; - BOOL currp_is_valid, reached_eof; + BOOL currp_is_valid, reached_eof, useCursor; mylog("%s: stmt=%p rowsetSize=%d\n", func, stmt, rowsetSize); @@ -1487,9 +1487,10 @@ PGAPI_ExtendedFetch( if (pcrow) *pcrow = 0; + useCursor = (SC_is_fetchcursor(stmt) && NULL != QR_get_cursor(res)); num_tuples = QR_get_num_total_tuples(res); reached_eof = QR_once_reached_eof(res) && QR_get_cursor(res); - if (SC_is_fetchcursor(stmt) && !reached_eof) + if (useCursor && !reached_eof) num_tuples = INT_MAX; inolog("num_tuples=%d\n", num_tuples); @@ -1713,7 +1714,7 @@ inolog("num_tuples=%d\n", num_tuples); */ if (!should_set_rowset_start) rowset_start = SC_get_rowset_start(stmt); - if (SC_is_fetchcursor(stmt)) + if (useCursor) { if (reached_eof && rowset_start >= num_tuples) @@ -1753,7 +1754,7 @@ inolog("num_tuples=%d\n", num_tuples); /* currTuple is always 1 row prior to the rowset start */ stmt->currTuple = RowIdx2GIdx(-1, stmt); - if (SC_is_fetchcursor(stmt) || + if (useCursor || SQL_CURSOR_KEYSET_DRIVEN == stmt->options.cursor_type) { move_cursor_position_if_needed(stmt, res); @@ -1885,7 +1886,7 @@ inolog("just skipping deleted row %d\n", currp); stmt->currTuple = RowIdx2GIdx(0, stmt); /* For declare/fetch, need to reset cursor to beginning of rowset */ - if (SC_is_fetchcursor(stmt)) + if (useCursor) QR_set_position(res, 0); /* Set the number of rows retrieved */ diff --git a/statement.c b/statement.c index c1d04a9..715cde2 100644 --- a/statement.c +++ b/statement.c @@ -1564,6 +1564,7 @@ SC_fetch(StatementClass *self) char *value; ColumnInfoClass *coli; BindInfoClass *bookmark; + BOOL useCursor; /* TupleField *tupleField; */ @@ -1575,7 +1576,8 @@ inolog("%s statement=%p res=%x ommitted=0\n", func, self, res); mylog("fetch_cursor=%d, %p->total_read=%d\n", SC_is_fetchcursor(self), res, res->num_total_read); - if (!SC_is_fetchcursor(self)) + useCursor = (SC_is_fetchcursor(self) && (NULL != QR_get_cursor(res))); + if (!useCursor) { if (self->currTuple >= (Int4) QR_get_num_total_tuples(res) - 1 || (self->options.maxRows > 0 && self->currTuple == self->options.maxRows - 1)) @@ -1716,7 +1718,7 @@ inolog("%s: stmt=%p ommitted++\n", func, self); mylog("type = %d, atttypmod = %d\n", type, atttypmod); - if (SC_is_fetchcursor(self)) + if (useCursor) value = QR_get_value_backend(res, lf); else { @@ -1794,6 +1796,7 @@ SC_execute(StatementClass *self) BOOL is_in_trans, issue_begin, has_out_para; BOOL use_extended_protocol; int func_cs_count = 0, i; + BOOL useCursor; conn = SC_get_conn(self); ci = &(conn->connInfo); @@ -1818,6 +1821,13 @@ SC_execute(StatementClass *self) goto cleanup; } is_in_trans = CC_is_in_trans(conn); + if (useCursor = SC_is_fetchcursor(self)) + { + QResultClass *curres = SC_get_Curres(self); + + if (NULL != curres) + useCursor = (NULL != QR_get_cursor(curres)); + } /* issue BEGIN ? */ issue_begin = TRUE; if (self->internal) @@ -1833,7 +1843,7 @@ SC_execute(StatementClass *self) } } else if (CC_does_autocommit(conn) && - (!SC_is_fetchcursor(self) + (!useCursor /* || SC_is_with_hold(self) thiw would lose the performance */ )) issue_begin = FALSE; @@ -1942,7 +1952,7 @@ inolog("get_Result=%p %p %d\n", res, SC_get_Result(self), self->curr_param_resul mylog(" Sending SELECT statement on stmt=%p, cursor_name='%s' qflag=%d,%d\n", self, SC_cursor_name(self), qflag, self->options.scroll_concurrency); /* send the declare/select */ - if (SC_is_fetchcursor(self)) + if (useCursor) { qi.result_in = NULL; qi.cursor = SC_cursor_name(self); @@ -1954,7 +1964,7 @@ inolog("get_Result=%p %p %d\n", res, SC_get_Result(self), self->curr_param_resul qflag |= IGNORE_ROUND_TRIP; } res = CC_send_query_append(conn, self->stmt_with_params, qryi, qflag, SC_get_ancestor(self), appendq); - if (SC_is_fetchcursor(self) && QR_command_maybe_successful(res)) + if (useCursor && QR_command_maybe_successful(res)) { if (appendq) { @@ -2079,7 +2089,7 @@ inolog("!!%p->SC_is_concat_pre=%x res=%p\n", self, self->miscinfo, res); */ if (SQL_CURSOR_KEYSET_DRIVEN == self->options.cursor_type && SQL_CONCUR_READ_ONLY != self->options.scroll_concurrency && - !SC_is_fetchcursor(self)) + !useCursor) { if (tres = res->next, tres) { diff --git a/version.h b/version.h index fd4791d..ac2030d 100644 --- a/version.h +++ b/version.h @@ -12,6 +12,6 @@ #define POSTGRESDRIVERVERSION "09.00.0311" #define POSTGRES_RESOURCE_VERSION "09.00.0311\0" #define PG_DRVFILE_VERSION 9,0,03,11 -#define PG_BUILD_VERSION "201111100001" +#define PG_BUILD_VERSION "201111110001" #endif -- 2.39.5