Fri Jul 27 16:20:35 CDT 2007 Jess Balint * fix and test for bug#6741 diff -rN -u old-odbc3/driver/options.c new-odbc3/driver/options.c --- old-odbc3/driver/options.c 2007-07-27 16:24:29.000000000 -0500 +++ new-odbc3/driver/options.c 2007-07-27 16:24:29.000000000 -0500 @@ -233,9 +233,7 @@ break; case SQL_ATTR_ROW_BIND_OFFSET_PTR: - *((SQLINTEGER *) ValuePtr)= options->bind_offset ? - *(options->bind_offset): - 0; + *((SQLINTEGER *) ValuePtr)= options->bind_offset; break; case SQL_ATTR_ROW_OPERATION_PTR: /* need to support this ....*/ diff -rN -u old-odbc3/driver/results.c new-odbc3/driver/results.c --- old-odbc3/driver/results.c 2007-07-27 16:24:29.000000000 -0500 +++ new-odbc3/driver/results.c 2007-07-27 16:24:29.000000000 -0500 @@ -1374,6 +1374,7 @@ { ulong offset,pcb_offset; SQLLEN pcbValue; + if ( stmt->stmt_options.bind_type == SQL_BIND_BY_COLUMN ) { offset= bind->cbValueMax*i; @@ -1381,7 +1382,16 @@ } else pcb_offset= offset= stmt->stmt_options.bind_type*i; + + /* apply SQL_ATTR_ROW_BIND_OFFSET_PTR */ + if (stmt->stmt_options.bind_offset) + { + offset += *stmt->stmt_options.bind_offset; + pcb_offset += *stmt->stmt_options.bind_offset; + } + stmt->getdata_offset= (ulong) ~0L; + if ( (tmp_res= sql_get_data( stmt, bind->fCType, bind->field, diff -rN -u old-odbc3/test/my_cursor.c new-odbc3/test/my_cursor.c --- old-odbc3/test/my_cursor.c 2007-07-27 16:24:29.000000000 -0500 +++ new-odbc3/test/my_cursor.c 2007-07-27 16:24:29.000000000 -0500 @@ -2486,6 +2486,44 @@ } +DECLARE_TEST(bug6741) +{ + const int vals = 5; + int i; + SQLUINTEGER offset; + SQLINTEGER results[vals]; + + ok_sql(hstmt, "drop table if exists t_bug6741"); + ok_sql(hstmt, "create table t_bug6741 (x int)"); + + ok_sql(hstmt, "insert into t_bug6741 values (0),(1),(2),(3),(4)"); + ok_sql(hstmt, "select x from t_bug6741 order by x"); + + ok_stmt(hstmt, SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_BIND_OFFSET_PTR, + &offset, SQL_IS_UINTEGER)); + ok_stmt(hstmt, SQLBindCol(hstmt, 1, SQL_C_LONG, results, 0, NULL)); + + /* fetch all the data */ + for(i = 0; i < vals; ++i) + { + offset = i * sizeof(SQLINTEGER); + ok_stmt(hstmt, SQLFetch(hstmt)); + } + expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA_FOUND); + + /* verify it */ + for(i = 0; i < vals; ++i) + { + printf("Results[%d] = %d\n", i, results[i]); + is_num(results[i], i); + } + + ok_sql(hstmt, "drop table if exists t_bug6741"); + + return OK; +} + + BEGIN_TESTS ADD_TEST(my_positioned_cursor) ADD_TEST(my_setpos_cursor) @@ -2524,6 +2562,7 @@ ADD_TEST(tmysql_pcbvalue) ADD_TEST(t_bug28255) ADD_TEST(bug10563) + ADD_TEST(bug6741) END_TESTS