1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
|
/*
Copyright (c) 2019, MariaDB Corporation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#define MYSQL_SERVER
#include <my_global.h>
#include <sql_class.h>
#include <mysql/plugin_function.h>
class Item_func_sysconst_test :public Item_func_sysconst
{
public:
Item_func_sysconst_test(THD *thd): Item_func_sysconst(thd) {}
String *val_str(String *str) override
{
null_value= str->copy(STRING_WITH_LEN("sysconst_test"), system_charset_info);
return null_value ? NULL : str;
}
bool fix_length_and_dec(THD *thd) override
{
max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen;
set_maybe_null();
return false;
}
LEX_CSTRING func_name_cstring() const override
{
static LEX_CSTRING name= {STRING_WITH_LEN("sysconst_test") };
return name;
}
const Lex_ident_routine fully_qualified_func_name() const override
{ return Lex_ident_routine("sysconst_test()"_LEX_CSTRING); }
Item *do_get_copy(THD *thd) const override
{ 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
static Plugin_function
plugin_descriptor_function_sysconst_test(BUILDER(Create_func_sysconst_test));
class Strnxfrm_args: public Null_flag
{
StringBuffer<128> m_srcbuf;
public:
String *m_src;
longlong m_dstlen;
longlong m_nweights;
longlong m_flags;
Strnxfrm_args(Item **args)
:Null_flag(true)
{
if (!(m_src= args[0]->val_str(&m_srcbuf)))
return;
m_dstlen= args[1]->val_int();
if (args[1]->null_value || m_dstlen < 0)
return;
m_nweights= args[2]->val_int();
if (args[2]->null_value || m_nweights < 0)
return;
m_flags= args[3]->val_int();
if (args[3]->null_value || m_flags < 0)
return;
m_is_null= false;
}
my_strnxfrm_ret_t exec(CHARSET_INFO *cs, String *to)
{
DBUG_ASSERT(!is_null());
if ((m_is_null= to->alloc(m_dstlen)))
return {0,0,0};
my_strnxfrm_ret_t rc= cs->strnxfrm((char*) to->ptr(),
(size_t)m_dstlen,
(uint) m_nweights,
m_src->ptr(), m_src->length(),
(uint) m_flags);
to->length((uint32) rc.m_result_length);
return rc;
}
};
class Item_func_strnxfrm_source_length_used: public Item_longlong_func
{
using Self = Item_func_strnxfrm_source_length_used;
public:
using Item_longlong_func::Item_longlong_func;
longlong val_int() override
{
Strnxfrm_args param(args);
if ((null_value= param.is_null()))
return 0;
StringBuffer<128> dstbuf;
my_strnxfrm_ret_t rc= param.exec(args[0]->collation.collation, &dstbuf);
if ((null_value= param.is_null()))
return 0;
return (longlong) rc.m_source_length_used;
}
LEX_CSTRING func_name_cstring() const override
{
static LEX_CSTRING name= "strnxfrm_source_length_used"_LEX_CSTRING;
return name;
}
Item *do_get_copy(THD *thd) const override
{
return get_item_copy<Self>(thd, this);
}
class Create_func : public Create_native_func
{
public:
using Create_native_func::Create_native_func;
Item *create_native(THD *thd, const LEX_CSTRING *name,
List<Item> *item_list) override
{
uint arg_count= item_list ? item_list->elements : 0;
if (arg_count != 4)
{
my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
return nullptr;
}
return new (thd->mem_root) Self(thd, *item_list);
}
};
static Plugin_function *plugin_descriptor()
{
static Create_func creator;
static Plugin_function descriptor(&creator);
return &descriptor;
}
};
class Item_func_strnxfrm_warnings: public Item_long_func
{
using Self = Item_func_strnxfrm_warnings;
public:
using Item_long_func::Item_long_func;
longlong val_int() override
{
Strnxfrm_args param(args);
if ((null_value= param.is_null()))
return 0;
StringBuffer<128> dstbuf;
my_strnxfrm_ret_t rc= param.exec(args[0]->collation.collation, &dstbuf);
if ((null_value= param.is_null()))
return 0;
return (longlong) rc.m_warnings;
}
LEX_CSTRING func_name_cstring() const override
{
static LEX_CSTRING name= "strnxfrm_warnings"_LEX_CSTRING;
return name;
}
Item *do_get_copy(THD *thd) const override
{
return get_item_copy<Self>(thd, this);
}
class Create_func : public Create_native_func
{
public:
using Create_native_func::Create_native_func;
Item *create_native(THD *thd, const LEX_CSTRING *name,
List<Item> *item_list) override
{
uint arg_count= item_list ? item_list->elements : 0;
if (arg_count != 4)
{
my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
return nullptr;
}
return new (thd->mem_root) Self(thd, *item_list);
}
};
static Plugin_function *plugin_descriptor()
{
static Create_func creator;
static Plugin_function descriptor(&creator);
return &descriptor;
}
};
class Item_func_strnxfrm: public Item_str_func
{
using Self = Item_func_strnxfrm;
public:
using Item_str_func::Item_str_func;
bool fix_length_and_dec(THD *thd) override
{
max_length= MAX_BLOB_WIDTH;
return false;
}
String *val_str(String *to) override
{
Strnxfrm_args param(args);
if ((null_value= param.is_null()))
return nullptr;
param.exec(args[0]->collation.collation, to);
if ((null_value= param.is_null()))
return nullptr;
return to;
}
LEX_CSTRING func_name_cstring() const override
{
static LEX_CSTRING name= "strnxfrm"_LEX_CSTRING;
return name;
}
Item *do_get_copy(THD *thd) const override
{
return get_item_copy<Self>(thd, this);
}
class Create_func : public Create_native_func
{
public:
using Create_native_func::Create_native_func;
Item *create_native(THD *thd, const LEX_CSTRING *name,
List<Item> *item_list) override
{
uint arg_count= item_list ? item_list->elements : 0;
if (arg_count != 4)
{
my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
return nullptr;
}
return new (thd->mem_root) Self(thd, *item_list);
}
};
static Plugin_function *plugin_descriptor()
{
static Create_func creator;
static Plugin_function descriptor(&creator);
return &descriptor;
}
};
/*************************************************************************/
maria_declare_plugin(type_test)
{
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
"MariaDB Corporation", // plugin author
"Function SYSCONST_TEST()", // the plugin description
PLUGIN_LICENSE_GPL, // the plugin license (see include/mysql/plugin.h)
0, // Pointer to plugin initialization function
0, // Pointer to plugin deinitialization function
0x0100, // Numeric version 0xAABB means AA.BB version
NULL, // Status variables
NULL, // System variables
"1.0", // String version representation
MariaDB_PLUGIN_MATURITY_EXPERIMENTAL // Maturity(see include/mysql/plugin.h)*/
},
{
MariaDB_FUNCTION_PLUGIN, // the plugin type
Item_func_strnxfrm::plugin_descriptor(),
"strnxfrm", // plugin name
"MariaDB Corporation", // plugin author
"Function STRNXFRM()", // the plugin description
PLUGIN_LICENSE_GPL, // the plugin license
0, // Pointer to plugin initialization function
0, // Pointer to plugin deinitialization function
0x0100, // Numeric version 0xAABB means AA.BB version
NULL, // Status variables
NULL, // System variables
"1.0", // String version representation
MariaDB_PLUGIN_MATURITY_EXPERIMENTAL // Maturity
},
{
MariaDB_FUNCTION_PLUGIN, // the plugin type
Item_func_strnxfrm_source_length_used::plugin_descriptor(),
"strnxfrm_source_length_used",// plugin name
"MariaDB Corporation", // plugin author
"Function STRNXFRM_SOURCE_LENGTH_USED()", // the plugin description
PLUGIN_LICENSE_GPL, // the plugin license
0, // Pointer to plugin initialization function
0, // Pointer to plugin deinitialization function
0x0100, // Numeric version 0xAABB means AA.BB version
NULL, // Status variables
NULL, // System variables
"1.0", // String version representation
MariaDB_PLUGIN_MATURITY_EXPERIMENTAL // Maturity
},
{
MariaDB_FUNCTION_PLUGIN, // the plugin type
Item_func_strnxfrm_warnings::plugin_descriptor(),
"strnxfrm_warnings",// plugin name
"MariaDB Corporation", // plugin author
"Function STRNXFRM_WARNINGS()", // the plugin description
PLUGIN_LICENSE_GPL, // the plugin license
0, // Pointer to plugin initialization function
0, // Pointer to plugin deinitialization function
0x0100, // Numeric version 0xAABB means AA.BB version
NULL, // Status variables
NULL, // System variables
"1.0", // String version representation
MariaDB_PLUGIN_MATURITY_EXPERIMENTAL // Maturity
}
maria_declare_plugin_end;
|