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

Merge branch '10.2-server' into 10.3-serg

This commit is contained in:
Sergei Golubchik
2018-08-10 14:24:53 +02:00
40 changed files with 763 additions and 296 deletions

View File

@@ -26,7 +26,7 @@ INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/include
${CC_SOURCE_DIR}/unittest/libmariadb)
ADD_DEFINITIONS(-DLIBMARIADB)
SET(API_TESTS "bulk1" "performance" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" "sp" "result" "connection" "misc" "ps_new" "thread" "features-10_2" "bulk1")
SET(API_TESTS "conc336" "bulk1" "performance" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" "sp" "result" "connection" "misc" "ps_new" "thread" "features-10_2" "bulk1")
IF(WITH_DYNCOL)
SET(API_TESTS ${API_TESTS} "dyncol")
ENDIF()

View File

@@ -996,8 +996,79 @@ static int bulk_null_null(MYSQL *mysql)
return OK;
}
static int test_mdev16593(MYSQL *mysql)
{
int i;
int rc;
MYSQL_BIND bind[2];
unsigned int array_size= 2;
int val_a[2]= {1,2};
char indicators[2]= {STMT_INDICATOR_NULL, STMT_INDICATOR_NULL};
const char *testcase[]= {"MYSQL_TYPE_LONG", "MYSQL_TYPE_NULL", "STMT_INDICATOR_NULL"};
diag("waiting for server fix");
return SKIP;
for (i=0; i < 3; i++)
{
MYSQL_RES *res;
MYSQL_ROW row;
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
rc= mysql_query(mysql, "CREATE OR REPLACE TABLE t1 (a int not null auto_increment primary key, b int)");
check_mysql_rc(rc, mysql);
memset(&bind, 0, sizeof(MYSQL_BIND));
switch (i) {
case 0:
bind[0].buffer_type= MYSQL_TYPE_LONG;
break;
case 1:
bind[0].buffer_type= MYSQL_TYPE_NULL;
break;
case 2:
bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].u.indicator= indicators;
break;
}
bind[0].buffer= val_a;
bind[1].buffer_type= MYSQL_TYPE_LONG;
bind[1].buffer= val_a;
rc= mysql_stmt_prepare(stmt, SL("insert into t1 values(?,?)"));
check_stmt_rc(rc, stmt);
rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size);
check_stmt_rc(rc, stmt);
rc= mysql_stmt_bind_param(stmt, bind);
check_stmt_rc(rc, stmt);
rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);
rc= mysql_query(mysql, "COMMIT");
check_mysql_rc(rc, mysql);
diag("Insert id with buffer_type %s: %lld",
testcase[i],
mysql_stmt_insert_id(stmt));
rc= mysql_query(mysql, "SELECT max(a) FROM t1");
check_mysql_rc(rc, mysql);
res= mysql_store_result(mysql);
row= mysql_fetch_row(res);
diag("Max value for t1.a=%s", row[0]);
mysql_free_result(res);
mysql_stmt_close(stmt);
}
return OK;
}
struct my_tests_st my_tests[] = {
{"check_bulk", check_bulk, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_mdev16593", test_mdev16593, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"bulk_null_null", bulk_null_null, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_char_conv1", test_char_conv1, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_char_conv2", test_char_conv2, TEST_CONNECTION_NEW, 0, NULL, NULL},

View File

@@ -0,0 +1,45 @@
#include "my_test.h"
#define MAX_COUNT 2000
int main(int argc, char *argv[]) {
MYSQL *mysql;
int i;
if (argc > 1)
get_options(argc, argv);
get_envvars();
for (i = 0; i < MAX_COUNT; ++i) {
if (mysql_library_init(-1, NULL, NULL) != 0) {
diag("mysql_library_init failed");
return 1;
}
mysql = mysql_init(NULL);
if (!mysql) {
diag("mysql_init failed");
return 1;
}
if (!mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0)) {
diag("mysql_real_connect failed: %s", mysql_error(mysql));
return 1;
}
if (mysql_query(mysql, "SELECT NULL LIMIT 0") != 0) {
diag("mysql_query failed: %s", mysql_error(mysql));
return 1;
}
mysql_close(mysql);
mysql_library_end();
}
return 0;
}

View File

@@ -1486,7 +1486,47 @@ static int test_conc327(MYSQL *unused __attribute__((unused)))
}
#endif
static int test_conc332(MYSQL *unused __attribute__((unused)))
{
int rc;
MYSQL *mysql= mysql_init(NULL);
int server_status1, server_status2;
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "utf8mb4");
my_test_connect(mysql, hostname, username, password, schema,
port, socketname, 0);
FAIL_IF(mysql_errno(mysql), "Error during connect");
mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status1);
diag("server_status: %d", server_status1);
if (server_status1 & SERVER_STATUS_AUTOCOMMIT)
rc= mysql_query(mysql, "SET autocommit= 0");
else
rc= mysql_query(mysql, "SET autocommit= 1");
check_mysql_rc(rc, mysql);
mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status2);
diag("server_status after changing autocommit: %d", server_status2);
rc= mysql_change_user(mysql, username, password, schema);
check_mysql_rc(rc, mysql);
mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status2);
diag("server_status after mysql_change_user: %d", server_status2);
if (server_status1 != server_status2)
{
diag("Expected server_status %d instead of %d", server_status1, server_status2);
mysql_close(mysql);
return FAIL;
}
mysql_close(mysql);
return OK;
}
struct my_tests_st my_tests[] = {
{"test_conc332", test_conc332, TEST_CONNECTION_NONE, 0, NULL, NULL},
#ifndef WIN32
{"test_conc327", test_conc327, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc317", test_conc317, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},

View File

@@ -253,12 +253,54 @@ static int dyncol_column_count(MYSQL *unused __attribute__((unused)))
return OK;
}
static int dyncol_nested(MYSQL *mysql __attribute__((unused)))
{
DYNAMIC_COLUMN col1, col2;
DYNAMIC_COLUMN_VALUE value[2];
MYSQL_LEX_STRING cols[2]= {{(char *)"0",1},{(char *)"1",1}};
DYNAMIC_STRING s;
mariadb_dyncol_init(&col1);
mariadb_dyncol_init(&col2);
memset(&value, 0, sizeof(DYNAMIC_COLUMN_VALUE));
value[0].type= DYN_COL_UINT;
value[0].x.ulong_value = 17;
mariadb_dyncol_create_many_named(&col1, 1, cols, value, 0);
if (mariadb_dyncol_check(&col1) != ER_DYNCOL_OK)
{
diag("Error while creating col1");
return FAIL;
}
value[1].type= DYN_COL_DYNCOL;
value[1].x.string.value.str= col1.str;
value[1].x.string.value.length= col1.length;
mariadb_dyncol_create_many_named(&col2, 2, cols, value, 0);
if (mariadb_dyncol_check(&col2) != ER_DYNCOL_OK)
{
diag("Error while creating col1");
return FAIL;
}
mariadb_dyncol_json(&col2, &s);
if (strcmp(s.str, "{\"0\":17,\"1\":{\"0\":17}}") != 0)
{
diag("%s != %s", s.str, "{\"0\":17,\"1\":{\"0\":17}}");
return FAIL;
}
return OK;
}
struct my_tests_st my_tests[] = {
{"mdev_x1", mdev_x1, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"mdev_4994", mdev_4994, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"create_dyncol_named", create_dyncol_named, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"create_dyncol_num", create_dyncol_num, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"dyncol_column_count", dyncol_column_count, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"dyncol_nested", dyncol_nested, TEST_CONNECTION_NEW, 0, NULL, NULL},
{NULL, NULL, 0, 0, NULL, 0}
};

View File

@@ -2209,7 +2209,7 @@ static int test_bind_negative(MYSQL *mysql)
my_bind[0].buffer_type= MYSQL_TYPE_LONG;
my_bind[0].buffer= (void *)&my_val;
my_bind[0].length= &my_length;
my_bind[0].is_null= (char*)&my_null;
my_bind[0].is_null= &my_null;
rc= mysql_stmt_bind_param(stmt, my_bind);
check_stmt_rc(rc, stmt);
@@ -2400,12 +2400,12 @@ static int test_union_param(MYSQL *mysql)
my_bind[0].buffer= (char*) &my_val;
my_bind[0].buffer_length= 4;
my_bind[0].length= &my_length;
my_bind[0].is_null= (char*)&my_null;
my_bind[0].is_null= &my_null;
my_bind[1].buffer_type= MYSQL_TYPE_STRING;
my_bind[1].buffer= (char*) &my_val;
my_bind[1].buffer_length= 4;
my_bind[1].length= &my_length;
my_bind[1].is_null= (char*)&my_null;
my_bind[1].is_null= &my_null;
rc= mysql_stmt_bind_param(stmt, my_bind);
check_stmt_rc(rc, stmt);
@@ -3313,7 +3313,7 @@ ENGINE=InnoDB DEFAULT CHARSET=utf8");
my_bind[0].buffer_type= MYSQL_TYPE_LONG;
my_bind[0].buffer= (void *)&my_val;
my_bind[0].length= &my_length;
my_bind[0].is_null= (char*)&my_null;
my_bind[0].is_null= &my_null;
my_val= 1;
rc= mysql_stmt_bind_param(stmt, my_bind);
check_stmt_rc(rc, stmt);
@@ -4637,7 +4637,6 @@ static int test_stmt_close(MYSQL *mysql)
FAIL_IF(mysql_stmt_param_count(stmt2) != 1, "param_count != 1");
rc= mysql_stmt_close(stmt1);
check_stmt_rc(rc, stmt1);
/*
Originally we were going to close all statements automatically in

View File

@@ -4654,43 +4654,138 @@ static int test_compress(MYSQL *mysql)
static int test_codbc138(MYSQL *mysql)
{
int rc;
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
MYSQL_STMT *stmt;
MYSQL_BIND bind[1];
MYSQL_TIME tm;
int i= 0;
rc= mysql_stmt_prepare(stmt, SL("SELECT DATE_ADD('2018-02-01', INTERVAL -188 DAY)"));
struct st_time_test {
const char *statement;
MYSQL_TIME tm;
} time_test[]= {
{"SELECT DATE_ADD('2018-02-01', INTERVAL -188 DAY)",
{2017,7,28,0,0,0,0L,0, MYSQL_TIMESTAMP_DATE}
},
{"SELECT '2001-02-03 11:12:13.123456'",
{2001,2,3,11,12,13,123456L,0, MYSQL_TIMESTAMP_DATETIME}
},
{"SELECT '-11:12:13'",
{0,0,0,11,12,13,0,1, MYSQL_TIMESTAMP_TIME}
},
{"SELECT ' '",
{0,0,0,0,0,0,0,0, MYSQL_TIMESTAMP_ERROR}
},
{"SELECT '1--'",
{1,0,0,0,0,0,0,0, MYSQL_TIMESTAMP_ERROR}
},
{"SELECT '-2001-01-01'",
{1,0,0,0,0,0,0,0, MYSQL_TIMESTAMP_ERROR}
},
{"SELECT '-11:00'",
{1,0,0,0,0,0,0,0, MYSQL_TIMESTAMP_ERROR}
},
{NULL, {0}}
};
while (time_test[i].statement)
{
stmt= mysql_stmt_init(mysql);
rc= mysql_stmt_prepare(stmt, SL(time_test[i].statement));
check_stmt_rc(rc, stmt);
rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);
rc= mysql_stmt_store_result(stmt);
memset(bind, 0, sizeof(MYSQL_BIND));
bind[0].buffer_type= MYSQL_TYPE_DATETIME;
bind[0].buffer= &tm;
bind[0].buffer_length= sizeof(MYSQL_TIME);
rc= mysql_stmt_bind_result(stmt, bind);
check_stmt_rc(rc, stmt);
rc= mysql_stmt_fetch(stmt);
check_stmt_rc(rc, stmt);
diag("test: %s %d %d", time_test[i].statement, tm.time_type, time_test[i].tm.time_type);
if (time_test[i].tm.time_type == MYSQL_TIMESTAMP_ERROR)
{
FAIL_UNLESS(tm.time_type == MYSQL_TIMESTAMP_ERROR, "MYSQL_TIMESTAMP_ERROR expected");
}
else
FAIL_UNLESS(memcmp(&tm, &time_test[i].tm, sizeof(MYSQL_TIME)) == 0, "time_in != time_out");
mysql_stmt_close(stmt);
i++;
}
return OK;
}
static int test_conc334(MYSQL *mysql)
{
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
MYSQL_RES *result;
MYSQL_FIELD *field;
int rc;
rc= mysql_stmt_prepare(stmt, SL("SHOW ENGINES"));
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_DATETIME;
bind[0].buffer= &tm;
bind[0].buffer_length= sizeof(MYSQL_TIME);
result= mysql_stmt_result_metadata(stmt);
if (!result)
{
diag("Coudn't retrieve result set");
mysql_stmt_close(stmt);
return FAIL;
}
rc= mysql_stmt_bind_result(stmt, bind);
mysql_field_seek(result, 0);
while ((field= mysql_fetch_field(result)))
{
FAIL_IF(field->name_length == 0, "Invalid name length (0)");
FAIL_IF(field->table_length == 0, "Invalid name length (0)");
}
mysql_free_result(result);
mysql_stmt_close(stmt);
return OK;
}
static int test_conc344(MYSQL *mysql)
{
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
int rc;
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "CREATE TABLE t1 (a int, b int)");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1,1), (2,2),(3,3),(4,4),(5,5)");
check_mysql_rc(rc, mysql);
rc= mysql_stmt_prepare(stmt, SL("SELECT * FROM t1 ORDER BY a"));
check_stmt_rc(rc, stmt);
rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);
while (!mysql_stmt_fetch(stmt));
FAIL_IF(mysql_stmt_num_rows(stmt) != 5, "expected 5 rows");
rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);
rc= mysql_stmt_fetch(stmt);
check_stmt_rc(rc, stmt);
if (tm.year != 2017 && tm.day != 28 && tm.month != 7)
{
diag("Error: Expected 2017-07-02");
return FAIL;
}
if (tm.minute | tm.second || tm.second_part)
{
diag("Error: minute, second or second_part is not zero");
return FAIL;
}
diag("num_rows: %lld", mysql_stmt_num_rows(stmt));
FAIL_IF(mysql_stmt_num_rows(stmt) != 1, "expected 1 row");
mysql_stmt_close(stmt);
return OK;
}
struct my_tests_st my_tests[] = {
{"test_conc344", test_conc344, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_conc334", test_conc334, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_compress", test_compress, TEST_CONNECTION_NEW, CLIENT_COMPRESS, NULL, NULL},
{"test_codbc138", test_codbc138, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc208", test_conc208, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
@@ -4776,4 +4871,3 @@ int main(int argc, char **argv)
return(exit_status());
}

View File

@@ -30,7 +30,7 @@ static int test_view(MYSQL *mysql)
MYSQL_BIND my_bind[1];
char str_data[50];
ulong length = 0L;
long is_null = 0L;
my_bool is_null = 0;
const char *query=
"SELECT COUNT(*) FROM v1 WHERE SERVERNAME=?";
@@ -84,7 +84,7 @@ static int test_view(MYSQL *mysql)
my_bind[0].buffer_length= 50;
my_bind[0].length= &length;
length= 4;
my_bind[0].is_null= (char*)&is_null;
my_bind[0].is_null= &is_null;
rc= mysql_stmt_bind_param(stmt, my_bind);
check_stmt_rc(rc, stmt);
@@ -301,7 +301,7 @@ static int test_view_insert(MYSQL *mysql)
MYSQL_BIND my_bind[1];
int my_val = 0;
ulong my_length = 0L;
long my_null = 0L;
my_bool my_null = 0;
const char *query=
"insert into v1 values (?)";
@@ -328,7 +328,7 @@ static int test_view_insert(MYSQL *mysql)
my_bind[0].buffer_type = MYSQL_TYPE_LONG;
my_bind[0].buffer = (char *)&my_val;
my_bind[0].length = &my_length;
my_bind[0].is_null = (char*)&my_null;
my_bind[0].is_null = &my_null;
rc= mysql_stmt_bind_param(insert_stmt, my_bind);
check_stmt_rc(rc, select_stmt);