1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

Merge 10.5 into 10.6

This commit is contained in:
Marko Mäkelä
2023-09-11 14:46:39 +03:00
98 changed files with 1125 additions and 22817 deletions

View File

@@ -6305,6 +6305,318 @@ static void test_date_dt()
test_bind_date_conv(2);
}
static void test_simple_temporal() {
MYSQL_STMT *stmt = NULL;
uint rc;
ulong length = 0;
MYSQL_BIND my_bind[4], my_bind2;
my_bool is_null = FALSE;
MYSQL_TIME tm;
char string[100];
MYSQL_RES *rs;
MYSQL_FIELD *field;
myheader("test_simple_temporal");
/* Initialize param/fetch buffers for data, null flags, lengths */
memset(&my_bind, 0, sizeof(my_bind));
memset(&my_bind2, 0, sizeof(my_bind2));
/* Initialize the first input parameter */
my_bind[0].buffer_type = MYSQL_TYPE_DATETIME;
my_bind[0].buffer = &tm;
my_bind[0].is_null = &is_null;
my_bind[0].length = &length;
my_bind[0].buffer_length = sizeof(tm);
/* Clone the other input parameters */
my_bind[3] = my_bind[2] = my_bind[1] = my_bind[0];
my_bind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
my_bind[2].buffer_type = MYSQL_TYPE_DATE;
my_bind[3].buffer_type = MYSQL_TYPE_TIME;
/* Initialize fetch parameter */
my_bind2.buffer_type = MYSQL_TYPE_STRING;
my_bind2.length = &length;
my_bind2.is_null = &is_null;
my_bind2.buffer_length = sizeof(string);
my_bind2.buffer = string;
/* Prepare and bind simple SELECT with DATETIME parameter */
stmt = mysql_simple_prepare(mysql, "SELECT ?");
check_stmt(stmt);
verify_param_count(stmt, 1);
rc = mysql_stmt_bind_param(stmt, &my_bind[0]);
check_execute(stmt, rc);
rc = mysql_stmt_bind_result(stmt, &my_bind2);
check_execute(stmt, rc);
/* Initialize DATETIME value */
tm.neg = FALSE;
tm.time_type = MYSQL_TIMESTAMP_DATETIME;
tm.year = 2001;
tm.month = 10;
tm.day = 20;
tm.hour = 10;
tm.minute = 10;
tm.second = 59;
tm.second_part = 500000;
/* Execute and fetch */
rc = mysql_stmt_execute(stmt);
check_execute(stmt, rc);
rs = mysql_stmt_result_metadata(stmt);
field = mysql_fetch_fields(rs);
rc = mysql_stmt_store_result(stmt);
check_execute(stmt, rc);
rc = mysql_stmt_fetch(stmt);
check_execute(stmt, rc);
DIE_UNLESS(field->type == MYSQL_TYPE_DATETIME);
DIE_UNLESS(strcmp(string, "2001-10-20 10:10:59.500000") == 0);
mysql_free_result(rs);
mysql_stmt_close(stmt);
/* Same test with explicit CAST */
stmt = mysql_simple_prepare(mysql, "SELECT CAST(? AS DATETIME(6))");
check_stmt(stmt);
verify_param_count(stmt, 1);
rc = mysql_stmt_bind_param(stmt, &my_bind[0]);
check_execute(stmt, rc);
rc = mysql_stmt_bind_result(stmt, &my_bind2);
check_execute(stmt, rc);
/* Execute and fetch */
rc = mysql_stmt_execute(stmt);
check_execute(stmt, rc);
rs = mysql_stmt_result_metadata(stmt);
field = mysql_fetch_fields(rs);
rc = mysql_stmt_store_result(stmt);
check_execute(stmt, rc);
rc = mysql_stmt_fetch(stmt);
check_execute(stmt, rc);
DIE_UNLESS(field->type == MYSQL_TYPE_DATETIME);
DIE_UNLESS(strcmp(string, "2001-10-20 10:10:59.500000") == 0);
mysql_free_result(rs);
mysql_stmt_close(stmt);
/* Prepare and bind simple SELECT with TIMESTAMP parameter */
stmt = mysql_simple_prepare(mysql, "SELECT ?");
check_stmt(stmt);
verify_param_count(stmt, 1);
rc = mysql_stmt_bind_param(stmt, &my_bind[1]);
check_execute(stmt, rc);
rc = mysql_stmt_bind_result(stmt, &my_bind2);
check_execute(stmt, rc);
/* Initialize TIMESTAMP value */
tm.neg = FALSE;
tm.time_type = MYSQL_TIMESTAMP_DATETIME;
tm.year = 2001;
tm.month = 10;
tm.day = 20;
tm.hour = 10;
tm.minute = 10;
tm.second = 59;
tm.second_part = 500000;
/* Execute and fetch */
rc = mysql_stmt_execute(stmt);
check_execute(stmt, rc);
rs = mysql_stmt_result_metadata(stmt);
field = mysql_fetch_fields(rs);
rc = mysql_stmt_store_result(stmt);
check_execute(stmt, rc);
rc = mysql_stmt_fetch(stmt);
check_execute(stmt, rc);
DIE_UNLESS(field->type == MYSQL_TYPE_TIMESTAMP);
DIE_UNLESS(strcmp(string, "2001-10-20 10:10:59.500000") == 0);
mysql_free_result(rs);
mysql_stmt_close(stmt);
/* Prepare and bind simple SELECT with DATE parameter */
stmt = mysql_simple_prepare(mysql, "SELECT ?");
check_stmt(stmt);
verify_param_count(stmt, 1);
rc = mysql_stmt_bind_param(stmt, &my_bind[2]);
check_execute(stmt, rc);
rc = mysql_stmt_bind_result(stmt, &my_bind2);
check_execute(stmt, rc);
/* Initialize DATE value */
tm.neg = FALSE;
tm.time_type = MYSQL_TIMESTAMP_DATE;
tm.year = 2001;
tm.month = 10;
tm.day = 20;
tm.hour = 0;
tm.minute = 0;
tm.second = 0;
tm.second_part = 0;
/* Execute and fetch */
rc = mysql_stmt_execute(stmt);
check_execute(stmt, rc);
rs = mysql_stmt_result_metadata(stmt);
field = mysql_fetch_fields(rs);
rc = mysql_stmt_store_result(stmt);
check_execute(stmt, rc);
rc = mysql_stmt_fetch(stmt);
check_execute(stmt, rc);
DIE_UNLESS(field->type == MYSQL_TYPE_DATE);
DIE_UNLESS(strcmp(string, "2001-10-20") == 0);
mysql_free_result(rs);
mysql_stmt_close(stmt);
/* Same test with explicit CAST */
stmt = mysql_simple_prepare(mysql, "SELECT CAST(? AS DATE)");
check_stmt(stmt);
verify_param_count(stmt, 1);
rc = mysql_stmt_bind_param(stmt, &my_bind[2]);
check_execute(stmt, rc);
rc = mysql_stmt_bind_result(stmt, &my_bind2);
check_execute(stmt, rc);
/* Execute and fetch */
rc = mysql_stmt_execute(stmt);
check_execute(stmt, rc);
rs = mysql_stmt_result_metadata(stmt);
field = mysql_fetch_fields(rs);
rc = mysql_stmt_store_result(stmt);
check_execute(stmt, rc);
rc = mysql_stmt_fetch(stmt);
check_execute(stmt, rc);
DIE_UNLESS(field->type == MYSQL_TYPE_DATE);
DIE_UNLESS(strcmp(string, "2001-10-20") == 0);
mysql_free_result(rs);
mysql_stmt_close(stmt);
/* Prepare and bind simple SELECT with TIME parameter */
stmt = mysql_simple_prepare(mysql, "SELECT ?");
check_stmt(stmt);
verify_param_count(stmt, 1);
rc = mysql_stmt_bind_param(stmt, &my_bind[3]);
check_execute(stmt, rc);
rc = mysql_stmt_bind_result(stmt, &my_bind2);
check_execute(stmt, rc);
/* Initialize TIME value */
tm.neg = FALSE;
tm.time_type = MYSQL_TIMESTAMP_TIME;
tm.year = 0;
tm.month = 0;
tm.day = 0;
tm.hour = 10;
tm.minute = 10;
tm.second = 59;
tm.second_part = 500000;
/* Execute and fetch */
rc = mysql_stmt_execute(stmt);
check_execute(stmt, rc);
rs = mysql_stmt_result_metadata(stmt);
field = mysql_fetch_fields(rs);
rc = mysql_stmt_store_result(stmt);
check_execute(stmt, rc);
rc = mysql_stmt_fetch(stmt);
check_execute(stmt, rc);
DIE_UNLESS(field->type == MYSQL_TYPE_TIME);
DIE_UNLESS(strcmp(string, "10:10:59.500000") == 0);
mysql_free_result(rs);
mysql_stmt_close(stmt);
/* Same test with explicit CAST */
stmt = mysql_simple_prepare(mysql, "SELECT CAST(? AS TIME(6))");
check_stmt(stmt);
verify_param_count(stmt, 1);
rc = mysql_stmt_bind_param(stmt, &my_bind[3]);
check_execute(stmt, rc);
rc = mysql_stmt_bind_result(stmt, &my_bind2);
check_execute(stmt, rc);
/* Initialize TIME value */
tm.neg = FALSE;
tm.time_type = MYSQL_TIMESTAMP_TIME;
tm.year = 0;
tm.month = 0;
tm.day = 0;
tm.hour = 10;
tm.minute = 10;
tm.second = 59;
tm.second_part = 500000;
/* Execute and fetch */
rc = mysql_stmt_execute(stmt);
check_execute(stmt, rc);
rs = mysql_stmt_result_metadata(stmt);
field = mysql_fetch_fields(rs);
rc = mysql_stmt_store_result(stmt);
check_execute(stmt, rc);
rc = mysql_stmt_fetch(stmt);
check_execute(stmt, rc);
DIE_UNLESS(field->type == MYSQL_TYPE_TIME);
DIE_UNLESS(strcmp(string, "10:10:59.500000") == 0);
mysql_free_result(rs);
mysql_stmt_close(stmt);
}
/* Misc tests to keep pure coverage happy */
@@ -21830,6 +22142,7 @@ static struct my_tests_st my_tests[]= {
{ "test_store_result2", test_store_result2 },
{ "test_subselect", test_subselect },
{ "test_date", test_date },
{ "test_simple_temporal", test_simple_temporal },
{ "test_date_date", test_date_date },
{ "test_date_time", test_date_time },
{ "test_date_ts", test_date_ts },