1) Corrent the handling of bookmark in SQLBulkOperations.
authorHiroshi Inoue <inoue@tpf.co.jp>
Tue, 27 May 2003 05:20:09 +0000 (05:20 +0000)
committerHiroshi Inoue <inoue@tpf.co.jp>
Tue, 27 May 2003 05:20:09 +0000 (05:20 +0000)
2) Correct the calculation of a global index in SC_pos_add.
3) Cleanup global/rowset/resultset index handling a little.

bind.c
options.c
pgapi30.c
results.c
statement.c
statement.h
version.h

diff --git a/bind.c b/bind.c
index 77838fd08fb4557e961e5a3a40157a62237fe784..3fd8925178633bb01cdfc859ce30f28e3e3f6d22 100644 (file)
--- 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:
index c540fed9f5218fc0f2f6ce21814d82b3fec78bb0..d26aadbc2bd5629da88518ceda528adef3fdc2c6 100644 (file)
--- 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 */
index 07d08cc2a3e1b625225d4e2de3b55d49b849004a..7ff2ce8da22a43728f6dd1d54603aafa1e3026c4 100644 (file)
--- 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++;
index d2fea06519b3bc3bad0f14877377ce392c4445f3..a5f97869664a60cd1f64957992b443bfb345aac6 100644 (file)
--- 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);
        }
    }
index 6c4198e2b1bba75cb36c1a3e056322b7c22412e5..23d097f4c040d973c2f9614e5e97fa34dd393a7c 100644 (file)
@@ -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);
            }
 
index 85bf16e405d4e68fd10e922e7633a87649965f28..d977ea7b9b1369dfcf4a00f7d859e79bf3ef0acb 100644 (file)
@@ -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
index d3549679eed1b561121448f1160bde8a215c2544..68ddd40ade4de00cbbaa466bbdbedea3c6b79f62 100644 (file)
--- 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