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
Merge branch 'master' of https://github.com/MariaDB/mariadb-connector-c
This commit is contained in:
@@ -26,7 +26,7 @@ INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/include
|
||||
${CC_SOURCE_DIR}/unittest/libmariadb)
|
||||
ADD_DEFINITIONS(-DLIBMARIADB)
|
||||
|
||||
SET(API_TESTS "performance" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" "sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "features-10_2" "bulk1" )
|
||||
SET(API_TESTS "bulk1" "performance" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" "sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "features-10_2" "bulk1")
|
||||
IF(WITH_DYNCOL)
|
||||
SET(API_TESTS ${API_TESTS} "dyncol")
|
||||
ENDIF()
|
||||
|
@@ -402,6 +402,7 @@ static int bulk5(MYSQL *mysql)
|
||||
|
||||
res= mysql_store_result(mysql);
|
||||
rows= (unsigned long)mysql_num_rows(res);
|
||||
diag("rows: %lu", rows);
|
||||
mysql_free_result(res);
|
||||
|
||||
FAIL_IF(rows != 5, "expected 5 rows");
|
||||
|
@@ -988,7 +988,7 @@ static int test_sess_track_db(MYSQL *mysql)
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
static int test_unix_socket_close(MYSQL *unused __attribute__((unused)))
|
||||
{
|
||||
MYSQL *mysql= mysql_init(NULL);
|
||||
@@ -1016,6 +1016,7 @@ static int test_unix_socket_close(MYSQL *unused __attribute__((unused)))
|
||||
mysql_close(mysql);
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int test_reset(MYSQL *mysql)
|
||||
{
|
||||
@@ -1069,9 +1070,32 @@ static int test_reset(MYSQL *mysql)
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int test_mdev12446(MYSQL *my __attribute__((unused)))
|
||||
{
|
||||
/*
|
||||
if specified file didn't exist, valgrind reported a leak,
|
||||
if no file was specified and no default file is installed,
|
||||
C/C crashed due to double free.
|
||||
*/
|
||||
MYSQL *mysql= mysql_init(NULL);
|
||||
mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "file.notfound");
|
||||
FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema,
|
||||
port, socketname, 0), mysql_error(mysql));
|
||||
mysql_close(mysql);
|
||||
mysql= mysql_init(NULL);
|
||||
mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "notfound");
|
||||
FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema,
|
||||
port, socketname, 0), mysql_error(mysql));
|
||||
mysql_close(mysql);
|
||||
return OK;
|
||||
}
|
||||
|
||||
struct my_tests_st my_tests[] = {
|
||||
{"test_mdev12446", test_mdev12446, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_reset", test_reset, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
#ifndef WIN32
|
||||
{"test_unix_socket_close", test_unix_socket_close, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||
#endif
|
||||
{"test_sess_track_db", test_sess_track_db, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_get_options", test_get_options, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_wrong_bind_address", test_wrong_bind_address, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
|
@@ -190,8 +190,31 @@ static int conc_218(MYSQL *mysql)
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int test_cursor(MYSQL *mysql)
|
||||
{
|
||||
int rc;
|
||||
MYSQL_STMT *stmt;
|
||||
unsigned int prefetch_rows= 1;
|
||||
unsigned long cursor_type= CURSOR_TYPE_READ_ONLY;
|
||||
|
||||
stmt= mysql_stmt_init(mysql);
|
||||
rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, &cursor_type);
|
||||
check_stmt_rc(rc, stmt);
|
||||
rc= mysql_stmt_attr_set(stmt, STMT_ATTR_PREFETCH_ROWS, &prefetch_rows);
|
||||
check_stmt_rc(rc, stmt);
|
||||
rc= mariadb_stmt_execute_direct(stmt, "SELECT 1 FROM DUAL UNION SELECT 2 FROM DUAL", -1);
|
||||
check_stmt_rc(rc, stmt);
|
||||
rc= mysql_stmt_fetch(stmt);
|
||||
check_stmt_rc(rc, stmt);
|
||||
rc= mariadb_stmt_execute_direct(stmt, "SELECT 1 FROM DUAL UNION SELECT 2 FROM DUAL", -1);
|
||||
check_stmt_rc(rc, stmt);
|
||||
mysql_stmt_close(stmt);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
struct my_tests_st my_tests[] = {
|
||||
{"test_cursor", test_cursor, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"conc_218", conc_218, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"conc_212", conc_212, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"conc_213", conc_213, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
|
@@ -265,7 +265,7 @@ static int test_frm_bug(MYSQL *mysql)
|
||||
sprintf(test_frm, "%s/%s/test_frm_bug.frm", data_dir, schema);
|
||||
|
||||
|
||||
if (!(test_file= fopen(test_frm, "rw")))
|
||||
if (!(test_file= fopen(test_frm, "w")))
|
||||
{
|
||||
mysql_stmt_close(stmt);
|
||||
diag("Can't write to file %s -> SKIP", test_frm);
|
||||
|
@@ -4974,7 +4974,106 @@ static int test_bit2tiny(MYSQL *mysql)
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int test_reexecute(MYSQL *mysql)
|
||||
{
|
||||
MYSQL_STMT *stmt;
|
||||
MYSQL_BIND ps_params[3]; /* input parameter buffers */
|
||||
int int_data[3]; /* input/output values */
|
||||
int rc;
|
||||
|
||||
/* set up stored procedure */
|
||||
rc = mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
rc = mysql_query(mysql,
|
||||
"CREATE PROCEDURE p1("
|
||||
" IN p_in INT, "
|
||||
" OUT p_out INT, "
|
||||
" INOUT p_inout INT) "
|
||||
"BEGIN "
|
||||
" SELECT p_in, p_out, p_inout; "
|
||||
" SET p_in = 100, p_out = 200, p_inout = 300; "
|
||||
" SELECT p_in, p_out, p_inout; "
|
||||
"END");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
/* initialize and prepare CALL statement with parameter placeholders */
|
||||
stmt = mysql_stmt_init(mysql);
|
||||
if (!stmt)
|
||||
{
|
||||
diag("Could not initialize statement");
|
||||
exit(1);
|
||||
}
|
||||
rc = mysql_stmt_prepare(stmt, "CALL p1(?, ?, ?)", 16);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
/* initialize parameters: p_in, p_out, p_inout (all INT) */
|
||||
memset(ps_params, 0, sizeof (ps_params));
|
||||
|
||||
ps_params[0].buffer_type = MYSQL_TYPE_LONG;
|
||||
ps_params[0].buffer = (char *) &int_data[0];
|
||||
ps_params[0].length = 0;
|
||||
ps_params[0].is_null = 0;
|
||||
|
||||
ps_params[1].buffer_type = MYSQL_TYPE_LONG;
|
||||
ps_params[1].buffer = (char *) &int_data[1];
|
||||
ps_params[1].length = 0;
|
||||
ps_params[1].is_null = 0;
|
||||
|
||||
ps_params[2].buffer_type = MYSQL_TYPE_LONG;
|
||||
ps_params[2].buffer = (char *) &int_data[2];
|
||||
ps_params[2].length = 0;
|
||||
ps_params[2].is_null = 0;
|
||||
|
||||
/* bind parameters */
|
||||
rc = mysql_stmt_bind_param(stmt, ps_params);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
/* assign values to parameters and execute statement */
|
||||
int_data[0]= 10; /* p_in */
|
||||
int_data[1]= 20; /* p_out */
|
||||
int_data[2]= 30; /* p_inout */
|
||||
|
||||
rc = mysql_stmt_execute(stmt);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
rc= mysql_stmt_execute(stmt);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
mysql_stmt_close(stmt);
|
||||
|
||||
rc = mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1");
|
||||
check_mysql_rc(rc, mysql);
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int test_prepare_error(MYSQL *mysql)
|
||||
{
|
||||
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
|
||||
int rc;
|
||||
|
||||
rc= mysql_stmt_prepare(stmt, "SELECT 1 FROM tbl_not_exists", -1);
|
||||
FAIL_IF(!rc, "Expected error");
|
||||
|
||||
rc= mysql_stmt_reset(stmt);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
rc= mysql_stmt_prepare(stmt, "SELECT 1 FROM tbl_not_exists", -1);
|
||||
FAIL_IF(!rc, "Expected error");
|
||||
|
||||
rc= mysql_stmt_reset(stmt);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
rc= mysql_stmt_prepare(stmt, "SET @a:=1", -1);
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
||||
mysql_stmt_close(stmt);
|
||||
return OK;
|
||||
}
|
||||
|
||||
struct my_tests_st my_tests[] = {
|
||||
{"test_prepare_error", test_prepare_error, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
{"test_reexecute", test_reexecute, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
{"test_bit2tiny", test_bit2tiny, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
{"test_conc97", test_conc97, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
{"test_conc83", test_conc83, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||
|
Reference in New Issue
Block a user