Skip to content

Commit

Permalink
Fetching Multiple Result Set Crash - completion of ODBC-126 fix
Browse files Browse the repository at this point in the history
- If Accompanying result set's field size is bigger than last one, crash occurs.
- Looks like originated from fixing issue 'ODBC-92'
  • Loading branch information
HeeM authored and lawrinn committed May 16, 2018
1 parent 860c985 commit 7da0dbb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ma_result.c
Expand Up @@ -100,6 +100,9 @@ SQLRETURN MADB_StmtMoreResults(MADB_Stmt *Stmt)
}

MADB_StmtResetResultStructures(Stmt);
/* We can't have it in MADB_StmtResetResultStructures, as it breaks dyn_cursor functionality.
Thus we free-ing bind structs on move to new result only */
MADB_FREE(Stmt->result);

MADB_DescSetIrdMetadata(Stmt, mysql_fetch_fields(FetchMetadata(Stmt)), mysql_stmt_field_count(Stmt->stmt));

Expand Down
54 changes: 54 additions & 0 deletions test/multistatement.c
Expand Up @@ -314,6 +314,59 @@ ODBC_TEST(t_odbc126)
return OK;
}

ODBC_TEST(diff_column_binding)
{
char bindc1[64];
int bind1, bind2, bind3;
SQLBIGINT bindb1;
SQLRETURN rc, Expected= SQL_SUCCESS;
SQLLEN indicator = 0, indicator2 = 0, indicator3 = 0, indicator4 = 0;
SQLLEN indicatorc = SQL_NTS;


OK_SIMPLE_STMT(Stmt, "DROP TABLE IF EXISTS diff_column_binding");
OK_SIMPLE_STMT(Stmt, "DROP PROCEDURE IF EXISTS diff_column_binding_1");

OK_SIMPLE_STMT(Stmt, "CREATE TABLE diff_column_binding(col1 INT, col2 VARCHAR(64), col3 BIGINT unsigned)");
OK_SIMPLE_STMT(Stmt, "CREATE PROCEDURE diff_column_binding_1()\
BEGIN\
SELECT 1017, 1370;\
SELECT * FROM diff_column_binding;\
END");

OK_SIMPLE_STMT(Stmt, "INSERT INTO diff_column_binding VALUES(1370, \"abcd\", 12345), (1417, \"abcdef\", 2390), (1475, \"@1475\", 0)");
OK_SIMPLE_STMT(Stmt, "CALL diff_column_binding_1");

// bind first result set
SQLBindCol(Stmt, 1, SQL_C_LONG, &bind1, sizeof(int), &indicator);
SQLBindCol(Stmt, 2, SQL_C_LONG, &bind2, sizeof(int), &indicator2);
SQLFetch(Stmt);
is_num(bind1, 1017);
is_num(bind2, 1370);

SQLMoreResults(Stmt);

// bind second result set
SQLBindCol(Stmt, 1, SQL_C_LONG, &bind3, sizeof(int), &indicator3);
SQLBindCol(Stmt, 2, SQL_C_CHAR, bindc1, sizeof(bindc1), &indicatorc);
SQLBindCol(Stmt, 3, SQL_C_SBIGINT, &bindb1, sizeof(SQLBIGINT), &indicator4);
SQLFetch(Stmt);
is_num(bind3, 1370);
is_num(strcmp(bindc1, "abcd"), 0);
is_num(bindb1, 12345);
SQLFetch(Stmt);
is_num(bind3, 1417);
is_num(strcmp(bindc1, "abcdef"), 0);
is_num(bindb1, 2390);
SQLFetch(Stmt);

CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

OK_SIMPLE_STMT(Stmt, "DROP TABLE diff_column_binding");
OK_SIMPLE_STMT(Stmt, "DROP PROCEDURE diff_column_binding_1");

return OK;
}

MA_ODBC_TESTS my_tests[]=
{
Expand All @@ -325,6 +378,7 @@ MA_ODBC_TESTS my_tests[]=
{t_odbc74, "t_odbc74and_odbc97"},
{t_odbc95, "t_odbc95"},
{t_odbc126, "t_odbc126"},
{diff_column_binding, "diff_column_binding"},
{NULL, NULL}
};

Expand Down

0 comments on commit 7da0dbb

Please sign in to comment.