1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +03:00

Fix for CONC-624:

- ER() macro now checks if the error code is known, if not it will return
  "Unknown or undefined error code" (instead of crashing)
- SET_CLIENT_STMT_ERROR now maps to stmt_set_error and accepts variadic
  arguments
This commit is contained in:
Georg Richter
2023-01-15 14:11:54 +01:00
parent b9e9758e93
commit bf82b2d8cb
7 changed files with 97 additions and 34 deletions

View File

@@ -805,7 +805,48 @@ static int test_compressed(MYSQL *unused __attribute__((unused)))
return OK;
}
static int test_conc624(MYSQL *mysql)
{
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
char errmsg[MYSQL_ERRMSG_SIZE];
SET_CLIENT_STMT_ERROR(stmt, 9000, SQLSTATE_UNKNOWN, 0);
snprintf(errmsg, MYSQL_ERRMSG_SIZE, ER_UNKNOWN_ERROR_CODE, 9000);
diag("stmt_error: %s", mysql_stmt_error(stmt));
FAIL_IF(strcmp(mysql_stmt_error(stmt), errmsg), "expected undefined error 9000");
SET_CLIENT_STMT_ERROR(stmt, 0, SQLSTATE_UNKNOWN, 0);
snprintf(errmsg, MYSQL_ERRMSG_SIZE, ER_UNKNOWN_ERROR_CODE, 0);
FAIL_IF(strcmp(mysql_stmt_error(stmt), errmsg), "expected undefined error 0");
SET_CLIENT_STMT_ERROR(stmt, 4999, SQLSTATE_UNKNOWN, 0);
snprintf(errmsg, MYSQL_ERRMSG_SIZE, ER_UNKNOWN_ERROR_CODE, 4999);
FAIL_IF(strcmp(mysql_stmt_error(stmt), errmsg), "expected undefined error 4999");
my_set_error(mysql, 4999, SQLSTATE_UNKNOWN, 0);
snprintf(errmsg, MYSQL_ERRMSG_SIZE, ER_UNKNOWN_ERROR_CODE, 4999);
FAIL_IF(strcmp(mysql_error(mysql), errmsg), "expected undefined error 4999");
my_set_error(mysql, 0, SQLSTATE_UNKNOWN, 0);
snprintf(errmsg, MYSQL_ERRMSG_SIZE, ER_UNKNOWN_ERROR_CODE, 0);
FAIL_IF(strcmp(mysql_error(mysql), errmsg), "expected undefined error 0");
my_set_error(mysql, 9000, SQLSTATE_UNKNOWN, 0);
snprintf(errmsg, MYSQL_ERRMSG_SIZE, ER_UNKNOWN_ERROR_CODE, 9000);
FAIL_IF(strcmp(mysql_error(mysql), errmsg), "expected undefined error 9000");
/* test if SET_CLIENT_STMT_ERROR works with variadic arguments */
SET_CLIENT_STMT_ERROR(stmt, CR_STMT_CLOSED, SQLSTATE_UNKNOWN, 0, "foobar");
snprintf(errmsg, MYSQL_ERRMSG_SIZE, ER(CR_STMT_CLOSED), "foobar");
FAIL_IF(strcmp(mysql_stmt_error(stmt), errmsg), "error when passing variadic arguments to prepared stmt error function");
mysql_stmt_close(stmt);
return OK;
}
struct my_tests_st my_tests[] = {
{"test_conc624", test_conc624, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc75", test_conc75, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc74", test_conc74, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc71", test_conc71, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},