From 7268e9442cb48f124be87f5b8fa6ff5e3585b90e Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Tue, 27 May 2003 05:20:09 +0000 Subject: [PATCH] 1) Corrent the handling of bookmark in SQLBulkOperations. 2) Correct the calculation of a global index in SC_pos_add. 3) Cleanup global/rowset/resultset index handling a little. --- bind.c | 1 - options.c | 2 +- pgapi30.c | 26 ++++++++++++++++++++------ results.c | 28 +++++++++++++--------------- statement.c | 4 +--- statement.h | 11 +++++++++++ version.h | 6 +++--- 7 files changed, 49 insertions(+), 29 deletions(-) diff --git a/bind.c b/bind.c index 77838fd..3fd8925 100644 --- a/bind.c +++ b/bind.c @@ -177,7 +177,6 @@ PGAPI_BindCol( else { /* Make sure it is the bookmark data type */ - if (fCType == SQL_C_BOOKMARK) switch (fCType) { case SQL_C_BOOKMARK: diff --git a/options.c b/options.c index c540fed..d26aadb 100644 --- a/options.c +++ b/options.c @@ -661,7 +661,7 @@ PGAPI_GetStmtOption( return SQL_ERROR; } - ridx = stmt->currTuple - stmt->rowset_start + res->base; + ridx = GIdx2ResultIdx(stmt->currTuple, stmt, res); if (stmt->manual_result || !SC_is_fetchcursor(stmt)) { /* make sure we're positioned on a valid row */ diff --git a/pgapi30.c b/pgapi30.c index 07d08cc..7ff2ce8 100644 --- a/pgapi30.c +++ b/pgapi30.c @@ -1460,11 +1460,23 @@ PGAPI_GetStmtAttr(HSTMT StatementHandle, len = 4; *((HSTMT *) Value) = descHandleFromStatementHandle(StatementHandle, Attribute); break; - case SQL_ATTR_AUTO_IPD: /* 10001 */ - /* case SQL_ATTR_ROW_BIND_TYPE: ** == SQL_BIND_TYPE(ODBC2.0) */ case SQL_ATTR_CURSOR_SCROLLABLE: /* -1 */ + len = 4; + if (SQL_CURSOR_FORWARD_ONLY == stmt->options.cursor_type) + *((SQLUINTEGER *) Value) = SQL_NONSCROLLABLE; + else + *((SQLUINTEGER *) Value) = SQL_SCROLLABLE; + break; case SQL_ATTR_CURSOR_SENSITIVITY: /* -2 */ + len = 4; + if (SQL_CONCUR_READ_ONLY == stmt->options.scroll_concurrency) + *((SQLUINTEGER *) Value) = SQL_INSENSITIVE; + else + *((SQLUINTEGER *) Value) = SQL_UNSPECIFIED; + break; + case SQL_ATTR_AUTO_IPD: /* 10001 */ + /* case SQL_ATTR_ROW_BIND_TYPE: ** == SQL_BIND_TYPE(ODBC2.0) */ case SQL_ATTR_ENABLE_AUTO_IPD: /* 15 */ case SQL_ATTR_METADATA_ID: /* 10014 */ @@ -1704,7 +1716,8 @@ PGAPI_BulkOperations(HSTMT hstmt, SQLSMALLINT operation) StatementClass *stmt = (StatementClass *) hstmt; ARDFields *opts = SC_get_ARD(stmt); RETCODE ret; - UInt4 offset, bind_size = opts->bind_size, *bmark = NULL; + UInt4 offset, bind_size = opts->bind_size, *bmark = NULL, + global_idx; int i, processed; ConnectionClass *conn; BOOL auto_commit_needed = FALSE; @@ -1731,6 +1744,7 @@ PGAPI_BulkOperations(HSTMT hstmt, SQLSMALLINT operation) } for (i = 0, processed = 0; i < opts->rowset_size; i++) { + global_idx = *bmark - 1; /* Note opts->row_operation_ptr is ignored */ switch (operation) { @@ -1738,13 +1752,13 @@ PGAPI_BulkOperations(HSTMT hstmt, SQLSMALLINT operation) ret = SC_pos_add(stmt, (UWORD) i); break; case SQL_UPDATE_BY_BOOKMARK: - ret = SC_pos_update(stmt, (UWORD) i, *bmark); + ret = SC_pos_update(stmt, (UWORD) i, global_idx); break; case SQL_DELETE_BY_BOOKMARK: - ret = SC_pos_delete(stmt, (UWORD) i, *bmark); + ret = SC_pos_delete(stmt, (UWORD) i, global_idx); break; case SQL_FETCH_BY_BOOKMARK: - ret = SC_pos_refresh(stmt, (UWORD) i, *bmark); + ret = SC_pos_refresh(stmt, (UWORD) i, global_idx); break; } processed++; diff --git a/results.c b/results.c index d2fea06..a5f9786 100644 --- a/results.c +++ b/results.c @@ -875,9 +875,7 @@ inolog("Column 0 is type %d not of type SQL_C_BOOKMARK", fCType); value = QR_get_value_manual(res, stmt->currTuple, icol); else { - Int4 curt = res->base; - if (stmt->rowset_start >= 0) - curt += (stmt->currTuple - stmt->rowset_start); + Int4 curt = GIdx2ResultIdx(stmt->currTuple, stmt, res); value = QR_get_value_backend_row(res, curt, icol); } mylog(" value = '%s'\n", value); @@ -1434,7 +1432,7 @@ PGAPI_ExtendedFetch( } /* currTuple is always 1 row prior to the rowset */ - stmt->currTuple = stmt->rowset_start - 1; + stmt->currTuple = RowIdx2GIdx(-1, stmt); /* increment the base row in the tuple cache */ QR_set_rowset_size(res, opts->rowset_size); @@ -1504,13 +1502,13 @@ PGAPI_ExtendedFetch( /* Save the fetch count for SQLSetPos */ stmt->last_fetch_count = i; - stmt->last_fetch_count_include_ommitted = currp - stmt->rowset_start; + stmt->last_fetch_count_include_ommitted = GIdx2RowIdx(currp, stmt); /* Reset next binding row */ stmt->bind_row = 0; /* Move the cursor position to the first row in the result set. */ - stmt->currTuple = stmt->rowset_start; + stmt->currTuple = RowIdx2GIdx(0, stmt); /* For declare/fetch, need to reset cursor to beginning of rowset */ if (SC_is_fetchcursor(stmt) && !stmt->manual_result) @@ -1667,7 +1665,7 @@ static void UndoRollback(StatementClass *stmt, QResultClass *res) status = keyset[index].status; if (0 != (status & CURS_SELF_ADDING)) { - ridx = index - stmt->rowset_start + res->base; + ridx = GIdx2ResultIdx(index, stmt, res); if (ridx >=0 && ridx < res->num_backend_rows) { TupleField *tuple = res->backend_tuples + res->num_fields * ridx; @@ -1852,7 +1850,7 @@ SC_pos_reload(StatementClass *stmt, UDWORD global_ridx, UWORD *count, BOOL logCh SC_set_error(stmt, STMT_INVALID_OPTION_IDENTIFIER, "the statement is read-only"); return SQL_ERROR; } - res_ridx = global_ridx - stmt->rowset_start + res->base; + res_ridx = GIdx2ResultIdx(global_ridx, stmt, res); if (!(oid = getOid(res, global_ridx))) { SC_set_error(stmt, STMT_ROW_VERSION_CHANGED, "the row was already deleted ?"); @@ -1941,7 +1939,7 @@ SC_pos_reload_needed(StatementClass *stmt, UDWORD flag) SC_set_error(stmt, STMT_INVALID_OPTION_IDENTIFIER, "the statement is read-only"); return SQL_ERROR; } - limitrow = stmt->rowset_start + res->rowset_size; + limitrow = RowIdx2GIdx(res->rowset_size, stmt); if (limitrow > res->num_total_rows) limitrow = res->num_total_rows; if (create_from_scratch) @@ -1954,7 +1952,7 @@ SC_pos_reload_needed(StatementClass *stmt, UDWORD flag) if (res->backend_tuples[i].value) free(res->backend_tuples[i].value); } - brows = limitrow - stmt->rowset_start; + brows = GIdx2RowIdx(limitrow, stmt); if (brows > res->count_backend_allocated) { res->backend_tuples = realloc(res->backend_tuples, sizeof(TupleField) * res->num_fields * brows); @@ -1998,7 +1996,7 @@ SC_pos_reload_needed(StatementClass *stmt, UDWORD flag) { if (oid == getOid(res, k)) { - l = k - stmt->rowset_start + res->base; + l = GIdx2ResultIdx(k, stmt, res); tuple = res->backend_tuples + res->num_fields * l; tuplew = qres->backend_tuples + qres->num_fields * j; for (m = 0; m < res->num_fields; m++, tuple++, tuplew++) @@ -2118,7 +2116,7 @@ SC_pos_newload(StatementClass *stmt, UInt4 oid, BOOL tidRef) } KeySetSet(tuplen, qres->num_fields, res->keyset + res->num_total_rows); - if (res->num_total_rows == res->num_backend_rows - res->base + stmt->rowset_start) + if (res->num_total_rows == ResultIdx2GIdx(res->num_backend_rows, stmt, res)) { if (res->num_backend_rows >= res->count_backend_allocated) { @@ -2644,7 +2642,7 @@ SC_pos_add(StatementClass *stmt, PGAPI_FreeStmt(hstmt, SQL_DROP); if (SQL_SUCCESS == ret && res->keyset) { - int global_ridx = res->num_total_rows + stmt->rowset_start - res->base - 1; + int global_ridx = res->num_total_rows - 1; if (CC_is_in_trans(conn)) { @@ -2813,7 +2811,7 @@ PGAPI_SetPos( ridx = -1; for (i = nrow = 0, processed = 0; nrow <= end_row; i++) { - global_ridx = i + stmt->rowset_start; + global_ridx = RowIdx2GIdx(i, stmt); if (SQL_ADD != fOption) { if ((int) global_ridx >= res->num_total_rows) @@ -2869,7 +2867,7 @@ PGAPI_SetPos( { if (SQL_ADD != fOption && ridx >= 0) /* for SQLGetData */ { - stmt->currTuple = stmt->rowset_start + ridx; + stmt->currTuple = RowIdx2GIdx(ridx, stmt); QR_set_position(res, ridx); } } diff --git a/statement.c b/statement.c index 6c4198e..23d097f 100644 --- a/statement.c +++ b/statement.c @@ -958,9 +958,7 @@ SC_fetch(StatementClass *self) value = QR_get_value_backend(res, lf); else { - int curt = res->base; - if (self->rowset_start >= 0) - curt += (self->currTuple - self->rowset_start); + int curt = GIdx2ResultIdx(self->currTuple, self, res); value = QR_get_value_backend_row(res, curt, lf); } diff --git a/statement.h b/statement.h index 85bf16e..d977ea7 100644 --- a/statement.h +++ b/statement.h @@ -290,4 +290,15 @@ RETCODE SC_pos_delete(StatementClass *self, UWORD irow, UDWORD index); RETCODE SC_pos_refresh(StatementClass *self, UWORD irow, UDWORD index); RETCODE SC_pos_add(StatementClass *self, UWORD irow); +/* + * Macros to convert global index <-> relative index in resultset/rowset + */ +/* a global index to the relative index in a rowset */ +#define GIdx2RowIdx(gidx, stmt) (gidx - stmt->rowset_start) +/* a global index to the relative index in a resultset(not a rowset) */ +#define GIdx2ResultIdx(gidx, stmt, res) ((stmt->rowset_start < 0) ? res->base : gidx - stmt->rowset_start + res->base) +/* a relative index in a rowset to the global index */ +#define RowIdx2GIdx(ridx, stmt) (ridx + stmt->rowset_start) +/* a relative index in a resultset to the global index */ +#define ResultIdx2GIdx(ridx, stmt, res) (ridx - res->base + stmt->rowset_start) #endif diff --git a/version.h b/version.h index d354967..68ddd40 100644 --- a/version.h +++ b/version.h @@ -9,8 +9,8 @@ #ifndef __VERSION_H__ #define __VERSION_H__ -#define POSTGRESDRIVERVERSION "07.03.0103" -#define POSTGRES_RESOURCE_VERSION "07.03.0103\0" -#define PG_DRVFILE_VERSION 7,3,1,03 +#define POSTGRESDRIVERVERSION "07.03.0104" +#define POSTGRES_RESOURCE_VERSION "07.03.0104\0" +#define PG_DRVFILE_VERSION 7,3,1,04 #endif -- 2.39.5