Index: driver/utility.c =================================================================== --- driver/utility.c (revision 1026) +++ driver/utility.c (working copy) @@ -637,8 +637,9 @@ @param[in] stmt Pointer to statement @param[out] result Buffer for result - @param[in] avail_bytes Size of result buffer (in characters) - @param[out] used_len Pointer to buffer for storing amount of buffer used + @param[in] result_len Size of result buffer (in characters) + @param[out] avail_bytes Pointer to buffer for storing amount of data + available before this call @param[in] field Field being stored @param[in] src Source data for result @param[in] src_bytes Length of source data (in bytes) @@ -702,7 +703,6 @@ stmt->getdata.latest_bytes= 0; } - while (src < src_end) { /* Find the conversion functions. */ @@ -786,19 +786,14 @@ continue; } + if (result) + stmt->getdata.source+= cnvres; + if (result && result == result_end) { - if (stmt->getdata.dst_bytes != (ulong)~0L) - { - stmt->getdata.source+= cnvres; - break; - } *result= 0; result= NULL; } - - if (result) - stmt->getdata.source+= cnvres; } else if (stmt->getdata.latest_bytes == MY_CS_ILUNI && wc != '?') { Index: test/my_result.c =================================================================== --- test/my_result.c (revision 1026) +++ test/my_result.c (working copy) @@ -2182,6 +2182,52 @@ } +/* + Bug #34429 - SQLGetData gives incorrect data +*/ +DECLARE_TEST(t_bug34429) +{ + SQLWCHAR buf[32]; + SQLLEN reslen; + + ok_sql(hstmt, "drop table if exists t_bug34429"); + ok_sql(hstmt, "create table t_bug34429 (x varchar(200))"); + ok_sql(hstmt, "insert into t_bug34429 values " + "(concat(repeat('x',32),repeat('y',32),repeat('z',16)))"); + ok_sql(hstmt, "select x from t_bug34429"); + + ok_stmt(hstmt, SQLFetch(hstmt)); + + /* first chunk */ + expect_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_WCHAR, buf, sizeof(buf), + &reslen), SQL_SUCCESS_WITH_INFO); + printMessage("Chunk 1, len=%d, data=%ls", reslen, buf); + is_num(reslen, 80 * sizeof(SQLWCHAR)); + is(!memcmp(buf, W(L"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"), + 32 * sizeof(SQLWCHAR))); + + /* second chunk */ + expect_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_WCHAR, buf, sizeof(buf), + &reslen), SQL_SUCCESS_WITH_INFO); + printMessage("Chunk 2, len=%d, data=%ls", reslen, buf); + is_num(reslen, 49 * sizeof(SQLWCHAR)); + is(!memcmp(buf, W(L"xyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"), + 32 * sizeof(SQLWCHAR))); + + /* third chunk */ + ok_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_WCHAR, buf, sizeof(buf), &reslen)); + printMessage("Chunk 3, len=%d, data=%ls", reslen, buf); + is_num(reslen, 18 * sizeof(SQLWCHAR)); + is(!memcmp(buf, W(L"yyzzzzzzzzzzzzzzzz"), 18 * sizeof(SQLWCHAR))); + + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + + ok_sql(hstmt, "drop table if exists t_bug34429"); + + return OK; +} + + BEGIN_TESTS ADD_TEST(my_resultset) ADD_TEST(t_convert_type) @@ -2213,6 +2259,7 @@ ADD_TEST(t_bug13776_auto) ADD_TEST(t_bug28617) ADD_TEST(t_bug32684) + ADD_TEST(t_bug34429) END_TESTS