2016-10-19 14:10:03 +04:00
|
|
|
#ifndef ITEM_JSONFUNC_INCLUDED
|
|
|
|
#define ITEM_JSONFUNC_INCLUDED
|
|
|
|
|
2021-06-29 15:02:10 +03:00
|
|
|
/* Copyright (c) 2016, 2021, MariaDB
|
2016-10-19 14:10:03 +04:00
|
|
|
|
|
|
|
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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
|
|
|
|
|
|
|
|
|
|
/* This file defines all JSON functions */
|
|
|
|
|
|
|
|
|
|
|
|
#include <json_lib.h>
|
|
|
|
#include "item_cmpfunc.h" // Item_bool_func
|
|
|
|
#include "item_strfunc.h" // Item_str_func
|
2019-07-04 13:12:08 +03:00
|
|
|
#include "item_sum.h"
|
2022-01-10 18:05:55 +04:00
|
|
|
#include "sql_type_json.h"
|
2022-10-28 13:03:13 +05:30
|
|
|
#include "json_schema.h"
|
2016-10-19 14:10:03 +04:00
|
|
|
|
|
|
|
class json_path_with_flags
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
json_path_t p;
|
|
|
|
bool constant;
|
|
|
|
bool parsed;
|
|
|
|
json_path_step_t *cur_step;
|
|
|
|
void set_constant_flag(bool s_constant)
|
|
|
|
{
|
|
|
|
constant= s_constant;
|
|
|
|
parsed= FALSE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-03-17 09:03:45 +04:00
|
|
|
void report_path_error_ex(const char *ps, json_path_t *p,
|
|
|
|
const char *fname, int n_param,
|
|
|
|
Sql_condition::enum_warning_level lv);
|
|
|
|
void report_json_error_ex(const char *js, json_engine_t *je,
|
|
|
|
const char *fname, int n_param,
|
|
|
|
Sql_condition::enum_warning_level lv);
|
|
|
|
|
2019-06-28 12:35:02 +04:00
|
|
|
class Json_engine_scan: public json_engine_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Json_engine_scan(CHARSET_INFO *i_cs, const uchar *str, const uchar *end)
|
|
|
|
{
|
|
|
|
json_scan_start(this, i_cs, str, end);
|
|
|
|
}
|
|
|
|
Json_engine_scan(const String &str)
|
|
|
|
:Json_engine_scan(str.charset(), (const uchar *) str.ptr(),
|
|
|
|
(const uchar *) str.end())
|
|
|
|
{ }
|
|
|
|
bool check_and_get_value_scalar(String *res, int *error);
|
2023-05-25 15:45:43 +05:30
|
|
|
bool check_and_get_value_complex(String *res, int *error,
|
|
|
|
json_value_types cur_value_type=
|
|
|
|
JSON_VALUE_UNINITIALIZED);
|
2019-06-28 12:35:02 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Json_path_extractor: public json_path_with_flags
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp_js, tmp_path;
|
|
|
|
virtual ~Json_path_extractor() { }
|
|
|
|
virtual bool check_and_get_value(Json_engine_scan *je,
|
|
|
|
String *to, int *error)=0;
|
|
|
|
bool extract(String *to, Item *js, Item *jp, CHARSET_INFO *cs);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-20 16:29:11 +04:00
|
|
|
class Item_func_json_valid: public Item_bool_func
|
2016-10-19 14:10:03 +04:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp_value;
|
|
|
|
|
|
|
|
public:
|
2017-05-20 16:29:11 +04:00
|
|
|
Item_func_json_valid(THD *thd, Item *json) : Item_bool_func(thd, json) {}
|
2024-05-14 09:19:34 +04:00
|
|
|
bool val_bool() override;
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_valid") };
|
|
|
|
return name;
|
|
|
|
}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override
|
2016-10-19 14:10:03 +04:00
|
|
|
{
|
2022-01-26 03:02:45 +05:30
|
|
|
if (Item_bool_func::fix_length_and_dec(thd))
|
2018-05-08 15:26:26 +02:00
|
|
|
return TRUE;
|
2020-09-02 03:13:32 +03:00
|
|
|
set_maybe_null();
|
2018-05-08 15:26:26 +02:00
|
|
|
return FALSE;
|
2016-10-19 14:10:03 +04:00
|
|
|
}
|
2020-03-10 16:05:42 +04:00
|
|
|
bool set_format_by_check_constraint(Send_field_extended_metadata *to) const
|
2020-08-19 02:53:22 +03:00
|
|
|
override
|
2020-03-10 16:05:42 +04:00
|
|
|
{
|
|
|
|
static const Lex_cstring fmt(STRING_WITH_LEN("json"));
|
|
|
|
return to->set_format_name(fmt);
|
|
|
|
}
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_valid>(thd, this); }
|
2020-08-19 02:53:22 +03:00
|
|
|
enum Functype functype() const override { return JSON_VALID_FUNC; }
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-07-02 08:20:37 +02:00
|
|
|
class Item_func_json_equals: public Item_bool_func
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Item_func_json_equals(THD *thd, Item *a, Item *b):
|
|
|
|
Item_bool_func(thd, a, b) {}
|
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_equals") };
|
|
|
|
return name;
|
|
|
|
}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2024-07-20 08:16:24 +02:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2021-07-02 08:20:37 +02:00
|
|
|
{ return get_item_copy<Item_func_json_equals>(thd, this); }
|
2024-10-29 15:24:38 +01:00
|
|
|
bool val_bool() override;
|
2021-07-02 08:20:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-20 16:29:11 +04:00
|
|
|
class Item_func_json_exists: public Item_bool_func
|
2016-10-19 14:10:03 +04:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
json_path_with_flags path;
|
|
|
|
String tmp_js, tmp_path;
|
|
|
|
|
|
|
|
public:
|
2016-12-24 11:40:31 +04:00
|
|
|
Item_func_json_exists(THD *thd, Item *js, Item *i_path):
|
2017-05-20 16:29:11 +04:00
|
|
|
Item_bool_func(thd, js, i_path) {}
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_exists") };
|
|
|
|
return name;
|
|
|
|
}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_exists>(thd, this); }
|
2024-05-14 09:19:34 +04:00
|
|
|
bool val_bool() override;
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-06-28 12:35:02 +04:00
|
|
|
class Item_json_func: public Item_str_func
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Item_json_func(THD *thd)
|
|
|
|
:Item_str_func(thd) { }
|
|
|
|
Item_json_func(THD *thd, Item *a)
|
|
|
|
:Item_str_func(thd, a) { }
|
|
|
|
Item_json_func(THD *thd, Item *a, Item *b)
|
|
|
|
:Item_str_func(thd, a, b) { }
|
|
|
|
Item_json_func(THD *thd, List<Item> &list)
|
|
|
|
:Item_str_func(thd, list) { }
|
2022-01-10 18:05:55 +04:00
|
|
|
const Type_handler *type_handler() const override
|
2020-03-10 16:05:42 +04:00
|
|
|
{
|
2022-01-10 18:05:55 +04:00
|
|
|
return Type_handler_json_common::json_type_handler(max_length);
|
2020-03-10 16:05:42 +04:00
|
|
|
}
|
2019-06-28 12:35:02 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Item_func_json_value: public Item_str_func,
|
|
|
|
public Json_path_extractor
|
2016-10-19 14:10:03 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2016-12-24 11:40:31 +04:00
|
|
|
Item_func_json_value(THD *thd, Item *js, Item *i_path):
|
|
|
|
Item_str_func(thd, js, i_path) {}
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_value") };
|
|
|
|
return name;
|
|
|
|
}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override ;
|
2019-06-29 23:53:09 +02:00
|
|
|
String *val_str(String *to) override
|
2019-06-28 12:35:02 +04:00
|
|
|
{
|
|
|
|
null_value= Json_path_extractor::extract(to, args[0], args[1],
|
|
|
|
collation.collation);
|
|
|
|
return null_value ? NULL : to;
|
|
|
|
}
|
|
|
|
bool check_and_get_value(Json_engine_scan *je,
|
|
|
|
String *res, int *error) override
|
|
|
|
{
|
|
|
|
return je->check_and_get_value_scalar(res, error);
|
|
|
|
}
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_value>(thd, this); }
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-06-28 12:35:02 +04:00
|
|
|
class Item_func_json_query: public Item_json_func,
|
|
|
|
public Json_path_extractor
|
2016-10-19 14:10:03 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-12-24 11:40:31 +04:00
|
|
|
Item_func_json_query(THD *thd, Item *js, Item *i_path):
|
2019-06-28 12:35:02 +04:00
|
|
|
Item_json_func(thd, js, i_path) {}
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_query") };
|
|
|
|
return name;
|
|
|
|
}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2019-06-29 23:53:09 +02:00
|
|
|
String *val_str(String *to) override
|
2019-06-28 12:35:02 +04:00
|
|
|
{
|
|
|
|
null_value= Json_path_extractor::extract(to, args[0], args[1],
|
|
|
|
collation.collation);
|
|
|
|
return null_value ? NULL : to;
|
|
|
|
}
|
|
|
|
bool check_and_get_value(Json_engine_scan *je,
|
|
|
|
String *res, int *error) override
|
|
|
|
{
|
2023-05-25 15:45:43 +05:30
|
|
|
return je->check_and_get_value_complex(res, error, JSON_VALUE_UNINITIALIZED);
|
2019-06-28 12:35:02 +04:00
|
|
|
}
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_query>(thd, this); }
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Item_func_json_quote: public Item_str_func
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp_s;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Item_func_json_quote(THD *thd, Item *s): Item_str_func(thd, s) {}
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_quote") };
|
|
|
|
return name;
|
|
|
|
}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override;
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_quote>(thd, this); }
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-11-15 17:04:31 +04:00
|
|
|
class Item_func_json_unquote: public Item_str_func
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp_s;
|
2017-08-08 10:35:26 +04:00
|
|
|
String *read_json(json_engine_t *je);
|
2016-11-15 17:04:31 +04:00
|
|
|
public:
|
|
|
|
Item_func_json_unquote(THD *thd, Item *s): Item_str_func(thd, s) {}
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_unquote") };
|
|
|
|
return name;
|
|
|
|
}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override;
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_unquote>(thd, this); }
|
2016-11-15 17:04:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-06-28 12:35:02 +04:00
|
|
|
class Item_json_str_multipath: public Item_json_func
|
2016-10-19 14:10:03 +04:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
json_path_with_flags *paths;
|
|
|
|
String *tmp_paths;
|
2023-11-10 17:46:19 +07:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
Number of paths returned by calling virtual method get_n_paths() and
|
|
|
|
remembered inside fix_fields(). It is used by the virtual destructor
|
|
|
|
~Item_json_str_multipath() to iterate along allocated memory chunks stored
|
|
|
|
in the array tmp_paths and free every of them. The virtual method
|
|
|
|
get_n_paths() can't be used for this goal from within virtual destructor.
|
|
|
|
We could get rid of the virtual method get_n_paths() and store the number
|
|
|
|
of paths directly in the constructor of classes derived from the class
|
|
|
|
Item_json_str_multipath but presence of the method get_n_paths() allows
|
|
|
|
to check invariant that the number of arguments not changed between
|
|
|
|
sequential runs of the same prepared statement that seems to be useful.
|
|
|
|
*/
|
|
|
|
uint n_paths;
|
2016-10-19 14:10:03 +04:00
|
|
|
public:
|
|
|
|
Item_json_str_multipath(THD *thd, List<Item> &list):
|
2023-12-01 13:43:58 +01:00
|
|
|
Item_json_func(thd, list), paths(NULL), tmp_paths(0), n_paths(0) {}
|
2023-11-10 17:46:19 +07:00
|
|
|
virtual ~Item_json_str_multipath();
|
|
|
|
|
2024-06-12 09:46:26 -04:00
|
|
|
bool fix_fields(THD *thd, Item **ref) override;
|
2016-10-19 14:10:03 +04:00
|
|
|
virtual uint get_n_paths() const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Item_func_json_extract: public Item_json_str_multipath
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp_js;
|
|
|
|
public:
|
2017-08-11 00:50:29 +04:00
|
|
|
String *read_json(String *str, json_value_types *type,
|
|
|
|
char **out_val, int *value_len);
|
2016-10-19 14:10:03 +04:00
|
|
|
Item_func_json_extract(THD *thd, List<Item> &list):
|
|
|
|
Item_json_str_multipath(thd, list) {}
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_extract") };
|
|
|
|
return name;
|
|
|
|
}
|
2020-08-19 02:53:22 +03:00
|
|
|
enum Functype functype() const override { return JSON_EXTRACT_FUNC; }
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override;
|
|
|
|
longlong val_int() override;
|
|
|
|
double val_real() override;
|
|
|
|
my_decimal *val_decimal(my_decimal *) override;
|
|
|
|
uint get_n_paths() const override { return arg_count - 1; }
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_extract>(thd, this); }
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-20 16:29:11 +04:00
|
|
|
class Item_func_json_contains: public Item_bool_func
|
2016-10-19 14:10:03 +04:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp_js;
|
2016-12-11 01:12:33 +04:00
|
|
|
json_path_with_flags path;
|
|
|
|
String tmp_path;
|
2016-10-19 14:10:03 +04:00
|
|
|
bool a2_constant, a2_parsed;
|
|
|
|
String tmp_val, *val;
|
|
|
|
public:
|
|
|
|
Item_func_json_contains(THD *thd, List<Item> &list):
|
2017-05-20 16:29:11 +04:00
|
|
|
Item_bool_func(thd, list) {}
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_contains") };
|
|
|
|
return name;
|
|
|
|
}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2024-05-14 09:19:34 +04:00
|
|
|
bool val_bool() override;
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_contains>(thd, this); }
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-20 16:29:11 +04:00
|
|
|
class Item_func_json_contains_path: public Item_bool_func
|
2016-10-19 14:10:03 +04:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp_js;
|
|
|
|
json_path_with_flags *paths;
|
|
|
|
String *tmp_paths;
|
|
|
|
bool mode_one;
|
|
|
|
bool ooa_constant, ooa_parsed;
|
2017-01-24 17:34:44 +04:00
|
|
|
bool *p_found;
|
2016-10-19 14:10:03 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
Item_func_json_contains_path(THD *thd, List<Item> &list):
|
2017-05-20 16:29:11 +04:00
|
|
|
Item_bool_func(thd, list), tmp_paths(0) {}
|
2023-11-10 17:46:19 +07:00
|
|
|
virtual ~Item_func_json_contains_path();
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_contains_path") };
|
|
|
|
return name;
|
|
|
|
}
|
2020-08-19 02:53:22 +03:00
|
|
|
bool fix_fields(THD *thd, Item **ref) override;
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2024-05-14 09:19:34 +04:00
|
|
|
bool val_bool() override;
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_contains_path>(thd, this); }
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-06-28 12:35:02 +04:00
|
|
|
class Item_func_json_array: public Item_json_func
|
2016-10-19 14:10:03 +04:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp_val;
|
2017-03-14 17:31:14 +04:00
|
|
|
ulong result_limit;
|
2016-10-19 14:10:03 +04:00
|
|
|
public:
|
|
|
|
Item_func_json_array(THD *thd):
|
2019-06-28 12:35:02 +04:00
|
|
|
Item_json_func(thd) {}
|
2016-10-19 14:10:03 +04:00
|
|
|
Item_func_json_array(THD *thd, List<Item> &list):
|
2019-06-28 12:35:02 +04:00
|
|
|
Item_json_func(thd, list) {}
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override;
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_array") };
|
|
|
|
return name;
|
|
|
|
}
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_array>(thd, this); }
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Item_func_json_array_append: public Item_json_str_multipath
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp_js;
|
|
|
|
String tmp_val;
|
|
|
|
public:
|
|
|
|
Item_func_json_array_append(THD *thd, List<Item> &list):
|
|
|
|
Item_json_str_multipath(thd, list) {}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override;
|
|
|
|
uint get_n_paths() const override { return arg_count/2; }
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_array_append") };
|
|
|
|
return name;
|
|
|
|
}
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_array_append>(thd, this); }
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-11-15 17:04:31 +04:00
|
|
|
class Item_func_json_array_insert: public Item_func_json_array_append
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Item_func_json_array_insert(THD *thd, List<Item> &list):
|
|
|
|
Item_func_json_array_append(thd, list) {}
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override;
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_array_insert") };
|
|
|
|
return name;
|
|
|
|
}
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_array_insert>(thd, this); }
|
2016-11-15 17:04:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-10-19 14:10:03 +04:00
|
|
|
class Item_func_json_object: public Item_func_json_array
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Item_func_json_object(THD *thd):
|
|
|
|
Item_func_json_array(thd) {}
|
|
|
|
Item_func_json_object(THD *thd, List<Item> &list):
|
|
|
|
Item_func_json_array(thd, list) {}
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override;
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_object") };
|
|
|
|
return name;
|
|
|
|
}
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_object>(thd, this); }
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Item_func_json_merge: public Item_func_json_array
|
|
|
|
{
|
|
|
|
protected:
|
2016-12-06 01:32:13 +04:00
|
|
|
String tmp_js1, tmp_js2;
|
2016-10-19 14:10:03 +04:00
|
|
|
public:
|
|
|
|
Item_func_json_merge(THD *thd, List<Item> &list):
|
|
|
|
Item_func_json_array(thd, list) {}
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override;
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_merge_preserve") };
|
|
|
|
return name;
|
|
|
|
}
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_merge>(thd, this); }
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
2019-05-17 11:53:58 +04:00
|
|
|
class Item_func_json_merge_patch: public Item_func_json_merge
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Item_func_json_merge_patch(THD *thd, List<Item> &list):
|
|
|
|
Item_func_json_merge(thd, list) {}
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_merge_patch") };
|
|
|
|
return name;
|
|
|
|
}
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override;
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2019-05-17 17:23:01 +02:00
|
|
|
{ return get_item_copy<Item_func_json_merge_patch>(thd, this); }
|
2019-05-17 11:53:58 +04:00
|
|
|
};
|
2016-10-19 14:10:03 +04:00
|
|
|
|
2021-07-02 08:18:16 +02:00
|
|
|
|
|
|
|
class Item_func_json_normalize: public Item_json_func
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Item_func_json_normalize(THD *thd, Item *a):
|
|
|
|
Item_json_func(thd, a) {}
|
|
|
|
String *val_str(String *) override;
|
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_normalize") };
|
|
|
|
return name;
|
|
|
|
}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2024-07-20 08:16:24 +02:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2021-07-02 08:18:16 +02:00
|
|
|
{ return get_item_copy<Item_func_json_normalize>(thd, this); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
MDEV-26182: Implement JSON_INTERSECT()
The idea is to have simple functions that the user can combine to produce
the exact result one wants, whether the user wants JSON object that has
common keys with another JSON object, or same key/value pair etc. So
making simpler function helps here.
We accomplish this by making three separate functions.
1) JSON_OBJECT_FILTER_KEYS(Obj, Arr_keys):
Put keys ( which are basically strings ) in hash, go over the object and
get key one by one. If the key is present in the hash,
add the key-value pair to result.
2) JSON_OBJECT_TO_ARRAY(Obj) : Create a string variable, Go over the json
object, and add each key value pair as an array into the result.
3) JSON_ARRAY_INTERSECT(arr1, arr2) :
Go over one of the json and add each item of the array
in hash (after normalizing each item). Go over the second array,
search the normalized item one by one in the hash. If item is found,
add it to the result.
Implementation Idea: Holyfoot ( Alexey Botchkov)
Author: tanruixiang and Rucha Deodhar
2022-06-16 15:05:35 +08:00
|
|
|
class Item_func_json_object_to_array: public Item_json_func
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp;
|
|
|
|
public:
|
|
|
|
Item_func_json_object_to_array(THD *thd, Item *a):
|
|
|
|
Item_json_func(thd, a) {}
|
|
|
|
String *val_str(String *) override;
|
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_object_to_array") };
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2024-08-03 09:50:16 +02:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
MDEV-26182: Implement JSON_INTERSECT()
The idea is to have simple functions that the user can combine to produce
the exact result one wants, whether the user wants JSON object that has
common keys with another JSON object, or same key/value pair etc. So
making simpler function helps here.
We accomplish this by making three separate functions.
1) JSON_OBJECT_FILTER_KEYS(Obj, Arr_keys):
Put keys ( which are basically strings ) in hash, go over the object and
get key one by one. If the key is present in the hash,
add the key-value pair to result.
2) JSON_OBJECT_TO_ARRAY(Obj) : Create a string variable, Go over the json
object, and add each key value pair as an array into the result.
3) JSON_ARRAY_INTERSECT(arr1, arr2) :
Go over one of the json and add each item of the array
in hash (after normalizing each item). Go over the second array,
search the normalized item one by one in the hash. If item is found,
add it to the result.
Implementation Idea: Holyfoot ( Alexey Botchkov)
Author: tanruixiang and Rucha Deodhar
2022-06-16 15:05:35 +08:00
|
|
|
{ return get_item_copy<Item_func_json_object_to_array>(thd, this); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-20 16:29:11 +04:00
|
|
|
class Item_func_json_length: public Item_long_func
|
2016-10-19 14:10:03 +04:00
|
|
|
{
|
2020-08-19 02:53:22 +03:00
|
|
|
bool check_arguments() const override
|
2017-10-01 00:30:58 +04:00
|
|
|
{
|
2023-04-11 16:15:19 +03:00
|
|
|
const LEX_CSTRING name= func_name_cstring();
|
2023-02-12 16:40:40 +01:00
|
|
|
if (arg_count == 0 || arg_count > 2)
|
|
|
|
{
|
2023-04-11 16:15:19 +03:00
|
|
|
my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
|
2023-02-12 16:40:40 +01:00
|
|
|
return true;
|
|
|
|
}
|
2023-04-11 16:15:19 +03:00
|
|
|
return args[0]->check_type_can_return_text(name) ||
|
|
|
|
(arg_count > 1 && args[1]->check_type_general_purpose_string(name));
|
2017-10-01 00:30:58 +04:00
|
|
|
}
|
2016-10-19 14:10:03 +04:00
|
|
|
protected:
|
2016-12-24 11:40:31 +04:00
|
|
|
json_path_with_flags path;
|
2016-10-19 14:10:03 +04:00
|
|
|
String tmp_js;
|
|
|
|
String tmp_path;
|
|
|
|
public:
|
|
|
|
Item_func_json_length(THD *thd, List<Item> &list):
|
2017-05-20 16:29:11 +04:00
|
|
|
Item_long_func(thd, list) {}
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_length") };
|
|
|
|
return name;
|
|
|
|
}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2020-08-19 02:53:22 +03:00
|
|
|
longlong val_int() override;
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_length>(thd, this); }
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-20 16:29:11 +04:00
|
|
|
class Item_func_json_depth: public Item_long_func
|
2016-10-19 14:10:03 +04:00
|
|
|
{
|
2020-08-19 02:53:22 +03:00
|
|
|
bool check_arguments() const override
|
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 20:29:55 +03:00
|
|
|
{ return args[0]->check_type_can_return_text(func_name_cstring()); }
|
2016-10-19 14:10:03 +04:00
|
|
|
protected:
|
|
|
|
String tmp_js;
|
|
|
|
public:
|
2017-05-20 16:29:11 +04:00
|
|
|
Item_func_json_depth(THD *thd, Item *js): Item_long_func(thd, js) {}
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_depth") };
|
|
|
|
return name;
|
|
|
|
}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override { max_length= 10; return FALSE; }
|
2020-08-19 02:53:22 +03:00
|
|
|
longlong val_int() override;
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_depth>(thd, this); }
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Item_func_json_type: public Item_str_func
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp_js;
|
|
|
|
public:
|
|
|
|
Item_func_json_type(THD *thd, Item *js): Item_str_func(thd, js) {}
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_type") };
|
|
|
|
return name;
|
|
|
|
}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override;
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_type>(thd, this); }
|
2016-10-19 14:10:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-11-15 17:04:31 +04:00
|
|
|
class Item_func_json_insert: public Item_json_str_multipath
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp_js;
|
|
|
|
String tmp_val;
|
|
|
|
bool mode_insert, mode_replace;
|
|
|
|
public:
|
|
|
|
Item_func_json_insert(bool i_mode, bool r_mode, THD *thd, List<Item> &list):
|
|
|
|
Item_json_str_multipath(thd, list),
|
|
|
|
mode_insert(i_mode), mode_replace(r_mode) {}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override;
|
|
|
|
uint get_n_paths() const override { return arg_count/2; }
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
2016-11-15 17:04:31 +04:00
|
|
|
{
|
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 20:29:55 +03:00
|
|
|
static LEX_CSTRING json_set= {STRING_WITH_LEN("json_set") };
|
|
|
|
static LEX_CSTRING json_insert= {STRING_WITH_LEN("json_insert") };
|
2021-08-19 12:25:00 +03:00
|
|
|
static LEX_CSTRING json_replace= {STRING_WITH_LEN("json_replace") };
|
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 20:29:55 +03:00
|
|
|
return (mode_insert ?
|
2021-08-19 12:25:00 +03:00
|
|
|
(mode_replace ? json_set : json_insert) : json_replace);
|
2016-11-15 17:04:31 +04:00
|
|
|
}
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_insert>(thd, this); }
|
2016-11-15 17:04:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Item_func_json_remove: public Item_json_str_multipath
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp_js;
|
|
|
|
public:
|
|
|
|
Item_func_json_remove(THD *thd, List<Item> &list):
|
|
|
|
Item_json_str_multipath(thd, list) {}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override;
|
|
|
|
uint get_n_paths() const override { return arg_count - 1; }
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_remove") };
|
|
|
|
return name;
|
|
|
|
}
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_remove>(thd, this); }
|
2016-11-15 17:04:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Item_func_json_keys: public Item_str_func
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
json_path_with_flags path;
|
|
|
|
String tmp_js, tmp_path;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Item_func_json_keys(THD *thd, List<Item> &list):
|
|
|
|
Item_str_func(thd, list) {}
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_keys") };
|
|
|
|
return name;
|
|
|
|
}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override;
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_keys>(thd, this); }
|
2016-11-15 17:04:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Item_func_json_search: public Item_json_str_multipath
|
|
|
|
{
|
|
|
|
protected:
|
2018-09-12 21:57:28 +04:00
|
|
|
String tmp_js, tmp_path, esc_value;
|
2016-11-15 17:04:31 +04:00
|
|
|
bool mode_one;
|
|
|
|
bool ooa_constant, ooa_parsed;
|
|
|
|
int escape;
|
|
|
|
int n_path_found;
|
|
|
|
json_path_t sav_path;
|
|
|
|
|
|
|
|
int compare_json_value_wild(json_engine_t *je, const String *cmp_str);
|
|
|
|
|
|
|
|
public:
|
|
|
|
Item_func_json_search(THD *thd, List<Item> &list):
|
|
|
|
Item_json_str_multipath(thd, list) {}
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_search") };
|
|
|
|
return name;
|
|
|
|
}
|
2020-08-19 02:53:22 +03:00
|
|
|
bool fix_fields(THD *thd, Item **ref) override;
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override;
|
|
|
|
uint get_n_paths() const override { return arg_count > 4 ? arg_count - 4 : 0; }
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_search>(thd, this); }
|
2016-11-15 17:04:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-06-28 12:35:02 +04:00
|
|
|
class Item_func_json_format: public Item_json_func
|
2017-02-06 06:47:48 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum formats
|
|
|
|
{
|
|
|
|
NONE,
|
|
|
|
COMPACT,
|
|
|
|
LOOSE,
|
|
|
|
DETAILED
|
|
|
|
};
|
|
|
|
protected:
|
|
|
|
formats fmt;
|
|
|
|
String tmp_js;
|
|
|
|
public:
|
|
|
|
Item_func_json_format(THD *thd, Item *js, formats format):
|
2019-06-28 12:35:02 +04:00
|
|
|
Item_json_func(thd, js), fmt(format) {}
|
2017-02-14 17:51:03 +04:00
|
|
|
Item_func_json_format(THD *thd, List<Item> &list):
|
2019-06-28 12:35:02 +04:00
|
|
|
Item_json_func(thd, list), fmt(DETAILED) {}
|
2017-02-14 17:51:03 +04:00
|
|
|
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override;
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *str) override;
|
|
|
|
String *val_json(String *str) override;
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_func_json_format>(thd, this); }
|
2017-02-06 06:47:48 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-07-04 13:12:08 +03:00
|
|
|
class Item_func_json_arrayagg : public Item_func_group_concat
|
|
|
|
{
|
2020-06-04 10:00:56 +04:00
|
|
|
protected:
|
|
|
|
/*
|
|
|
|
Overrides Item_func_group_concat::skip_nulls()
|
|
|
|
NULL-s should be added to the result as JSON null value.
|
|
|
|
*/
|
2020-08-19 02:53:22 +03:00
|
|
|
bool skip_nulls() const override { return false; }
|
|
|
|
String *get_str_from_item(Item *i, String *tmp) override;
|
2020-06-04 13:53:14 +04:00
|
|
|
String *get_str_from_field(Item *i, Field *f, String *tmp,
|
2020-08-19 02:53:22 +03:00
|
|
|
const uchar *key, size_t offset) override;
|
2020-06-15 22:51:21 +04:00
|
|
|
void cut_max_length(String *result,
|
2020-08-19 02:53:22 +03:00
|
|
|
uint old_length, uint max_length) const override;
|
2019-07-04 13:12:08 +03:00
|
|
|
public:
|
2020-06-04 13:53:14 +04:00
|
|
|
String m_tmp_json; /* Used in get_str_from_*.. */
|
2019-07-04 13:12:08 +03:00
|
|
|
Item_func_json_arrayagg(THD *thd, Name_resolution_context *context_arg,
|
|
|
|
bool is_distinct, List<Item> *is_select,
|
|
|
|
const SQL_I_List<ORDER> &is_order, String *is_separator,
|
|
|
|
bool limit_clause, Item *row_limit, Item *offset_limit):
|
|
|
|
Item_func_group_concat(thd, context_arg, is_distinct, is_select, is_order,
|
|
|
|
is_separator, limit_clause, row_limit, offset_limit)
|
|
|
|
{
|
|
|
|
}
|
2021-06-24 13:28:28 +04:00
|
|
|
Item_func_json_arrayagg(THD *thd, Item_func_json_arrayagg *item) :
|
|
|
|
Item_func_group_concat(thd, item) {}
|
2022-01-10 18:05:55 +04:00
|
|
|
const Type_handler *type_handler() const override
|
|
|
|
{
|
|
|
|
return Type_handler_json_common::json_type_handler_sum(this);
|
|
|
|
}
|
2019-07-04 13:12:08 +03:00
|
|
|
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_arrayagg(") };
|
|
|
|
return name;
|
|
|
|
}
|
2023-11-02 14:57:37 +01:00
|
|
|
bool fix_fields(THD *thd, Item **ref) override;
|
2021-06-29 15:02:10 +03:00
|
|
|
enum Sumfunctype sum_func() const override { return JSON_ARRAYAGG_FUNC; }
|
2019-07-04 13:12:08 +03:00
|
|
|
|
2020-08-19 02:53:22 +03:00
|
|
|
String* val_str(String *str) override;
|
2019-07-04 13:12:08 +03:00
|
|
|
|
2021-06-24 13:28:28 +04:00
|
|
|
Item *copy_or_same(THD* thd) override;
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2019-10-14 14:24:22 +04:00
|
|
|
{ return get_item_copy<Item_func_json_arrayagg>(thd, this); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Item_func_json_objectagg : public Item_sum
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
public:
|
|
|
|
Item_func_json_objectagg(THD *thd, Item *key, Item *value) :
|
|
|
|
Item_sum(thd, key, value)
|
|
|
|
{
|
2020-06-29 20:06:28 +05:30
|
|
|
quick_group= FALSE;
|
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 20:29:55 +03:00
|
|
|
result.append('{');
|
2019-10-14 14:24:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Item_func_json_objectagg(THD *thd, Item_func_json_objectagg *item);
|
2020-08-19 02:53:22 +03:00
|
|
|
void cleanup() override;
|
2019-10-14 14:24:22 +04:00
|
|
|
|
2020-08-19 02:53:22 +03:00
|
|
|
enum Sumfunctype sum_func () const override { return JSON_OBJECTAGG_FUNC;}
|
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 20:29:55 +03:00
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_objectagg") };
|
|
|
|
return name;
|
|
|
|
}
|
2020-08-19 02:53:22 +03:00
|
|
|
const Type_handler *type_handler() const override
|
2019-10-14 14:24:22 +04:00
|
|
|
{
|
2022-01-10 18:05:55 +04:00
|
|
|
return Type_handler_json_common::json_type_handler_sum(this);
|
2019-10-14 14:24:22 +04:00
|
|
|
}
|
2020-08-19 02:53:22 +03:00
|
|
|
void clear() override;
|
|
|
|
bool add() override;
|
|
|
|
void reset_field() override { DBUG_ASSERT(0); } // not used
|
|
|
|
void update_field() override { DBUG_ASSERT(0); } // not used
|
|
|
|
bool fix_fields(THD *,Item **) override;
|
2019-10-14 14:24:22 +04:00
|
|
|
|
2021-06-29 15:02:10 +03:00
|
|
|
double val_real() override { return 0.0; }
|
|
|
|
longlong val_int() override { return 0; }
|
2020-08-19 02:53:22 +03:00
|
|
|
my_decimal *val_decimal(my_decimal *decimal_value) override
|
2019-10-14 14:24:22 +04:00
|
|
|
{
|
|
|
|
my_decimal_set_zero(decimal_value);
|
|
|
|
return decimal_value;
|
|
|
|
}
|
2020-08-19 02:53:22 +03:00
|
|
|
bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) override
|
2019-10-14 14:24:22 +04:00
|
|
|
{
|
|
|
|
return get_date_from_string(thd, ltime, fuzzydate);
|
|
|
|
}
|
2021-06-29 15:02:10 +03:00
|
|
|
String* val_str(String* str) override;
|
2020-08-19 02:53:22 +03:00
|
|
|
Item *copy_or_same(THD* thd) override;
|
|
|
|
void no_rows_in_result() override {}
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2019-10-14 14:24:22 +04:00
|
|
|
{ return get_item_copy<Item_func_json_objectagg>(thd, this); }
|
2019-07-04 13:12:08 +03:00
|
|
|
};
|
|
|
|
|
2022-02-03 17:01:31 +01:00
|
|
|
extern bool is_json_type(const Item *item);
|
2019-07-04 13:12:08 +03:00
|
|
|
|
2022-01-30 15:45:25 +05:30
|
|
|
class Item_func_json_overlaps: public Item_bool_func
|
|
|
|
{
|
|
|
|
String tmp_js;
|
|
|
|
bool a2_constant, a2_parsed;
|
|
|
|
String tmp_val, *val;
|
|
|
|
public:
|
|
|
|
Item_func_json_overlaps(THD *thd, Item *a, Item *b):
|
2022-10-28 13:03:13 +05:30
|
|
|
Item_bool_func(thd, a, b)
|
|
|
|
{}
|
2022-01-30 15:45:25 +05:30
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_overlaps") };
|
|
|
|
return name;
|
|
|
|
}
|
2022-01-26 03:02:45 +05:30
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2024-10-29 15:24:38 +01:00
|
|
|
bool val_bool() override;
|
2024-07-20 08:16:24 +02:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2022-01-30 15:45:25 +05:30
|
|
|
{ return get_item_copy<Item_func_json_overlaps>(thd, this); }
|
|
|
|
};
|
|
|
|
|
2022-10-28 13:03:13 +05:30
|
|
|
class Item_func_json_schema_valid: public Item_bool_func
|
|
|
|
{
|
|
|
|
String tmp_js;
|
|
|
|
bool schema_parsed;
|
|
|
|
String tmp_val, *val;
|
|
|
|
List<Json_schema_keyword> keyword_list;
|
|
|
|
List<Json_schema_keyword> all_keywords;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Item_func_json_schema_valid(THD *thd, Item *a, Item *b):
|
|
|
|
Item_bool_func(thd, a, b)
|
|
|
|
{
|
|
|
|
val= NULL;
|
|
|
|
schema_parsed= false;
|
2023-05-02 16:34:07 +05:30
|
|
|
set_maybe_null();
|
2022-10-28 13:03:13 +05:30
|
|
|
}
|
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_schema_valid") };
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
2024-10-29 16:39:47 +01:00
|
|
|
bool val_bool() override;
|
2024-08-03 09:32:42 +02:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2022-10-28 13:03:13 +05:30
|
|
|
{ return get_item_copy<Item_func_json_schema_valid>(thd, this); }
|
|
|
|
void cleanup() override;
|
|
|
|
};
|
|
|
|
|
2023-05-25 15:45:43 +05:30
|
|
|
class Item_func_json_key_value: public Item_json_func,
|
|
|
|
public Json_path_extractor
|
|
|
|
{
|
|
|
|
|
|
|
|
String tmp_str;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Item_func_json_key_value(THD *thd, Item *js, Item *i_path):
|
|
|
|
Item_json_func(thd, js, i_path) {}
|
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_key_value") };
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
|
|
|
String *val_str(String *to) override;
|
|
|
|
bool check_and_get_value(Json_engine_scan *je,
|
|
|
|
String *res, int *error) override
|
|
|
|
{
|
|
|
|
return je->check_and_get_value_complex(res, error, JSON_VALUE_OBJECT);
|
|
|
|
}
|
|
|
|
bool get_key_value(json_engine_t *je, String *str);
|
2024-08-03 09:50:16 +02:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2023-05-25 15:45:43 +05:30
|
|
|
{ return get_item_copy<Item_func_json_key_value>(thd, this); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
MDEV-26182: Implement JSON_INTERSECT()
The idea is to have simple functions that the user can combine to produce
the exact result one wants, whether the user wants JSON object that has
common keys with another JSON object, or same key/value pair etc. So
making simpler function helps here.
We accomplish this by making three separate functions.
1) JSON_OBJECT_FILTER_KEYS(Obj, Arr_keys):
Put keys ( which are basically strings ) in hash, go over the object and
get key one by one. If the key is present in the hash,
add the key-value pair to result.
2) JSON_OBJECT_TO_ARRAY(Obj) : Create a string variable, Go over the json
object, and add each key value pair as an array into the result.
3) JSON_ARRAY_INTERSECT(arr1, arr2) :
Go over one of the json and add each item of the array
in hash (after normalizing each item). Go over the second array,
search the normalized item one by one in the hash. If item is found,
add it to the result.
Implementation Idea: Holyfoot ( Alexey Botchkov)
Author: tanruixiang and Rucha Deodhar
2022-06-16 15:05:35 +08:00
|
|
|
|
|
|
|
class Item_func_json_array_intersect: public Item_str_func
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp_js1, tmp_js2;
|
|
|
|
bool hash_inited, root_inited;
|
|
|
|
HASH items;
|
|
|
|
MEM_ROOT hash_root;
|
2023-07-04 14:39:57 +05:30
|
|
|
bool parse_for_each_row;
|
MDEV-26182: Implement JSON_INTERSECT()
The idea is to have simple functions that the user can combine to produce
the exact result one wants, whether the user wants JSON object that has
common keys with another JSON object, or same key/value pair etc. So
making simpler function helps here.
We accomplish this by making three separate functions.
1) JSON_OBJECT_FILTER_KEYS(Obj, Arr_keys):
Put keys ( which are basically strings ) in hash, go over the object and
get key one by one. If the key is present in the hash,
add the key-value pair to result.
2) JSON_OBJECT_TO_ARRAY(Obj) : Create a string variable, Go over the json
object, and add each key value pair as an array into the result.
3) JSON_ARRAY_INTERSECT(arr1, arr2) :
Go over one of the json and add each item of the array
in hash (after normalizing each item). Go over the second array,
search the normalized item one by one in the hash. If item is found,
add it to the result.
Implementation Idea: Holyfoot ( Alexey Botchkov)
Author: tanruixiang and Rucha Deodhar
2022-06-16 15:05:35 +08:00
|
|
|
public:
|
|
|
|
Item_func_json_array_intersect(THD *thd, Item *a, Item *b):
|
2023-07-04 14:39:57 +05:30
|
|
|
Item_str_func(thd, a, b) { hash_inited= root_inited= parse_for_each_row= false; }
|
MDEV-26182: Implement JSON_INTERSECT()
The idea is to have simple functions that the user can combine to produce
the exact result one wants, whether the user wants JSON object that has
common keys with another JSON object, or same key/value pair etc. So
making simpler function helps here.
We accomplish this by making three separate functions.
1) JSON_OBJECT_FILTER_KEYS(Obj, Arr_keys):
Put keys ( which are basically strings ) in hash, go over the object and
get key one by one. If the key is present in the hash,
add the key-value pair to result.
2) JSON_OBJECT_TO_ARRAY(Obj) : Create a string variable, Go over the json
object, and add each key value pair as an array into the result.
3) JSON_ARRAY_INTERSECT(arr1, arr2) :
Go over one of the json and add each item of the array
in hash (after normalizing each item). Go over the second array,
search the normalized item one by one in the hash. If item is found,
add it to the result.
Implementation Idea: Holyfoot ( Alexey Botchkov)
Author: tanruixiang and Rucha Deodhar
2022-06-16 15:05:35 +08:00
|
|
|
String *val_str(String *) override;
|
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_array_intersect") };
|
|
|
|
return name;
|
|
|
|
}
|
2024-08-03 09:50:16 +02:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
MDEV-26182: Implement JSON_INTERSECT()
The idea is to have simple functions that the user can combine to produce
the exact result one wants, whether the user wants JSON object that has
common keys with another JSON object, or same key/value pair etc. So
making simpler function helps here.
We accomplish this by making three separate functions.
1) JSON_OBJECT_FILTER_KEYS(Obj, Arr_keys):
Put keys ( which are basically strings ) in hash, go over the object and
get key one by one. If the key is present in the hash,
add the key-value pair to result.
2) JSON_OBJECT_TO_ARRAY(Obj) : Create a string variable, Go over the json
object, and add each key value pair as an array into the result.
3) JSON_ARRAY_INTERSECT(arr1, arr2) :
Go over one of the json and add each item of the array
in hash (after normalizing each item). Go over the second array,
search the normalized item one by one in the hash. If item is found,
add it to the result.
Implementation Idea: Holyfoot ( Alexey Botchkov)
Author: tanruixiang and Rucha Deodhar
2022-06-16 15:05:35 +08:00
|
|
|
{ return get_item_copy<Item_func_json_array_intersect>(thd, this); }
|
|
|
|
void cleanup() override
|
|
|
|
{
|
2023-06-17 19:00:56 +02:00
|
|
|
Item_str_func::cleanup();
|
MDEV-26182: Implement JSON_INTERSECT()
The idea is to have simple functions that the user can combine to produce
the exact result one wants, whether the user wants JSON object that has
common keys with another JSON object, or same key/value pair etc. So
making simpler function helps here.
We accomplish this by making three separate functions.
1) JSON_OBJECT_FILTER_KEYS(Obj, Arr_keys):
Put keys ( which are basically strings ) in hash, go over the object and
get key one by one. If the key is present in the hash,
add the key-value pair to result.
2) JSON_OBJECT_TO_ARRAY(Obj) : Create a string variable, Go over the json
object, and add each key value pair as an array into the result.
3) JSON_ARRAY_INTERSECT(arr1, arr2) :
Go over one of the json and add each item of the array
in hash (after normalizing each item). Go over the second array,
search the normalized item one by one in the hash. If item is found,
add it to the result.
Implementation Idea: Holyfoot ( Alexey Botchkov)
Author: tanruixiang and Rucha Deodhar
2022-06-16 15:05:35 +08:00
|
|
|
if (hash_inited)
|
|
|
|
my_hash_free(&items);
|
|
|
|
if (root_inited)
|
|
|
|
free_root(&hash_root, MYF(0));
|
|
|
|
}
|
2023-07-04 14:39:57 +05:30
|
|
|
void prepare_json_and_create_hash(json_engine_t *je1, String *js);
|
MDEV-26182: Implement JSON_INTERSECT()
The idea is to have simple functions that the user can combine to produce
the exact result one wants, whether the user wants JSON object that has
common keys with another JSON object, or same key/value pair etc. So
making simpler function helps here.
We accomplish this by making three separate functions.
1) JSON_OBJECT_FILTER_KEYS(Obj, Arr_keys):
Put keys ( which are basically strings ) in hash, go over the object and
get key one by one. If the key is present in the hash,
add the key-value pair to result.
2) JSON_OBJECT_TO_ARRAY(Obj) : Create a string variable, Go over the json
object, and add each key value pair as an array into the result.
3) JSON_ARRAY_INTERSECT(arr1, arr2) :
Go over one of the json and add each item of the array
in hash (after normalizing each item). Go over the second array,
search the normalized item one by one in the hash. If item is found,
add it to the result.
Implementation Idea: Holyfoot ( Alexey Botchkov)
Author: tanruixiang and Rucha Deodhar
2022-06-16 15:05:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class Item_func_json_object_filter_keys: public Item_str_func
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
String tmp_js1, tmp_js2;
|
|
|
|
bool hash_inited, root_inited;
|
|
|
|
HASH items;
|
|
|
|
MEM_ROOT hash_root;
|
|
|
|
public:
|
|
|
|
Item_func_json_object_filter_keys(THD *thd, Item *a, Item *b):
|
|
|
|
Item_str_func(thd, a, b) { hash_inited= root_inited= false; }
|
|
|
|
String *val_str(String *) override;
|
|
|
|
bool fix_length_and_dec(THD *thd) override;
|
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("json_object_filter_keys") };
|
|
|
|
return name;
|
|
|
|
}
|
2024-08-03 09:50:16 +02:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
MDEV-26182: Implement JSON_INTERSECT()
The idea is to have simple functions that the user can combine to produce
the exact result one wants, whether the user wants JSON object that has
common keys with another JSON object, or same key/value pair etc. So
making simpler function helps here.
We accomplish this by making three separate functions.
1) JSON_OBJECT_FILTER_KEYS(Obj, Arr_keys):
Put keys ( which are basically strings ) in hash, go over the object and
get key one by one. If the key is present in the hash,
add the key-value pair to result.
2) JSON_OBJECT_TO_ARRAY(Obj) : Create a string variable, Go over the json
object, and add each key value pair as an array into the result.
3) JSON_ARRAY_INTERSECT(arr1, arr2) :
Go over one of the json and add each item of the array
in hash (after normalizing each item). Go over the second array,
search the normalized item one by one in the hash. If item is found,
add it to the result.
Implementation Idea: Holyfoot ( Alexey Botchkov)
Author: tanruixiang and Rucha Deodhar
2022-06-16 15:05:35 +08:00
|
|
|
{ return get_item_copy<Item_func_json_object_filter_keys>(thd, this); }
|
|
|
|
|
|
|
|
void cleanup() override
|
|
|
|
{
|
2023-06-17 19:00:56 +02:00
|
|
|
Item_str_func::cleanup();
|
MDEV-26182: Implement JSON_INTERSECT()
The idea is to have simple functions that the user can combine to produce
the exact result one wants, whether the user wants JSON object that has
common keys with another JSON object, or same key/value pair etc. So
making simpler function helps here.
We accomplish this by making three separate functions.
1) JSON_OBJECT_FILTER_KEYS(Obj, Arr_keys):
Put keys ( which are basically strings ) in hash, go over the object and
get key one by one. If the key is present in the hash,
add the key-value pair to result.
2) JSON_OBJECT_TO_ARRAY(Obj) : Create a string variable, Go over the json
object, and add each key value pair as an array into the result.
3) JSON_ARRAY_INTERSECT(arr1, arr2) :
Go over one of the json and add each item of the array
in hash (after normalizing each item). Go over the second array,
search the normalized item one by one in the hash. If item is found,
add it to the result.
Implementation Idea: Holyfoot ( Alexey Botchkov)
Author: tanruixiang and Rucha Deodhar
2022-06-16 15:05:35 +08:00
|
|
|
if (hash_inited)
|
|
|
|
my_hash_free(&items);
|
|
|
|
if (root_inited)
|
|
|
|
free_root(&hash_root, MYF(0));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-10-19 14:10:03 +04:00
|
|
|
#endif /* ITEM_JSONFUNC_INCLUDED */
|