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

First implementation of mariadb_stmt_execute_direct

This commit is contained in:
Georg Richter
2016-01-28 16:58:30 +01:00
parent 25e610c965
commit 8845fcb7ce
11 changed files with 392 additions and 125 deletions

View File

@@ -22,7 +22,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
ADD_DEFINITIONS(-DLIBMARIADB)
SET(API_TESTS "async" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs"
"sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "dyncol" "features-10_2")
"sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "dyncol" "features-10_2" )
#exclude following tests from ctests, since we need to run them maually with different credentials
SET(MANUAL_TESTS "t_aurora")

View File

@@ -3,26 +3,30 @@
#include "my_test.h"
my_bool have_com_multi= 1;
static int com_multi_1(MYSQL *mysql)
{
int rc;
MYSQL_RES *res;
my_bool is_multi= 1;
enum mariadb_com_multi status;
/* TEST a simple query before COM_MULTI */
rc= mysql_query(mysql, "select 1");
check_mysql_rc(rc, mysql);
FAIL_UNLESS(res, "1 simple query no result");
res= mysql_store_result(mysql);
FAIL_UNLESS(res, "1 simple query no result");
mysql_free_result(res);
/* TEST COM_MULTI */
if (mysql_options(mysql, MARIADB_OPT_COM_MULTI, &is_multi))
status= MARIADB_COM_MULTI_BEGIN;
if (mysql_options(mysql, MARIADB_OPT_COM_MULTI, &status))
{
diag("COM_MULT not supported");
have_com_multi= 0;
return SKIP;
}
@@ -30,7 +34,8 @@ static int com_multi_1(MYSQL *mysql)
rc= mysql_query(mysql, "select 2");
rc= mariadb_flush_multi_command(mysql);
status= MARIADB_COM_MULTI_END;
rc= mysql_options(mysql, MARIADB_OPT_COM_MULTI, &status);
check_mysql_rc(rc, mysql);
/* 1 SELECT result */
res= mysql_store_result(mysql);
@@ -48,10 +53,6 @@ static int com_multi_1(MYSQL *mysql)
strcmp(res->fields[0].name, "2") == 0,
"1 of 2 simple query in batch wrong result");
mysql_free_result(res);
/* WHOLE batch result (OK) */
rc= mysql_next_result(mysql);
res= mysql_store_result(mysql);
FAIL_UNLESS(res == NULL, "rows instead of batch OK");
rc= mysql_next_result(mysql);
FAIL_UNLESS(rc == -1, "more then 2 results");
@@ -69,8 +70,86 @@ static int com_multi_1(MYSQL *mysql)
return OK;
}
static int com_multi_ps1(MYSQL *mysql)
{
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
int rc;
if (!have_com_multi)
return SKIP;
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "CREATE TABLE t1 (a int, b varchar(20))");
rc= mysql_stmt_prepare(stmt, "INSERT INTO t1 values (2, 'execute_direct')", -1);
check_stmt_rc(rc, stmt);
rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);
diag("affected_rows: %d", mysql_stmt_affected_rows(stmt));
diag("stmt_id: %d", stmt->stmt_id);
mysql_stmt_close(stmt);
stmt= mysql_stmt_init(mysql);
rc= mariadb_stmt_execute_direct(stmt, "INSERT INTO t1 values (2, 'execute_direct')", -1);
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);
return OK;
}
static int com_multi_ps2(MYSQL *mysql)
{
MYSQL_STMT *stmt;
MYSQL_BIND bind[3];
int intval= 3, rc;
int i;
char *varval= "com_multi_ps2";
if (!have_com_multi)
return SKIP;
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "CREATE TABLE t1 (a int, b varchar(20))");
memset(&bind, 0, sizeof(MYSQL_BIND) * 3);
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;
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);
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);
}
return OK;
}
struct my_tests_st my_tests[] = {
{"com_multi_1", com_multi_1, 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},
{NULL, NULL, 0, 0, NULL, NULL}
};

View File

@@ -189,6 +189,8 @@ int do_verify_prepare_field(MYSQL_RES *result,
FAIL_UNLESS(strcmp(field->table, table) == 0, "field->table differs");
if (org_table)
FAIL_UNLESS(strcmp(field->org_table, org_table) == 0, "field->org_table differs");
if (strcmp(field->db,db))
diag("%s / %s", field->db, db);
FAIL_UNLESS(strcmp(field->db, db) == 0, "field->db differs");
/*
Character set should be taken into account for multibyte encodings, such

View File

@@ -830,6 +830,7 @@ static int test_prepare_alter(MYSQL *mysql)
FAIL_IF(!(mysql_real_connect(mysql_new, hostname, username, password,
schema, port, socketname, 0)), "mysql_real_connect failed");
rc= mysql_query(mysql_new, "ALTER TABLE test_prep_alter change id id_new varchar(20)");
diag("Error: %d %s", mysql_errno(mysql_new), mysql_error(mysql_new));
check_mysql_rc(rc, mysql_new);
mysql_close(mysql_new);