You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-08 14:02:17 +03:00
several fixes for mariadb_stmt_execute_direct:
- allow param binding via mysql_stmt_attr_set: mysql_stmt_attr_set(stmt, STMT_ATTR_PREBIND_PARAMS, ¶m_count); - If a prepared statement will be reexecuted, we send COM_STMT_CLOSE together with COM_STMT_PREPARE and COM_STMT_EXECUTE
This commit is contained in:
@@ -70,6 +70,8 @@ ENDIF()
|
||||
|
||||
ADD_LIBRARY(ma_getopt ma_getopt.c)
|
||||
|
||||
ADD_EXECUTABLE(my_test test.c)
|
||||
TARGET_LINK_LIBRARIES(my_test mariadbclient)
|
||||
FOREACH(API_TEST ${API_TESTS})
|
||||
ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c)
|
||||
TARGET_LINK_LIBRARIES(${API_TEST} mytap ma_getopt mariadbclient)
|
||||
|
@@ -876,7 +876,8 @@ static int test_get_options(MYSQL *my)
|
||||
mysql_options(mysql, options_char[i], char1);
|
||||
char2= NULL;
|
||||
mysql_get_optionv(mysql, options_char[i], (void *)&char2);
|
||||
FAIL_IF(strcmp(char1, char2), "mysql_get_optionv (char) failed");
|
||||
if (options_char[i] != MYSQL_SET_CHARSET_NAME)
|
||||
FAIL_IF(strcmp(char1, char2), "mysql_get_optionv (char) failed");
|
||||
}
|
||||
|
||||
for (i=0; i < 3; i++)
|
||||
|
@@ -72,7 +72,7 @@ static int com_multi_1(MYSQL *mysql)
|
||||
|
||||
|
||||
#define repeat1 100
|
||||
#define repeat2 10
|
||||
#define repeat2 1
|
||||
|
||||
static int com_multi_2(MYSQL *mysql)
|
||||
{
|
||||
@@ -171,11 +171,11 @@ static int com_multi_ps1(MYSQL *mysql)
|
||||
static int com_multi_ps2(MYSQL *mysql)
|
||||
{
|
||||
MYSQL_STMT *stmt;
|
||||
MYSQL_BIND bind[3];
|
||||
MYSQL_BIND bind[2];
|
||||
int intval= 3, rc;
|
||||
int i;
|
||||
char *varval= "com_multi_ps2";
|
||||
|
||||
unsigned int param_count= 2;
|
||||
|
||||
if (!have_com_multi)
|
||||
return SKIP;
|
||||
@@ -184,28 +184,79 @@ static int com_multi_ps2(MYSQL *mysql)
|
||||
check_mysql_rc(rc, mysql);
|
||||
rc= mysql_query(mysql, "CREATE TABLE t1 (a int, b varchar(20))");
|
||||
|
||||
memset(&bind, 0, sizeof(MYSQL_BIND) * 3);
|
||||
memset(&bind, 0, sizeof(MYSQL_BIND) * 2);
|
||||
bind[0].buffer_type= MYSQL_TYPE_SHORT;
|
||||
bind[0].buffer= &intval;
|
||||
bind[1].buffer_type= MYSQL_TYPE_STRING;
|
||||
bind[1].buffer= varval;
|
||||
bind[1].buffer_length= strlen(varval);
|
||||
bind[2].buffer_type= MAX_NO_FIELD_TYPES;
|
||||
|
||||
stmt= mysql_stmt_init(mysql);
|
||||
mysql_stmt_attr_set(stmt, STMT_ATTR_PREBIND_PARAMS, ¶m_count);
|
||||
rc= mysql_stmt_bind_param(stmt, bind);
|
||||
check_stmt_rc(rc, stmt);
|
||||
rc= mariadb_stmt_execute_direct(stmt, "INSERT INTO t1 VALUES (?,?)", -1);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
for (i=0; i < 2; i++)
|
||||
{
|
||||
stmt= mysql_stmt_init(mysql);
|
||||
rc= mysql_stmt_bind_param(stmt, bind);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
rc= mariadb_stmt_execute_direct(stmt, "INSERT INTO t1 VALUES (1,'foo')", -1);
|
||||
mysql_stmt_execute(stmt);
|
||||
check_stmt_rc(rc, stmt);
|
||||
FAIL_IF(mysql_stmt_affected_rows(stmt) != 1, "expected affected_rows= 1");
|
||||
FAIL_IF(stmt->stmt_id < 1, "expected statement id > 0");
|
||||
|
||||
rc= mysql_stmt_close(stmt);
|
||||
check_mysql_rc(rc, mysql);
|
||||
}
|
||||
rc= mysql_stmt_close(stmt);
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int execute_direct(MYSQL *mysql)
|
||||
{
|
||||
long rc= 0, i= 0;
|
||||
MYSQL_STMT *stmt;
|
||||
MYSQL_BIND bind;
|
||||
unsigned int param_count= 1;
|
||||
MYSQL_RES *res= NULL;
|
||||
|
||||
stmt= mysql_stmt_init(mysql);
|
||||
|
||||
rc= mariadb_stmt_execute_direct(stmt, "DROP TABLE IF EXISTS t1", -1);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
rc= mariadb_stmt_execute_direct(stmt, "CREATE TABLE t1 (a int)", -1);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
memset(&bind, 0, sizeof(MYSQL_BIND));
|
||||
|
||||
bind.buffer= &i;
|
||||
bind.buffer_type= MYSQL_TYPE_LONG;
|
||||
bind.buffer_length= sizeof(long);
|
||||
|
||||
mysql_stmt_close(stmt);
|
||||
stmt= mysql_stmt_init(mysql);
|
||||
mysql_stmt_attr_set(stmt, STMT_ATTR_PREBIND_PARAMS, ¶m_count);
|
||||
|
||||
rc= mysql_stmt_bind_param(stmt, &bind);
|
||||
check_stmt_rc(rc, stmt);
|
||||
rc= mariadb_stmt_execute_direct(stmt, "INSERT INTO t1 VALUES (?)", -1);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
for (i=1; i < 1000; i++)
|
||||
{
|
||||
rc= mysql_stmt_execute(stmt);
|
||||
check_stmt_rc(rc, stmt);
|
||||
}
|
||||
rc= mysql_stmt_close(stmt);
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
rc= mysql_query(mysql, "SELECT * FROM t1");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
res= mysql_store_result(mysql);
|
||||
FAIL_IF(mysql_num_rows(res) != 1000, "Expected 1000 rows");
|
||||
|
||||
mysql_free_result(res);
|
||||
|
||||
return OK;
|
||||
}
|
||||
@@ -215,6 +266,7 @@ struct my_tests_st my_tests[] = {
|
||||
{"com_multi_2", com_multi_2, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
{"com_multi_ps1", com_multi_ps1, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
{"com_multi_ps2", com_multi_ps2, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
{"execute_direct", execute_direct, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{NULL, NULL, 0, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
|
@@ -74,11 +74,11 @@ static int test_conc83(MYSQL *my)
|
||||
check_stmt_rc(rc, stmt);
|
||||
diag("Ok");
|
||||
|
||||
/* 2. Status is prepared, second prepare should fail */
|
||||
/* 2. Status is prepared, execute should fail */
|
||||
rc= mysql_kill(mysql, mysql_thread_id(mysql));
|
||||
sleep(2);
|
||||
|
||||
rc= mysql_stmt_prepare(stmt, query, -1);
|
||||
rc= mysql_stmt_execute(stmt);
|
||||
FAIL_IF(!rc, "Error expected");
|
||||
|
||||
mysql_stmt_close(stmt);
|
||||
|
@@ -4247,7 +4247,94 @@ static int test_conc179(MYSQL *mysql)
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int test_conc182(MYSQL *mysql)
|
||||
{
|
||||
MYSQL_STMT *stmt;
|
||||
int rc;
|
||||
MYSQL_BIND bind[2];
|
||||
char buf1[22];
|
||||
MYSQL_RES *result;
|
||||
MYSQL_ROW row;
|
||||
|
||||
stmt= mysql_stmt_init(mysql);
|
||||
rc= mariadb_stmt_execute_direct(stmt, "DROP TABLE IF EXISTS t1", -1);
|
||||
check_stmt_rc(rc, stmt);
|
||||
rc= mariadb_stmt_execute_direct(stmt, "DROP TABLE IF EXISTS t1", -1);
|
||||
check_stmt_rc(rc, stmt);
|
||||
rc= mariadb_stmt_execute_direct(stmt, "SELECT 1", -1);
|
||||
check_stmt_rc(rc, stmt);
|
||||
rc= mariadb_stmt_execute_direct(stmt, "SELECT 1", -1);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
rc= mysql_stmt_close(stmt);
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
rc= mysql_query(mysql, "SELECT row_count()");
|
||||
result= mysql_store_result(mysql);
|
||||
row= mysql_fetch_row(result);
|
||||
diag("buf: %s", row[0]);
|
||||
mysql_free_result(result);
|
||||
|
||||
|
||||
stmt= mysql_stmt_init(mysql);
|
||||
rc= mysql_stmt_prepare(stmt, "SELECT row_count()", -1);
|
||||
check_stmt_rc(rc, stmt);
|
||||
rc= mysql_stmt_execute(stmt);
|
||||
|
||||
memset(bind, 0, 2 * sizeof(MYSQL_BIND));
|
||||
bind[0].buffer= &buf1;
|
||||
bind[0].buffer_length= bind[1].buffer_length= 20;
|
||||
bind[0].buffer_type= bind[1].buffer_type= MYSQL_TYPE_STRING;
|
||||
|
||||
rc= mysql_stmt_bind_result(stmt, bind);
|
||||
|
||||
while(!mysql_stmt_fetch(stmt))
|
||||
diag("b1: %s", buf1);
|
||||
rc= mysql_stmt_close(stmt);
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int test_conc181(MYSQL *mysql)
|
||||
{
|
||||
MYSQL_STMT *stmt;
|
||||
int rc;
|
||||
MYSQL_BIND bind;
|
||||
char *stmt_str= "SELECT a FROM t1";
|
||||
float f=1;
|
||||
my_bool err= 0;
|
||||
|
||||
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_query(mysql, "INSERT INTO t1 VALUES(1073741825)");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
stmt= mysql_stmt_init(mysql);
|
||||
rc= mysql_stmt_prepare(stmt, stmt_str, strlen(stmt_str));
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
rc= mysql_stmt_execute(stmt);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
memset(&bind, 0, sizeof(MYSQL_BIND));
|
||||
bind.buffer= &f;
|
||||
bind.error= &err;
|
||||
bind.buffer_type= MYSQL_TYPE_FLOAT;
|
||||
rc= mysql_stmt_bind_result(stmt, &bind);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
rc= mysql_stmt_fetch(stmt);
|
||||
diag("rc=%d err=%d float=%f, %d", rc, err, f, MYSQL_DATA_TRUNCATED);
|
||||
|
||||
rc= mysql_stmt_close(stmt);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
struct my_tests_st my_tests[] = {
|
||||
{"test_conc182", test_conc182, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_conc181", test_conc181, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_conc179", test_conc179, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_conc177", test_conc177, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_conc167", test_conc167, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
|
Reference in New Issue
Block a user