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

Support mariadb_stmt_execute_direct also for versions < 10.2

Bundled COM_CLOSE and COM_PREPARE packets
This commit is contained in:
Georg Richter
2016-11-12 17:51:01 +01:00
parent 64862325a5
commit 03a7ec1b8b
7 changed files with 121 additions and 22 deletions

View File

@@ -19,6 +19,8 @@
#define TEST_ARRAY_SIZE 1024
static my_bool bulk_enabled= 0;
char *rand_str(size_t length) {
const char charset[] = "0123456789"
"abcdefghijklmnopqrstuvwxyz"
@@ -32,6 +34,14 @@ char *rand_str(size_t length) {
return p;
}
static int check_bulk(MYSQL *mysql)
{
bulk_enabled= (!(mysql->server_capabilities & CLIENT_MYSQL) &&
(mysql->extension->mariadb_server_capabilities & MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32));
diag("bulk %ssupported", bulk_enabled ? "" : "not ");
return OK;
}
static int bulk1(MYSQL *mysql)
{
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
@@ -47,6 +57,9 @@ static int bulk1(MYSQL *mysql)
MYSQL_ROW row;
unsigned int intval;
if (!bulk_enabled)
return SKIP;
rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk1");
check_mysql_rc(rc, mysql);
@@ -133,6 +146,9 @@ static int bulk2(MYSQL *mysql)
unsigned int array_size=1024;
char indicator[1024];
long lval[1024];
if (!bulk_enabled)
return SKIP;
rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk2");
check_mysql_rc(rc, mysql);
@@ -187,6 +203,8 @@ static int bulk3(MYSQL *mysql)
int array_size= 3;
ulong length= -1;
if (!bulk_enabled)
return SKIP;
rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk3");
check_mysql_rc(rc,mysql);
rc= mysql_query(mysql, "CREATE TABLE bulk3 (name varchar(20), row int)");
@@ -218,6 +236,7 @@ static int bulk3(MYSQL *mysql)
}
struct my_tests_st my_tests[] = {
{"check_bulk", check_bulk, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"bulk1", bulk1, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"bulk2", bulk2, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"bulk3", bulk3, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},

View File

@@ -100,7 +100,66 @@ static int execute_direct_example(MYSQL *mysql)
return OK;
}
static int conc_213(MYSQL *mysql)
{
MYSQL_BIND bind;
unsigned int param_count= 1;
long id= 1234;
MYSQL_STMT *stmt;
stmt = mysql_stmt_init(mysql);
memset(&bind, '\0', sizeof(bind));
bind.buffer_type = MYSQL_TYPE_LONG;
bind.buffer = (void *)&id;
bind.buffer_length = sizeof(long);
/* bind.is_null = &is_null;
bind.length = &length;
bind.error = &error; */
mysql_stmt_attr_set(stmt, STMT_ATTR_PREBIND_PARAMS, &param_count);
check_stmt_rc(mysql_stmt_bind_param(stmt, &bind), stmt);
check_stmt_rc(mariadb_stmt_execute_direct(stmt, "SELECT ?", -1), stmt);
check_stmt_rc(mysql_stmt_store_result(stmt), stmt);
check_stmt_rc(mysql_stmt_free_result(stmt), stmt);
mysql_stmt_close(stmt);
return OK;
}
static int conc_212(MYSQL *mysql)
{
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
int rc;
rc= mariadb_stmt_execute_direct(stmt, "SELECT 1, 2", -1);
check_stmt_rc(rc, stmt);
mysql_stmt_store_result(stmt);
mysql_stmt_free_result(stmt);
sleep(100);
rc= mariadb_stmt_execute_direct(stmt, "SELECT 1, 2", -1);
check_stmt_rc(rc, stmt);
mysql_stmt_store_result(stmt);
mysql_stmt_free_result(stmt);
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
check_mysql_rc(rc,mysql);
rc= mysql_query(mysql, "CREATE TABLE t1(a int)");
check_mysql_rc(rc,mysql);
rc= mysql_stmt_close(stmt);
return OK;
}
struct my_tests_st my_tests[] = {
{"conc_212", conc_212, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"conc_213", conc_213, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"execute_direct", execute_direct, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"execute_direct_example", execute_direct_example, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{NULL, NULL, 0, 0, NULL, NULL}