/** * @file prepare_statement_err3024-t.cpp * @brief Checks proper handling by ProxySQL of binary resultset holding errors. * @details This test, performs a mixed set of queries, some of them expecting errors. The test is also * compiled against 'libmysqlclient' and also makes use of both ASYNC and SYNC APIs. */ #include #include #include #include #include #include #include #include "tap.h" #include "command_line.h" #include "proxysql_utils.h" #include "utils.h" const int NUM_EXECUTIONS = 5; std::string select_query[3] = { "SELECT /*+ MAX_EXECUTION_TIME(10) */ COUNT(*) FROM test.sbtest1 a JOIN test.sbtest1 b WHERE (a.id+b.id)%2" , "SELECT COUNT(*) FROM (SELECT a.* FROM test.sbtest1 a JOIN test.sbtest1 b WHERE (a.id+b.id)%2 LIMIT 1000) t" , "SELECT a.* FROM test.sbtest1 a JOIN test.sbtest1 b WHERE (a.id+b.id)%2 LIMIT 10000" }; #ifndef LIBMYSQL_HELPER /* Helper function to do the waiting for events on the socket. */ static int wait_for_mysql(MYSQL *mysql, int status) { struct pollfd pfd; int timeout, res; pfd.fd = mysql_get_socket(mysql); pfd.events = (status & MYSQL_WAIT_READ ? POLLIN : 0) | (status & MYSQL_WAIT_WRITE ? POLLOUT : 0) | (status & MYSQL_WAIT_EXCEPT ? POLLPRI : 0); if (status & MYSQL_WAIT_TIMEOUT) timeout = 1000*mysql_get_timeout_value(mysql); else timeout = -1; res = poll(&pfd, 1, timeout); if (res == 0) return MYSQL_WAIT_TIMEOUT; else if (res < 0) return MYSQL_WAIT_TIMEOUT; else { int status = 0; if (pfd.revents & POLLIN) status |= MYSQL_WAIT_READ; if (pfd.revents & POLLOUT) status |= MYSQL_WAIT_WRITE; if (pfd.revents & POLLPRI) status |= MYSQL_WAIT_EXCEPT; return status; } } #endif /** * @brief Function is required to be duplicated in the test because multiple compilations using * 'libmysqlclient' and 'libmariadbclient'. TODO: Being able to share helper functions targetting different * connector libraries between tap tests. */ int add_more_rows_test_sbtest1(int num_rows, MYSQL *mysql, bool sqlite) { std::random_device rd; std::mt19937 mt(rd()); std::uniform_int_distribution dist(0.0, 9.0); diag("Creating %d rows in sbtest1", num_rows); while (num_rows) { std::stringstream q; if (sqlite==false) { q << "INSERT INTO test.sbtest1 (k, c, pad) values "; } else { q << "INSERT INTO sbtest1 (k, c, pad) values "; } bool put_comma = false; int i=0; unsigned int cnt=5+rand()%50; if (cnt > num_rows) cnt = num_rows; for (i=0; i