Index: driver/results.c =================================================================== --- driver/results.c (revision 1041) +++ driver/results.c (working copy) @@ -341,6 +341,11 @@ *((ulonglong *)rgbValue)= (ulonglong)strtoull(value, NULL, 10); *pcbValue= sizeof(ulonglong); break; + + default: + return set_error(stmt,MYERR_07006, + "Restricted data type attribute violation",0); + break; } } @@ -1392,7 +1397,7 @@ if ( bind->rgbValue || bind->pcbValue ) { SQLLEN offset,pcb_offset; - SQLLEN pcbValue; + SQLLEN pcbValue= 0; if ( stmt->stmt_options.bind_type == SQL_BIND_BY_COLUMN ) { @@ -1429,7 +1434,7 @@ else res= SQL_ERROR; } - if (bind->pcbValue) + else if (bind->pcbValue) *(bind->pcbValue + (pcb_offset / sizeof(SQLLEN))) = pcbValue; } if ( lengths ) Index: test/my_types.c =================================================================== --- test/my_types.c (revision 1041) +++ test/my_types.c (working copy) @@ -721,6 +721,23 @@ } +/* + Bug #31220 - SQLFetch or SQLFetchScroll returns negative data length + when using SQL_C_WCHAR +*/ +DECLARE_TEST(t_bug31220) +{ + SQLLEN outlen= 999; + SQLWCHAR outbuf[5]; + ok_sql(hstmt, "select 1"); + ok_stmt(hstmt, SQLBindCol(hstmt, 1, SQL_C_WCHAR, outbuf, 5, &outlen)); + expect_stmt(hstmt, SQLFetch(hstmt), SQL_ERROR); + is(check_sqlstate(hstmt, "07006") == OK); + is_num(outlen, 999); + return OK; +} + + BEGIN_TESTS ADD_TEST(t_longlong1) ADD_TEST(t_numeric) @@ -736,6 +753,7 @@ ADD_TEST(float_scale) ADD_TEST(bit) ADD_TEST(t_bug32171) + ADD_TEST(t_bug31220) END_TESTS