2017-03-09 06:16:53 +01:00
|
|
|
/* Copyright (c) 2017, MariaDB Corporation.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
|
|
|
System Versioning items
|
|
|
|
*/
|
|
|
|
|
2017-11-23 16:57:26 +01:00
|
|
|
#include "mariadb.h"
|
|
|
|
#include "sql_priv.h"
|
|
|
|
|
2017-03-09 06:16:53 +01:00
|
|
|
#include "sql_class.h"
|
|
|
|
#include "tztime.h"
|
2017-03-11 07:09:07 +01:00
|
|
|
#include "item.h"
|
2017-03-09 06:16:53 +01:00
|
|
|
|
2021-04-21 21:14:08 +02:00
|
|
|
bool Item_func_history::val_bool()
|
|
|
|
{
|
|
|
|
Item_field *f= static_cast<Item_field *>(args[0]);
|
2020-08-14 18:51:10 +02:00
|
|
|
DBUG_ASSERT(f->fixed());
|
2021-10-11 12:36:06 +02:00
|
|
|
DBUG_ASSERT(f->field->flags & VERS_ROW_END);
|
2021-04-21 21:14:08 +02:00
|
|
|
return !f->field->is_max();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Item_func_history::print(String *str, enum_query_type query_type)
|
|
|
|
{
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
str->append(func_name_cstring());
|
2021-04-21 21:14:08 +02:00
|
|
|
str->append('(');
|
|
|
|
args[0]->print(str, query_type);
|
|
|
|
str->append(')');
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:53:44 +02:00
|
|
|
Item_func_trt_ts::Item_func_trt_ts(THD *thd, Item* a, TR_table::field_id_t _trt_field) :
|
2017-11-10 15:54:46 +01:00
|
|
|
Item_datetimefunc(thd, a),
|
2018-04-17 08:53:44 +02:00
|
|
|
trt_field(_trt_field)
|
2017-03-09 06:16:53 +01:00
|
|
|
{
|
|
|
|
decimals= 6;
|
|
|
|
null_value= true;
|
|
|
|
DBUG_ASSERT(arg_count == 1 && args[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2018-09-28 12:01:17 +02:00
|
|
|
Item_func_trt_ts::get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate)
|
2017-03-09 06:16:53 +01:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(thd);
|
2017-08-03 09:11:49 +02:00
|
|
|
DBUG_ASSERT(args[0]);
|
|
|
|
if (args[0]->result_type() != INT_RESULT)
|
|
|
|
{
|
|
|
|
my_error(ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION, MYF(0),
|
|
|
|
args[0]->type_handler()->name().ptr(),
|
|
|
|
func_name());
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-09 06:16:53 +01:00
|
|
|
ulonglong trx_id= args[0]->val_uint();
|
|
|
|
if (trx_id == ULONGLONG_MAX)
|
|
|
|
{
|
|
|
|
null_value= false;
|
|
|
|
thd->variables.time_zone->gmt_sec_to_TIME(res, TIMESTAMP_MAX_VALUE);
|
2017-08-18 13:29:22 +02:00
|
|
|
res->second_part= TIME_MAX_SECOND_PART;
|
2017-03-09 06:16:53 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-10 15:54:46 +01:00
|
|
|
TR_table trt(thd);
|
|
|
|
|
|
|
|
null_value= !trt.query(trx_id);
|
2017-08-03 09:11:49 +02:00
|
|
|
if (null_value)
|
2017-11-10 15:54:46 +01:00
|
|
|
return true;
|
2017-03-09 06:16:53 +01:00
|
|
|
|
2018-09-28 12:01:17 +02:00
|
|
|
return trt[trt_field]->get_date(res, fuzzydate);
|
2017-03-09 06:16:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-17 08:53:44 +02:00
|
|
|
Item_func_trt_id::Item_func_trt_id(THD *thd, Item* a, TR_table::field_id_t _trt_field,
|
2017-11-10 15:54:46 +01:00
|
|
|
bool _backwards) :
|
|
|
|
Item_longlong_func(thd, a),
|
2018-04-17 08:53:44 +02:00
|
|
|
trt_field(_trt_field),
|
2017-03-09 06:16:53 +01:00
|
|
|
backwards(_backwards)
|
|
|
|
{
|
|
|
|
decimals= 0;
|
|
|
|
unsigned_flag= 1;
|
|
|
|
null_value= true;
|
|
|
|
DBUG_ASSERT(arg_count == 1 && args[0]);
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:53:44 +02:00
|
|
|
Item_func_trt_id::Item_func_trt_id(THD *thd, Item* a, Item* b, TR_table::field_id_t _trt_field) :
|
2017-11-10 15:54:46 +01:00
|
|
|
Item_longlong_func(thd, a, b),
|
2018-04-17 08:53:44 +02:00
|
|
|
trt_field(_trt_field),
|
2017-03-09 06:16:53 +01:00
|
|
|
backwards(false)
|
|
|
|
{
|
|
|
|
decimals= 0;
|
|
|
|
unsigned_flag= 1;
|
|
|
|
null_value= true;
|
|
|
|
DBUG_ASSERT(arg_count == 2 && args[0] && args[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
longlong
|
2018-04-17 08:53:44 +02:00
|
|
|
Item_func_trt_id::get_by_trx_id(ulonglong trx_id)
|
2017-03-09 06:16:53 +01:00
|
|
|
{
|
2017-11-10 15:54:46 +01:00
|
|
|
THD *thd= current_thd;
|
2017-03-09 06:16:53 +01:00
|
|
|
DBUG_ASSERT(thd);
|
|
|
|
|
|
|
|
if (trx_id == ULONGLONG_MAX)
|
|
|
|
{
|
|
|
|
null_value= true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-10 15:54:46 +01:00
|
|
|
TR_table trt(thd);
|
|
|
|
null_value= !trt.query(trx_id);
|
|
|
|
if (null_value)
|
|
|
|
return 0;
|
|
|
|
|
2018-04-17 08:53:44 +02:00
|
|
|
return trt[trt_field]->val_int();
|
2017-03-09 06:16:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
longlong
|
2018-04-17 08:53:44 +02:00
|
|
|
Item_func_trt_id::get_by_commit_ts(MYSQL_TIME &commit_ts, bool backwards)
|
2017-03-09 06:16:53 +01:00
|
|
|
{
|
2017-11-10 15:54:46 +01:00
|
|
|
THD *thd= current_thd;
|
2017-03-09 06:16:53 +01:00
|
|
|
DBUG_ASSERT(thd);
|
|
|
|
|
2017-11-10 15:54:46 +01:00
|
|
|
TR_table trt(thd);
|
|
|
|
null_value= !trt.query(commit_ts, backwards);
|
2017-03-09 06:16:53 +01:00
|
|
|
if (null_value)
|
2018-04-25 16:13:20 +02:00
|
|
|
return backwards ? ULONGLONG_MAX : 0;
|
2017-03-09 06:16:53 +01:00
|
|
|
|
2018-04-17 08:53:44 +02:00
|
|
|
return trt[trt_field]->val_int();
|
2017-03-09 06:16:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
longlong
|
2018-04-17 08:53:44 +02:00
|
|
|
Item_func_trt_id::val_int()
|
2017-03-09 06:16:53 +01:00
|
|
|
{
|
|
|
|
if (args[0]->is_null())
|
|
|
|
{
|
2018-04-17 08:53:44 +02:00
|
|
|
if (arg_count < 2 || trt_field == TR_table::FLD_TRX_ID)
|
2017-03-09 06:16:53 +01:00
|
|
|
{
|
|
|
|
null_value= true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return get_by_trx_id(args[1]->val_uint());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MYSQL_TIME commit_ts;
|
2018-11-23 16:04:42 +01:00
|
|
|
THD *thd= current_thd;
|
|
|
|
Datetime::Options opt(TIME_CONV_NONE, thd);
|
|
|
|
if (args[0]->get_date(thd, &commit_ts, opt))
|
2017-03-09 06:16:53 +01:00
|
|
|
{
|
|
|
|
null_value= true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (arg_count > 1)
|
|
|
|
{
|
|
|
|
backwards= args[1]->val_bool();
|
|
|
|
DBUG_ASSERT(arg_count == 2);
|
|
|
|
}
|
|
|
|
return get_by_commit_ts(commit_ts, backwards);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:53:44 +02:00
|
|
|
Item_func_trt_trx_sees::Item_func_trt_trx_sees(THD *thd, Item* a, Item* b) :
|
2017-11-10 15:54:46 +01:00
|
|
|
Item_bool_func(thd, a, b),
|
2017-03-09 06:16:53 +01:00
|
|
|
accept_eq(false)
|
|
|
|
{
|
|
|
|
null_value= true;
|
|
|
|
DBUG_ASSERT(arg_count == 2 && args[0] && args[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
longlong
|
2018-04-17 08:53:44 +02:00
|
|
|
Item_func_trt_trx_sees::val_int()
|
2017-03-09 06:16:53 +01:00
|
|
|
{
|
|
|
|
THD *thd= current_thd;
|
|
|
|
DBUG_ASSERT(thd);
|
|
|
|
|
|
|
|
DBUG_ASSERT(arg_count > 1);
|
2017-11-10 15:54:46 +01:00
|
|
|
ulonglong trx_id1= args[0]->val_uint();
|
|
|
|
ulonglong trx_id0= args[1]->val_uint();
|
|
|
|
bool result= accept_eq;
|
2017-03-09 06:16:53 +01:00
|
|
|
|
2017-11-10 15:54:46 +01:00
|
|
|
TR_table trt(thd);
|
|
|
|
null_value= trt.query_sees(result, trx_id1, trx_id0);
|
2017-03-09 06:16:53 +01:00
|
|
|
return result;
|
|
|
|
}
|