Index: ChangeLog =================================================================== --- ChangeLog (revision 830) +++ ChangeLog (working copy) @@ -1,6 +1,8 @@ 3.51.22 Functionality added or changed: + * The wrong result was returned by SQLGetData() when the data was an + empty string and a zero-sized buffer was specified. (Bug #30958) * Added FLAG_COLUMN_SIZE_S32 to limit the reported column size to a signed 32-bit integer. This option is automatically enabled for ADO applications, in order to work around a bug in ADO. (Bug #13776) Index: driver/utility.c =================================================================== --- driver/utility.c (revision 830) +++ driver/utility.c (working copy) @@ -255,7 +255,8 @@ !(((STMT FAR*)Handle)->dbc->flag & FLAG_PAD_SPACE) ) fill_length= src_length; } - if ( *offset == (ulong) ~0L ) + + if (arg_length && *offset == (ulong) ~0L) { /* This is first call. Even if data has zero size, we don't @@ -263,7 +264,7 @@ */ *offset= 0; } - else if ( *offset >= (ulong) fill_length ) + else if (*offset != (ulong) ~0L && *offset >= (ulong) fill_length) { /* If not the first call, and we have no data left, @@ -274,9 +275,12 @@ return SQL_NO_DATA_FOUND; } - src+= *offset; - src_length-= (long) *offset; - fill_length-= *offset; + if (*offset != (ulong) ~0L) + { + src+= *offset; + src_length-= (long) *offset; + fill_length-= *offset; + } length= min(fill_length, cbValueMax); (*offset)+= length; /* Fix for next call */ Index: test/my_result.c =================================================================== --- test/my_result.c (revision 830) +++ test/my_result.c (working copy) @@ -1783,8 +1783,8 @@ ok_stmt(hstmt, SQLFetch(hstmt)); /* - check first that we get truncation, with zero bytes - available in out buffer, outbuffer should be untouched + check first that we get truncation, with zero bytes + available in out buffer, outbuffer should be untouched */ outlen= 99; expect_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_CHAR, outbuf, outmax, @@ -1793,7 +1793,7 @@ is_num(outlen, 0); is(check_sqlstate(hstmt, "01004") == OK); - /* exact the same result, and not SQL_NO_DATA */ + /* expect the same result, and not SQL_NO_DATA */ outlen= 99; expect_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_CHAR, outbuf, outmax, &outlen), SQL_SUCCESS_WITH_INFO); @@ -2008,7 +2008,7 @@ ADD_TEST(bug6157) ADD_TEST(t_binary_collation) ADD_TODO(t_bug29239) - ADD_TODO(t_bug30958) + ADD_TEST(t_bug30958) ADD_TEST(t_bug31246) ADD_TEST(t_bug13776) ADD_TEST(t_bug13776_auto)