Skip to content

Commit 46a58c7

Browse files
author
Bogdan Degtyariov
committed
Connector/ODBC does not send correct error message when 2006 error occurs (Bug #25671389)
1 parent a83a757 commit 46a58c7

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
and not connection (Bug# 17259397/69554)
1111
* SQLTABLES patch (Bug 13914518) has to be extended for NO_I_S case
1212
(Bug# 14005343)
13+
* Connector/ODBC does not send correct error message when 2006 error occurs
14+
(Bug #25671389)
1315

1416
Built using MySQL 5.7.
1517

driver/execute.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ SQLRETURN do_query(STMT *stmt,char *query, SQLULEN query_length)
4949
if(!SQL_SUCCEEDED(set_sql_select_limit(stmt->dbc,
5050
stmt->stmt_options.max_rows, TRUE)))
5151
{
52+
/* The error is set for DBC, copy it into STMT */
53+
set_stmt_error(stmt, stmt->dbc->error.sqlstate,
54+
stmt->dbc->error.message,
55+
stmt->dbc->error.native_error);
56+
5257
/* if setting sql_select_limit fails, the query will probably fail anyway too */
5358
goto skip_unlock_exit;
5459
}

test/my_error.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,50 @@ DECLARE_TEST(t_bug11750296)
769769
}
770770

771771

772+
DECLARE_TEST(t_bug25671389)
773+
{
774+
DECLARE_BASIC_HANDLES(henv1, hdbc1, hstmt1);
775+
776+
SQLINTEGER connection_id;
777+
SQLCHAR buf[255];
778+
SQLHSTMT hstmt2;
779+
780+
SQLRETURN rc = SQL_ERROR;
781+
SQLCHAR sqlState[6] = { '\0' };
782+
SQLCHAR eMsg[SQL_MAX_MESSAGE_LENGTH] = { '\0' };
783+
SQLINTEGER nError = 0;
784+
SQLSMALLINT msgLen = 0;
785+
786+
is(OK == alloc_basic_handles(&henv1, &hdbc1, &hstmt1));
787+
/* The bug is repeatable when limit is set and two STMTs exist */
788+
ok_con(hdbc1, SQLAllocHandle(SQL_HANDLE_STMT, hdbc1, &hstmt2));
789+
ok_stmt(hstmt2, SQLSetStmtAttr(hstmt2, SQL_ATTR_MAX_ROWS, (SQLPOINTER)100, 0));
790+
791+
ok_sql(hstmt1, "SELECT connection_id()");
792+
ok_stmt(hstmt1, SQLFetch(hstmt1));
793+
connection_id = my_fetch_int(hstmt1, 1);
794+
ok_stmt(hstmt1, SQLFreeStmt(hstmt1, SQL_CLOSE));
795+
796+
/* From another connection, kill the connection created above */
797+
sprintf(buf, "KILL %d", connection_id);
798+
ok_stmt(hstmt, SQLExecDirect(hstmt, (SQLCHAR *)buf, SQL_NTS));
799+
800+
/* Now check that the connection killed returns the right SQLSTATE */
801+
expect_sql(hstmt2, "SELECT connection_id()", SQL_ERROR);
802+
803+
rc = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt2, 1, sqlState, &nError, eMsg, sizeof(eMsg), &msgLen);
804+
/* Check that the error has been properly reported */
805+
is(rc == SQL_SUCCESS);
806+
is(nError > 0);
807+
is(strlen(sqlState) > 0);
808+
is(strlen(eMsg) > 0);
809+
is(msgLen > 0);
810+
811+
free_basic_handles(&henv1, &hdbc1, &hstmt1);
812+
return OK;
813+
}
814+
815+
772816
BEGIN_TESTS
773817
#ifndef NO_DRIVERMANAGER
774818
#ifndef USE_IODBC
@@ -785,6 +829,7 @@ BEGIN_TESTS
785829
ADD_TEST(t_warning)
786830
ADD_TEST(t_bug3456)
787831
ADD_TEST(t_bug16224)
832+
ADD_TEST(t_bug25671389)
788833
#ifndef USE_IODBC
789834
ADD_TEST(bind_invalidcol)
790835
ADD_TEST(t_handle_err)

0 commit comments

Comments
 (0)