404
405
virtual ~Create_func_cot() {}
409
class Create_func_crc32 : public Create_func_arg1
412
virtual Item *create(THD *thd, Item *arg1);
414
static Create_func_crc32 s_singleton;
417
Create_func_crc32() {}
418
virtual ~Create_func_crc32() {}
407
422
class Create_func_date_format : public Create_func_arg2
539
class Create_func_encode : public Create_func_arg2
542
virtual Item *create(THD *thd, Item *arg1, Item *arg2);
544
static Create_func_encode s_singleton;
547
Create_func_encode() {}
548
virtual ~Create_func_encode() {}
552
class Create_func_encrypt : public Create_native_func
555
virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
557
static Create_func_encrypt s_singleton;
560
Create_func_encrypt() {}
561
virtual ~Create_func_encrypt() {}
524
565
class Create_func_exp : public Create_func_arg1
923
964
virtual ~Create_func_master_pos_wait() {}
968
class Create_func_md5 : public Create_func_arg1
971
virtual Item *create(THD *thd, Item *arg1);
973
static Create_func_md5 s_singleton;
977
virtual ~Create_func_md5() {}
926
981
class Create_func_monthname : public Create_func_arg1
1423
class Create_func_uuid_short : public Create_func_arg0
1426
virtual Item *create(THD *thd);
1428
static Create_func_uuid_short s_singleton;
1431
Create_func_uuid_short() {}
1432
virtual ~Create_func_uuid_short() {}
1368
1436
class Create_func_version : public Create_func_arg0
1450
1519
Create_udf_func Create_udf_func::s_singleton;
1453
1522
Create_udf_func::create(THD *thd, LEX_STRING name, List<Item> *item_list)
1455
1524
udf_func *udf= find_udf(name.str, name.length);
1457
1526
return create(thd, udf, item_list);
1470
1539
thd->lex->set_stmt_unsafe();
1472
func= udf->create_func(thd->mem_root);
1474
func->set_arguments(*item_list);
1541
DBUG_ASSERT( (udf->type == UDFTYPE_FUNCTION)
1542
|| (udf->type == UDFTYPE_AGGREGATE));
1544
switch(udf->returns) {
1547
if (udf->type == UDFTYPE_FUNCTION)
1550
func= new (thd->mem_root) Item_func_udf_str(udf, *item_list);
1552
func= new (thd->mem_root) Item_func_udf_str(udf);
1557
func= new (thd->mem_root) Item_sum_udf_str(udf, *item_list);
1559
func= new (thd->mem_root) Item_sum_udf_str(udf);
1565
if (udf->type == UDFTYPE_FUNCTION)
1568
func= new (thd->mem_root) Item_func_udf_float(udf, *item_list);
1570
func= new (thd->mem_root) Item_func_udf_float(udf);
1575
func= new (thd->mem_root) Item_sum_udf_float(udf, *item_list);
1577
func= new (thd->mem_root) Item_sum_udf_float(udf);
1583
if (udf->type == UDFTYPE_FUNCTION)
1586
func= new (thd->mem_root) Item_func_udf_int(udf, *item_list);
1588
func= new (thd->mem_root) Item_func_udf_int(udf);
1593
func= new (thd->mem_root) Item_sum_udf_int(udf, *item_list);
1595
func= new (thd->mem_root) Item_sum_udf_int(udf);
1599
case DECIMAL_RESULT:
1601
if (udf->type == UDFTYPE_FUNCTION)
1604
func= new (thd->mem_root) Item_func_udf_decimal(udf, *item_list);
1606
func= new (thd->mem_root) Item_func_udf_decimal(udf);
1611
func= new (thd->mem_root) Item_sum_udf_decimal(udf, *item_list);
1613
func= new (thd->mem_root) Item_sum_udf_decimal(udf);
1619
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "UDF return type");
1680
1827
Create_func_bin::create(THD *thd, Item *arg1)
1682
Item *i10= new (thd->mem_root) Item_int((int32_t) 10,2);
1683
Item *i2= new (thd->mem_root) Item_int((int32_t) 2,1);
1829
Item *i10= new (thd->mem_root) Item_int((int32) 10,2);
1830
Item *i2= new (thd->mem_root) Item_int((int32) 2,1);
1684
1831
return new (thd->mem_root) Item_func_conv(arg1, i10, i2);
1810
1957
return new (thd->mem_root) Item_func_div(i1, i2);
1961
Create_func_crc32 Create_func_crc32::s_singleton;
1964
Create_func_crc32::create(THD *thd, Item *arg1)
1966
return new (thd->mem_root) Item_func_crc32(arg1);
1813
1970
Create_func_date_format Create_func_date_format::s_singleton;
2027
Create_func_decode Create_func_decode::s_singleton;
2030
Create_func_decode::create(THD *thd, Item *arg1, Item *arg2)
2032
return new (thd->mem_root) Item_func_decode(arg1, arg2);
1870
2036
Create_func_degrees Create_func_degrees::s_singleton;
2067
Create_func_encode Create_func_encode::s_singleton;
2070
Create_func_encode::create(THD *thd, Item *arg1, Item *arg2)
2072
return new (thd->mem_root) Item_func_encode(arg1, arg2);
2076
Create_func_encrypt Create_func_encrypt::s_singleton;
2079
Create_func_encrypt::create_native(THD *thd, LEX_STRING name,
2080
List<Item> *item_list)
2085
if (item_list != NULL)
2086
arg_count= item_list->elements;
2088
switch (arg_count) {
2091
Item *param_1= item_list->pop();
2092
func= new (thd->mem_root) Item_func_encrypt(param_1);
2097
Item *param_1= item_list->pop();
2098
Item *param_2= item_list->pop();
2099
func= new (thd->mem_root) Item_func_encrypt(param_1, param_2);
2104
my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1901
2113
Create_func_exp Create_func_exp::s_singleton;
2632
Create_func_md5 Create_func_md5::s_singleton;
2635
Create_func_md5::create(THD *thd, Item *arg1)
2637
return new (thd->mem_root) Item_func_md5(arg1);
2420
2641
Create_func_monthname Create_func_monthname::s_singleton;
2441
2662
Create_func_oct::create(THD *thd, Item *arg1)
2443
Item *i10= new (thd->mem_root) Item_int((int32_t) 10,2);
2444
Item *i8= new (thd->mem_root) Item_int((int32_t) 8,1);
2664
Item *i10= new (thd->mem_root) Item_int((int32) 10,2);
2665
Item *i8= new (thd->mem_root) Item_int((int32) 8,1);
2445
2666
return new (thd->mem_root) Item_func_conv(arg1, i10, i8);
2648
2869
The parsed item tree should not depend on
2649
2870
<code>thd->variables.collation_connection</code>.
2651
const CHARSET_INFO * const cs= thd->variables.collation_connection;
2872
CHARSET_INFO *cs= thd->variables.collation_connection;
2654
2875
if (cs->mbminlen > 1)
2656
uint32_t dummy_errors;
2657
2878
sp= new (thd->mem_root) Item_string("", 0, cs, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
2658
sp->str_value.copy(" ", 1, &my_charset_utf8_general_ci, cs, &dummy_errors);
2879
sp->str_value.copy(" ", 1, &my_charset_latin1, cs, &dummy_errors);
3043
Create_func_uuid_short Create_func_uuid_short::s_singleton;
3046
Create_func_uuid_short::create(THD *thd)
3048
thd->lex->set_stmt_unsafe();
3049
return new (thd->mem_root) Item_func_uuid_short();
2822
3053
Create_func_version Create_func_version::s_singleton;
2927
3158
{ { C_STRING_WITH_LEN("CONV") }, BUILDER(Create_func_conv)},
2928
3159
{ { C_STRING_WITH_LEN("COS") }, BUILDER(Create_func_cos)},
2929
3160
{ { C_STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)},
3161
{ { C_STRING_WITH_LEN("CRC32") }, BUILDER(Create_func_crc32)},
2930
3162
{ { C_STRING_WITH_LEN("DATEDIFF") }, BUILDER(Create_func_datediff)},
2931
3163
{ { C_STRING_WITH_LEN("DATE_FORMAT") }, BUILDER(Create_func_date_format)},
2932
3164
{ { C_STRING_WITH_LEN("DAYNAME") }, BUILDER(Create_func_dayname)},
2933
3165
{ { C_STRING_WITH_LEN("DAYOFMONTH") }, BUILDER(Create_func_dayofmonth)},
2934
3166
{ { C_STRING_WITH_LEN("DAYOFWEEK") }, BUILDER(Create_func_dayofweek)},
2935
3167
{ { C_STRING_WITH_LEN("DAYOFYEAR") }, BUILDER(Create_func_dayofyear)},
3168
{ { C_STRING_WITH_LEN("DECODE") }, BUILDER(Create_func_decode)},
2936
3169
{ { C_STRING_WITH_LEN("DEGREES") }, BUILDER(Create_func_degrees)},
2937
3170
{ { C_STRING_WITH_LEN("ELT") }, BUILDER(Create_func_elt)},
3171
{ { C_STRING_WITH_LEN("ENCODE") }, BUILDER(Create_func_encode)},
3172
{ { C_STRING_WITH_LEN("ENCRYPT") }, BUILDER(Create_func_encrypt)},
2938
3173
{ { C_STRING_WITH_LEN("EXP") }, BUILDER(Create_func_exp)},
2939
3174
{ { C_STRING_WITH_LEN("EXPORT_SET") }, BUILDER(Create_func_export_set)},
2940
3175
{ { C_STRING_WITH_LEN("FIELD") }, BUILDER(Create_func_field)},
2967
3202
{ { C_STRING_WITH_LEN("MAKETIME") }, BUILDER(Create_func_maketime)},
2968
3203
{ { C_STRING_WITH_LEN("MAKE_SET") }, BUILDER(Create_func_make_set)},
2969
3204
{ { C_STRING_WITH_LEN("MASTER_POS_WAIT") }, BUILDER(Create_func_master_pos_wait)},
3205
{ { C_STRING_WITH_LEN("MD5") }, BUILDER(Create_func_md5)},
2970
3206
{ { C_STRING_WITH_LEN("MONTHNAME") }, BUILDER(Create_func_monthname)},
2971
3207
{ { C_STRING_WITH_LEN("NULLIF") }, BUILDER(Create_func_nullif)},
2972
3208
{ { C_STRING_WITH_LEN("OCT") }, BUILDER(Create_func_oct)},
3003
3239
{ { C_STRING_WITH_LEN("UNIX_TIMESTAMP") }, BUILDER(Create_func_unix_timestamp)},
3004
3240
{ { C_STRING_WITH_LEN("UPPER") }, BUILDER(Create_func_ucase)},
3005
3241
{ { C_STRING_WITH_LEN("UUID") }, BUILDER(Create_func_uuid)},
3242
{ { C_STRING_WITH_LEN("UUID_SHORT") }, BUILDER(Create_func_uuid_short)},
3006
3243
{ { C_STRING_WITH_LEN("VERSION") }, BUILDER(Create_func_version)},
3007
3244
{ { C_STRING_WITH_LEN("WEEKDAY") }, BUILDER(Create_func_weekday)},
3008
3245
{ { C_STRING_WITH_LEN("WEEKOFYEAR") }, BUILDER(Create_func_weekofyear)},
3014
3251
static HASH native_functions_hash;
3016
extern "C" unsigned char*
3017
get_native_fct_hash_key(const unsigned char *buff, size_t *length,
3254
get_native_fct_hash_key(const uchar *buff, size_t *length,
3255
my_bool /* unused */)
3020
3257
Native_func_registry *func= (Native_func_registry*) buff;
3021
3258
*length= func->name.length;
3022
return (unsigned char*) func->name.str;
3259
return (uchar*) func->name.str;
3033
3270
Native_func_registry *func;
3272
DBUG_ENTER("item_create_init");
3035
3274
if (hash_init(& native_functions_hash,
3036
3275
system_charset_info,
3037
3276
array_elements(func_array),
3040
3279
(hash_get_key) get_native_fct_hash_key,
3041
3280
NULL, /* Nothing to free */
3045
3284
for (func= func_array; func->builder != NULL; func++)
3047
if (my_hash_insert(& native_functions_hash, (unsigned char*) func))
3286
if (my_hash_insert(& native_functions_hash, (uchar*) func))
3291
for (uint i=0 ; i < native_functions_hash.records ; i++)
3293
func= (Native_func_registry*) hash_element(& native_functions_hash, i);
3294
DBUG_PRINT("info", ("native function: %s length: %u",
3295
func->name.str, (uint) func->name.length));
3060
3308
void item_create_cleanup()
3310
DBUG_ENTER("item_create_cleanup");
3062
3311
hash_free(& native_functions_hash);
3067
find_native_function_builder(THD *thd __attribute__((unused)),
3316
find_native_function_builder(THD *thd, LEX_STRING name)
3070
3318
Native_func_registry *func;
3071
3319
Create_func *builder= NULL;
3073
3321
/* Thread safe */
3074
3322
func= (Native_func_registry*) hash_search(& native_functions_hash,
3075
(unsigned char*) name.str,
3088
create_func_char_cast(THD *thd, Item *a, int len, const CHARSET_INFO * const cs)
3336
create_func_char_cast(THD *thd, Item *a, int len, CHARSET_INFO *cs)
3090
const CHARSET_INFO * const real_cs= (cs ? cs : thd->variables.collation_connection);
3338
CHARSET_INFO *real_cs= (cs ? cs : thd->variables.collation_connection);
3091
3339
return new (thd->mem_root) Item_char_typecast(a, len, real_cs);
3096
3344
create_func_cast(THD *thd, Item *a, Cast_target cast_type,
3097
3345
const char *c_len, const char *c_dec,
3098
const CHARSET_INFO * const cs)
3104
3352
switch (cast_type) {
3105
3353
case ITEM_CAST_BINARY: