=== modified file 'driver/execute.c' --- driver/execute.c 2009-10-07 20:43:23 +0000 +++ driver/execute.c 2009-11-13 07:06:26 +0000 @@ -287,7 +287,13 @@ if (!octet_length_ptr && aprec->octet_length > 0 && aprec->octet_length != SQL_SETPARAM_VALUE_MAX) - length= myodbc_min(length, aprec->octet_length); + { + /* 0 bytes should not be considered as string terminators */ + if(aprec->concise_type == SQL_C_BINARY) + length= aprec->octet_length; + else + length= myodbc_min(length, aprec->octet_length); + } } else { === modified file 'test/my_catalog.c' --- test/my_catalog.c 2008-11-21 20:57:00 +0000 +++ test/my_catalog.c 2009-11-10 06:24:00 +0000 @@ -1437,6 +1437,40 @@ } === modified file 'test/my_result.c' --- test/my_result.c 2009-10-19 20:13:39 +0000 +++ test/my_result.c 2009-11-13 09:45:03 +0000 @@ -2493,6 +2493,54 @@ } +/* + Bug 48699 - c/ODBC cuts BINARY parameter after encountering first 00 + */ +DECLARE_TEST(t_bug48699) +{ + #define ROWS_TO_INSERT 3 + typedef struct DataBinding + { + SQLCHAR bData[5]; + + } DATA_BINDING; + + SQLCHAR buff[50]; + DATA_BINDING dataBinding[ROWS_TO_INSERT]; + SQLUSMALLINT paramStatusArray[ROWS_TO_INSERT]; + SQLULEN paramsProcessed; + + ok_stmt(hstmt, SQLExecDirect(hstmt, "DROP TABLE IF EXISTS bug48699", SQL_NTS)); + ok_stmt(hstmt, SQLExecDirect(hstmt, "CREATE TABLE bug48699 (id int primary key auto_increment,"\ + "bData binary(5) NULL)", SQL_NTS)); + + ok_stmt(hstmt, SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_BIND_TYPE, sizeof(DATA_BINDING), 0)); + ok_stmt(hstmt, SQLSetStmtAttr(hstmt, SQL_ATTR_PARAMSET_SIZE, ROWS_TO_INSERT, 0)); + ok_stmt(hstmt, SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_STATUS_PTR, paramStatusArray, 0)); + ok_stmt(hstmt, SQLSetStmtAttr(hstmt, SQL_ATTR_PARAMS_PROCESSED_PTR, ¶msProcessed, 0)); + + ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_BINARY, + sizeof(DATA_BINDING), 0, dataBinding[0].bData, 5, 0)); + + memcpy(dataBinding[0].bData, "\x01\x80\x00\x80\x00", 5); + memcpy(dataBinding[1].bData, "\x02\x80\x00\x80\x00", 5); + memcpy(dataBinding[2].bData, "\x03\x80\x00\x80\x00", 5); + + ok_stmt(hstmt, SQLExecDirect(hstmt, "INSERT INTO bug48699 (bData) " \ + "VALUES (?)", SQL_NTS)); + + ok_stmt(hstmt, SQLExecDirect(hstmt, "SELECT hex(bData) FROM bug48699 WHERE id=1;", SQL_NTS)); + ok_stmt(hstmt, SQLFetch(hstmt)); + is_str(my_fetch_str(hstmt, buff, 1), "0180008000", 10); + + /* Clean-up */ + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + ok_stmt(hstmt, SQLExecDirect(hstmt, "DROP TABLE IF EXISTS bug48699", SQL_NTS)); + + return OK; +} + + BEGIN_TESTS ADD_TEST(my_resultset) ADD_TEST(t_convert_type) @@ -2532,6 +2580,7 @@ ADD_TEST(t_bug36069) ADD_TEST(t_bug41942) ADD_TEST(t_bug39644) + ADD_TEST(t_bug48699) END_TESTS