Index: driver/execute.c =================================================================== --- driver/execute.c (revision 805) +++ driver/execute.c (working copy) @@ -293,8 +293,12 @@ We may see SQL_COLUMN_IGNORE from bulk INSERT operations, where we may have been told to ignore a column in one particular row. So we try to insert DEFAULT, or NULL for really old servers. + In case there are less parameters than result columns we have to + insert NULL or DEFAULT. */ - else if ( *(param->actual_len) == SQL_COLUMN_IGNORE ) + else if (*(param->actual_len) == SQL_COLUMN_IGNORE || + (*(param->actual_len) == 0 && param->CType == 0 && + param->buffer == NULL)) { if (is_minimum_version(dbc->mysql.server_version, "4.0.3", 5)) return add_to_buffer(net,to,"DEFAULT",7); Index: test/my_result.c =================================================================== --- test/my_result.c (revision 805) +++ test/my_result.c (working copy) @@ -1854,6 +1854,37 @@ } +DECLARE_TEST(t_bug31246) +{ + SQLSMALLINT ncol; + SQLCHAR buf[50]= "Some Text"; + SQLRETURN rc; + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug31246"); + ok_sql(hstmt, "CREATE TABLE t_bug31246 (" + "field1 VARCHAR(50) NOT NULL, " + "field2 int DEFAULT NULL, " + "field3 VARCHAR(50) DEFAULT NULL)"); + + /* No need to insert any rows in the table, so do SELECT */ + ok_sql(hstmt, "SELECT * FROM t_bug31246"); + ok_stmt(hstmt, SQLNumResultCols(hstmt,&ncol)); + is_num(ncol, 3); + + /* Bind only one column instead of three ones */ + ok_stmt(hstmt, SQLBindCol(hstmt, 1, SQL_C_CHAR, buf, sizeof(buf), NULL)); + + /* Expect SQL_NO_DATA_FOUND result from the empty table */ + rc= SQLExtendedFetch(hstmt, SQL_FETCH_NEXT, 1, NULL, NULL); + is_num(rc, SQL_NO_DATA_FOUND); + + /* Here was the problem */ + ok_stmt(hstmt, SQLSetPos(hstmt, 1, SQL_ADD, SQL_LOCK_NO_CHANGE)); + ok_sql(hstmt, "DROP TABLE t_bug31246"); + return OK; +} + + BEGIN_TESTS ADD_TEST(my_resultset) ADD_TEST(t_convert_type) @@ -1878,6 +1909,7 @@ ADD_TEST(t_binary_collation) ADD_TODO(t_bug29239) ADD_TODO(t_bug30958) + ADD_TODO(t_bug31246) END_TESTS