Skip to content

Commit

Permalink
Fix for CONC-633:
Browse files Browse the repository at this point in the history
If prepare step failed in mariadb_stmt_execute_direct now both
mysql_stmt_error and mysql_error return the error message from
prepare step instead of error message of execute.
  • Loading branch information
9EOR9 committed Feb 8, 2023
1 parent 75439c0 commit 669726a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
9 changes: 8 additions & 1 deletion libmariadb/mariadb_stmt.c
Expand Up @@ -2569,7 +2569,14 @@ int STDCALL mariadb_stmt_execute_direct(MYSQL_STMT *stmt,
stmt->mysql->methods->db_stmt_flush_unbuffered(stmt);
} while(mysql_stmt_more_results(stmt));
}
stmt->state= MYSQL_STMT_INITTED;

/* CONC-633: If prepare returned an error, we ignore error from execute */
if (mysql_stmt_errno(stmt))
{
my_set_error(mysql, mysql_stmt_errno(stmt), mysql_stmt_sqlstate(stmt),
mysql_stmt_error(stmt));
stmt->state= MYSQL_STMT_INITTED;
}
return 1;
}

Expand Down
76 changes: 76 additions & 0 deletions unittest/libmariadb/ps_bugs.c
Expand Up @@ -5507,7 +5507,83 @@ static int test_conc627(MYSQL *mysql)
return OK;
}

static int test_conc633(MYSQL *mysql)
{
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
MYSQL *my= mysql_init(NULL);
int ret= FAIL;
int rc;

if (!mariadb_stmt_execute_direct(stmt, SL("SÄLECT 1")))
{
diag("Syntax error expected");
goto end;
}

if (mysql_errno(mysql) != mysql_stmt_errno(stmt))
{
diag("Different error codes. mysql_errno= %d, mysql_stmt_errno=%d",
mysql_errno(mysql), mysql_stmt_errno(stmt));
goto end;
}

if ((long)stmt->stmt_id != -1)
{
diag("Error: expected stmt_id=-1");
goto end;
}

if (!(my= test_connect(NULL)))
{
diag("Can establish connection (%s)", mysql_error(my));
goto end;
}

rc= mysql_query(my, "CREATE OR REPLACE TABLE conc633 (a int)");
check_mysql_rc(rc, mysql);

rc= mysql_query(mysql, "SET @@lock_wait_timeout=3");

rc= mysql_query(my, "LOCK TABLES conc633 WRITE");
check_mysql_rc(rc, mysql);

rc= mysql_query(mysql, "SET @@lock_wait_timeout=3");
check_mysql_rc(rc, mysql);

if (!mariadb_stmt_execute_direct(stmt, SL("INSERT INTO conc633 VALUES (1)")))
{
diag("lock wait timeout error expected");
goto end;
}

if (stmt->state != MYSQL_STMT_PREPARED)
{
diag("Error: stmt hasn't prepared status");
goto end;
}

if ((long)stmt->stmt_id == -1)
{
diag("Error: no stmt_id assigned");
goto end;
}

rc= mysql_query(my, "UNLOCK TABLES");
check_mysql_rc(rc, mysql);
rc= mysql_query(my, "DROP TABLE conc633");
check_mysql_rc(rc, mysql);

ret= OK;

end:
if (my)
mysql_close(my);
mysql_stmt_close(stmt);
return ret;
}

struct my_tests_st my_tests[] = {
{"test_conc633", test_conc633, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc627", test_conc627, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_mdev19838", test_mdev19838, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc566", test_conc566, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
Expand Down

0 comments on commit 669726a

Please sign in to comment.