Bug #72506 | SQLNumResultCols causes unexpected execution of statement in stored procedure | ||
---|---|---|---|
Submitted: | 1 May 2014 20:45 | Modified: | 7 Aug 2024 5:15 |
Reporter: | Robert Conde | Email Updates: | |
Status: | Can't repeat | Impact on me: | |
Category: | Connector / ODBC | Severity: | S2 (Serious) |
Version: | MySQL ODBC 5.3 ANSI Driver 5.02.03.00 | OS: | Windows (7 64-Bit) |
Assigned to: | Bogdan Degtyariov | CPU Architecture: | Any |
Tags: | ODBC, SQLDescribeCol, SQLNumResultCols |
[1 May 2014 20:45]
Robert Conde
[5 May 2014 9:52]
Bogdan Degtyariov
Hi Robert, Unfortunately, the behavior you expect from MySQL Connector/ODBC is not supported by MySQL Server. In order to get the insert to rollback you have to start the transaction and then roll it back. The driver will not do that for you because switching autocommit on and off without you knowing it is not desirable. Also, MySQL does not support the nested transactions, so rolling back the transaction with the insert implicitly done from SQLNumResultCols() would roll back the bigger transaction if it was ever started. I do not think we can help it in any way. Thus, marking the bug report as "Unsupported".
[5 May 2014 15:04]
Robert Conde
What you said makes some sense...however if you directly call the insert (rather than within a procedure) it works as expected. I don't think this behavior is consistent with your explanation. In other words: bool insertInProc = true; if(insertInProc) //doesn't work as expected { if(!executeCommand(hConnection,hStatement,"DROP PROCEDURE BUG_TEST_PROC")) { //accept an error here because the table might not exist } if ( !executeCommand ( hConnection, hStatement, "CREATE PROCEDURE BUG_TEST_PROC()\n" "BEGIN\n" " INSERT INTO BUG_TEST VALUES (5);\n" "END\n" ) ) { return -1; } if(!executeCommand(hConnection,hStatement,"CALL BUG_TEST_PROC()")) { return -1; } } else //works as expected { if(!executeCommand(hConnection,hStatement,"INSERT INTO BUG_TEST VALUES (5)")) { return -1; } }
[6 May 2014 9:23]
Bogdan Degtyariov
Robert, sorry, I misunderstood the problem at the beginning. You do not want the insert to be rolled back as I initially thought. Debugging showed me that the actual bug is in Connector/ODBC, which is calling the stored procedure twice. Setting the status to verified.
[7 Aug 2024 5:15]
Bogdan Degtyariov
Posted by developer: The issue is no longer repeatable after the code in SQLNumResultCols() was reworked in the version 8.0. Test case: DECLARE_TEST(t_bug18709928_num_cols) { try{ odbc::table tab(hstmt, "tab18709928", "col1 INT"); odbc::procedure proc(hstmt, "proc18709928", "()" "BEGIN " " INSERT INTO tab18709928 VALUES (5); " "END"); odbc::stmt_prepare(hstmt, "CALL proc18709928"); odbc::stmt_execute(hstmt); is_num(0, odbc::num_result_cols(hstmt)); is_num(1, odbc::num_result_rows(hstmt)); odbc::stmt_close(hstmt); odbc::sql(hstmt, "SELECT * FROM tab18709928"); is_num(1, odbc::num_result_cols(hstmt)); is_num(1, odbc::num_result_rows(hstmt)); while(SQLFetch(hstmt) == SQL_SUCCESS) {} odbc::stmt_close(hstmt); } ENDCATCH; }