diff --git a/include/my_stmt.h b/include/my_stmt.h index fe727234..4b1e6b55 100644 --- a/include/my_stmt.h +++ b/include/my_stmt.h @@ -246,3 +246,4 @@ my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt); my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt); unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt); int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt); +my_bool STDCALL mysql_stmt_more_results(MYSQL_STMT *stmt); diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 8535ecec..ab1ac6f5 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -2853,7 +2853,7 @@ char *STDCALL mysql_info(MYSQL *mysql) my_bool STDCALL mysql_more_results(MYSQL *mysql) { DBUG_ENTER("mysql_more_results"); - DBUG_RETURN(test(mysql->server_status & SERVER_MORE_RESULTS_EXIST)); + DBUG_RETURN(test(mysql->server_status & SERVER_MORE_RESULTS_EXIST)); } int STDCALL mysql_next_result(MYSQL *mysql) diff --git a/libmariadb/libmariadb_exports.def b/libmariadb/libmariadb_exports.def index 5365d819..c4b69cca 100644 --- a/libmariadb/libmariadb_exports.def +++ b/libmariadb/libmariadb_exports.def @@ -103,5 +103,6 @@ EXPORTS mysql_set_character_set mysql_get_character_set_info mysql_stmt_next_result + mysql_stmt_more_results mariadb_connection mysql_get_server_name diff --git a/libmariadb/my_stmt.c b/libmariadb/my_stmt.c index 6607c906..08bd269a 100644 --- a/libmariadb/my_stmt.c +++ b/libmariadb/my_stmt.c @@ -1771,11 +1771,17 @@ MYSQL_RES* STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt) DBUG_RETURN(NULL); } -int STDCALL mysql_stmt_more_results(MYSQL_STMT *stmt) +my_bool STDCALL mysql_stmt_more_results(MYSQL_STMT *stmt) { + /* MDEV 4604: Server doesn't set MORE_RESULT flag for + OutParam result set, so we need to check + for SERVER_MORE_RESULTS_EXIST and for + SERVER_PS_OUT_PARAMS) + */ return (stmt && stmt->mysql && - (stmt->mysql->server_status & SERVER_MORE_RESULTS_EXIST)); + ((stmt->mysql->server_status & SERVER_MORE_RESULTS_EXIST) || + (stmt->mysql->server_status & SERVER_PS_OUT_PARAMS))); } int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt) diff --git a/unittest/libmariadb/ps.c b/unittest/libmariadb/ps.c index ac453586..e5c3bb81 100644 --- a/unittest/libmariadb/ps.c +++ b/unittest/libmariadb/ps.c @@ -4727,7 +4727,46 @@ int test_fracseconds(MYSQL *mysql) return OK; } +int test_notrunc(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + my_bool trunc= 1; + MYSQL_BIND bind[1]; + char buffer[5]; + int rc, len= 1, error= 0; + + char *query= "SELECT '1234567890' FROM DUAL"; + + mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, &trunc); + + stmt= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(stmt, query, strlen(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(bind, 0, sizeof(MYSQL_BIND)); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= buffer; + bind[0].buffer_length= 3; + bind[0].length= &len; + bind[0].error= &error; + +// rc= mysql_stmt_bind_result(stmt, bind); +// check_stmt_rc(rc, stmt); + mysql_stmt_store_result(stmt); + + rc= mysql_stmt_fetch(stmt); + diag("rc= %d len=%d", rc, len); + + mysql_stmt_close(stmt); + return OK; +} + struct my_tests_st my_tests[] = { + {"test_notrunc", test_notrunc, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_fracseconds", test_fracseconds, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_blob_9000", test_blob_9000, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, {"test_long_data1", test_long_data1, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, diff --git a/unittest/libmariadb/ps_new.c b/unittest/libmariadb/ps_new.c index 3c3b6761..7f33bef0 100644 --- a/unittest/libmariadb/ps_new.c +++ b/unittest/libmariadb/ps_new.c @@ -209,8 +209,6 @@ int test_sp_params(MYSQL *mysql) } } while (mysql_stmt_next_result(stmt) == 0); - - rc= mysql_stmt_close(stmt); return OK; } @@ -219,13 +217,13 @@ int test_sp_reset(MYSQL *mysql) { int i, rc; MYSQL_STMT *stmt; - - rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); - check_mysql_rc(rc, mysql); int a[] = {10,20,30}; MYSQL_BIND bind[3]; char *stmtstr= "CALL P1(?,?,?)"; + rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE PROCEDURE p1(OUT p_out VARCHAR(19), IN p_in INT, INOUT p_inout INT)" "BEGIN " " SET p_in = 300, p_out := 'This is OUT param', p_inout = 200; " @@ -334,6 +332,7 @@ int test_sp_reset2(MYSQL *mysql) MYSQL_STMT *stmt; MYSQL_BIND bind[4]; long l[4]; + char *stmtstr= "CALL P1()"; rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); check_mysql_rc(rc, mysql); @@ -342,7 +341,6 @@ int test_sp_reset2(MYSQL *mysql) rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); check_mysql_rc(rc, mysql); - char *stmtstr= "CALL P1()"; rc= mysql_query(mysql, "CREATE PROCEDURE p1()" "BEGIN " @@ -380,7 +378,6 @@ int test_sp_reset2(MYSQL *mysql) rc= mysql_stmt_fetch(stmt); diag("l=%d", l[0]); } - diag("next result"); rc= mysql_stmt_next_result(stmt); check_stmt_rc(rc, stmt); @@ -395,7 +392,6 @@ int test_sp_reset2(MYSQL *mysql) diag("l=%d l=%d", l[0], l[1]); } - diag("next result"); rc= mysql_stmt_next_result(stmt); check_stmt_rc(rc, stmt); @@ -422,7 +418,7 @@ int test_sp_reset2(MYSQL *mysql) int test_query(MYSQL *mysql) { int rc; - int counter= 0; + int i; MYSQL_STMT *stmt; MYSQL_BIND bind[1]; @@ -434,8 +430,7 @@ int test_query(MYSQL *mysql) rc= mysql_query(mysql, "CREATE PROCEDURE p1(OUT p_out VARCHAR(19))" "BEGIN " " SET p_out = 'foo';" - " SELECT 'foo' FROM DUAL;" - " SELECT 'bar' FROM DUAL;" + " SELECT 1 FROM DUAL;" "END"); check_mysql_rc(rc, mysql); @@ -445,33 +440,48 @@ int test_query(MYSQL *mysql) rc= mysql_stmt_prepare(stmt, stmtstr, strlen(stmtstr)); check_stmt_rc(rc, stmt); - memset(tmp, 0, sizeof(tmp)); - memset(bind, 0, sizeof(MYSQL_BIND)); - bind[0].buffer= tmp; - bind[0].buffer_type= MYSQL_TYPE_STRING; - bind[0].buffer_length= 4; + for (i=0; i < 1000; i++) + { + int status; + memset(tmp, 0, sizeof(tmp)); + memset(bind, 0, sizeof(MYSQL_BIND)); + bind[0].buffer= tmp; + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer_length= 4; - mysql_stmt_bind_param(stmt, bind); + mysql_stmt_bind_param(stmt, bind); - rc= mysql_stmt_execute(stmt); - check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + do { + if (stmt->field_count) + { + mysql_stmt_bind_result(stmt, bind); + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + while(mysql_stmt_fetch(stmt) == 0); - do { - if (!mysql_stmt_store_result(stmt)) - { - counter++; - mysql_stmt_free_result(stmt); - } - } while (mysql_more_results(stmt->mysql) && mysql_next_result(stmt->mysql) == 0); + rc= mysql_stmt_free_result(stmt); + check_stmt_rc(rc, stmt); + } + status= mysql_stmt_next_result(stmt); + if (status == 1) + check_stmt_rc(status, stmt); + } while (status == 0); - diag ("result sets: %d", counter); + rc= mysql_stmt_reset(stmt); + if (rc) + diag("reset failed after %d iterations", i); + check_stmt_rc(rc, stmt); + } mysql_stmt_close(stmt); + return OK; } struct my_tests_st my_tests[] = { - {"test_query", test_query, TEST_CONNECTION_DEFAULT, CLIENT_MULTI_STATEMENTS , NULL , NULL}, + {"test_query", test_query, TEST_CONNECTION_DEFAULT, CLIENT_MULTI_RESULTS , NULL , NULL}, {"test_sp_params", test_sp_params, TEST_CONNECTION_DEFAULT, CLIENT_MULTI_STATEMENTS, NULL , NULL}, {"test_sp_reset", test_sp_reset, TEST_CONNECTION_DEFAULT, CLIENT_MULTI_STATEMENTS, NULL , NULL}, {"test_sp_reset1", test_sp_reset1, TEST_CONNECTION_DEFAULT, CLIENT_MULTI_STATEMENTS, NULL , NULL},