2019-10-07 10:46:25 +04:00
|
|
|
/*
|
2019-10-10 17:40:21 +02:00
|
|
|
Copyright (c) 2019, MariaDB Corporation
|
2019-10-07 10:46:25 +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 */
|
|
|
|
|
|
|
|
#define MYSQL_SERVER
|
|
|
|
|
|
|
|
#include <my_global.h>
|
|
|
|
#include <sql_class.h>
|
2019-10-16 12:43:24 +04:00
|
|
|
#include <mysql/plugin_function.h>
|
2019-10-07 10:46:25 +04:00
|
|
|
|
|
|
|
class Item_func_sysconst_test :public Item_func_sysconst
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Item_func_sysconst_test(THD *thd): Item_func_sysconst(thd) {}
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *str) override
|
2019-10-07 10:46:25 +04:00
|
|
|
{
|
|
|
|
null_value= str->copy(STRING_WITH_LEN("sysconst_test"), system_charset_info);
|
|
|
|
return null_value ? NULL : str;
|
|
|
|
}
|
2020-08-19 02:53:22 +03:00
|
|
|
bool fix_length_and_dec() override
|
2019-10-07 10:46:25 +04:00
|
|
|
{
|
|
|
|
max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen;
|
2020-09-02 03:13:32 +03:00
|
|
|
set_maybe_null();
|
2019-10-07 10:46:25 +04:00
|
|
|
return 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
|
|
|
LEX_CSTRING func_name_cstring() const override
|
|
|
|
{
|
|
|
|
static LEX_CSTRING name= {STRING_WITH_LEN("sysconst_test") };
|
|
|
|
return name;
|
|
|
|
}
|
2020-08-19 02:53:22 +03:00
|
|
|
const char *fully_qualified_func_name() const override
|
|
|
|
{ return "sysconst_test()"; }
|
|
|
|
Item *get_copy(THD *thd) override
|
2019-10-07 10:46:25 +04:00
|
|
|
{ return get_item_copy<Item_func_sysconst_test>(thd, this); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Create_func_sysconst_test : public Create_func_arg0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Item *create_builder(THD *thd) override;
|
|
|
|
static Create_func_sysconst_test s_singleton;
|
|
|
|
protected:
|
|
|
|
Create_func_sysconst_test() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Create_func_sysconst_test Create_func_sysconst_test::s_singleton;
|
|
|
|
|
|
|
|
Item* Create_func_sysconst_test::create_builder(THD *thd)
|
|
|
|
{
|
|
|
|
return new (thd->mem_root) Item_func_sysconst_test(thd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define BUILDER(F) & F::s_singleton
|
|
|
|
|
|
|
|
|
2019-10-16 12:43:24 +04:00
|
|
|
static Plugin_function
|
|
|
|
plugin_descriptor_function_sysconst_test(BUILDER(Create_func_sysconst_test));
|
2019-10-07 10:46:25 +04:00
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
maria_declare_plugin(type_test)
|
|
|
|
{
|
2019-10-16 12:43:24 +04:00
|
|
|
MariaDB_FUNCTION_PLUGIN, // the plugin type (see include/mysql/plugin.h)
|
|
|
|
&plugin_descriptor_function_sysconst_test, // pointer to type-specific plugin descriptor
|
|
|
|
"sysconst_test", // plugin name
|
2019-10-07 10:46:25 +04:00
|
|
|
"MariaDB Corporation", // plugin author
|
2019-10-16 12:43:24 +04:00
|
|
|
"Function SYSCONST_TEST()", // the plugin description
|
2019-10-07 10:46:25 +04:00
|
|
|
PLUGIN_LICENSE_GPL, // the plugin license (see include/mysql/plugin.h)
|
|
|
|
0, // Pointer to plugin initialization function
|
|
|
|
0, // Pointer to plugin deinitialization function
|
2019-10-10 17:40:21 +02:00
|
|
|
0x0100, // Numeric version 0xAABB means AA.BB version
|
2019-10-07 10:46:25 +04:00
|
|
|
NULL, // Status variables
|
|
|
|
NULL, // System variables
|
|
|
|
"1.0", // String version representation
|
|
|
|
MariaDB_PLUGIN_MATURITY_EXPERIMENTAL // Maturity(see include/mysql/plugin.h)*/
|
|
|
|
}
|
|
|
|
maria_declare_plugin_end;
|