From 639413cb210f25657909062e68a2a4769d8a4b20 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Tue, 23 Oct 2018 13:11:23 +0200 Subject: [PATCH] Implementation of CONC-349: Added new parameter STMT_ATTR_STATE to retrieve statement status via api function mysql_stmt_attr_get --- include/mariadb_stmt.h | 3 ++- libmariadb/mariadb_stmt.c | 3 +++ unittest/libmariadb/ps.c | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/include/mariadb_stmt.h b/include/mariadb_stmt.h index 8d676450..40063bc4 100644 --- a/include/mariadb_stmt.h +++ b/include/mariadb_stmt.h @@ -64,7 +64,8 @@ enum enum_stmt_attr_type STMT_ATTR_PREFETCH_ROWS, STMT_ATTR_PREBIND_PARAMS=200, STMT_ATTR_ARRAY_SIZE, - STMT_ATTR_ROW_SIZE + STMT_ATTR_ROW_SIZE, + STMT_ATTR_STATE }; enum enum_cursor_type diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c index f5ca3818..076ec53a 100644 --- a/libmariadb/mariadb_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -1028,6 +1028,9 @@ unsigned long long STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt) my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, void *value) { switch (attr_type) { + case STMT_ATTR_STATE: + *(enum mysql_stmt_state *)value= stmt->state; + break; case STMT_ATTR_UPDATE_MAX_LENGTH: *(my_bool *)value= stmt->update_max_length; break; diff --git a/unittest/libmariadb/ps.c b/unittest/libmariadb/ps.c index df2af5c3..8acc4489 100644 --- a/unittest/libmariadb/ps.c +++ b/unittest/libmariadb/ps.c @@ -5071,7 +5071,33 @@ static int test_prepare_error(MYSQL *mysql) return OK; } +static int test_conc349(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + enum mysql_stmt_state state; + + rc= mysql_stmt_attr_get(stmt, STMT_ATTR_STATE, &state); + FAIL_IF(state != MYSQL_STMT_INITTED, "expected status MYSQL_STMT_INITTED"); + + rc= mysql_stmt_prepare(stmt, SL("SET @a:=1")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_attr_get(stmt, STMT_ATTR_STATE, &state); + FAIL_IF(state != MYSQL_STMT_PREPARED, "expected status MYSQL_STMT_PREPARED"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_attr_get(stmt, STMT_ATTR_STATE, &state); + FAIL_IF(state != MYSQL_STMT_EXECUTED, "expected status MYSQL_STMT_EXECUTED"); + + mysql_stmt_close(stmt); + return OK; +} + struct my_tests_st my_tests[] = { + {"test_conc349", test_conc349, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_prepare_error", test_prepare_error, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_reexecute", test_reexecute, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_bit2tiny", test_bit2tiny, TEST_CONNECTION_NEW, 0, NULL, NULL},