drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
drizzled/item/create.cc
Go to the documentation of this file.
1/* Copyright (C) 2000-2003 MySQL AB
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
22
23#include <config.h>
24#include <drizzled/item/create.h>
25#include <drizzled/item/func.h>
26#include <drizzled/error.h>
27#include <drizzled/system_variables.h>
28
29#include <drizzled/function_container.h>
30
31#include <drizzled/function/str/binary.h>
32#include <drizzled/function/str/concat.h>
33#include <drizzled/function/str/conv.h>
34#include <drizzled/function/str/export_set.h>
35#include <drizzled/function/str/load_file.h>
36#include <drizzled/function/str/make_set.h>
37#include <drizzled/function/str/pad.h>
38#include <drizzled/function/str/repeat.h>
39#include <drizzled/function/str/str_conv.h>
40#include <drizzled/function/str/trim.h>
41
42#include <drizzled/function/time/date_format.h>
43#include <drizzled/function/time/dayname.h>
44#include <drizzled/function/time/dayofmonth.h>
45#include <drizzled/function/time/dayofyear.h>
46#include <drizzled/function/time/from_unixtime.h>
47#include <drizzled/function/time/from_days.h>
48#include <drizzled/function/time/last_day.h>
49#include <drizzled/function/time/makedate.h>
50#include <drizzled/function/time/month.h>
51#include <drizzled/function/time/period_add.h>
52#include <drizzled/function/time/period_diff.h>
53#include <drizzled/function/time/to_days.h>
54#include <drizzled/function/time/typecast.h>
55#include <drizzled/function/time/unix_timestamp.h>
56#include <drizzled/function/time/weekday.h>
57
58#include <drizzled/item/cmpfunc.h>
59#include <drizzled/plugin/function.h>
60#include <drizzled/session.h>
61
62/* Function declarations */
63
64#include <drizzled/function/func.h>
65#include <drizzled/function/additive_op.h>
66#include <drizzled/function/math/dec.h>
67#include <drizzled/function/math/decimal_typecast.h>
68#include <drizzled/function/field.h>
69#include <drizzled/function/find_in_set.h>
70#include <drizzled/function/found_rows.h>
71#include <drizzled/function/get_system_var.h>
72#include <drizzled/function/math/int_val.h>
73#include <drizzled/function/math/integer.h>
74#include <drizzled/function/last_insert.h>
75#include <drizzled/function/locate.h>
76#include <drizzled/function/min_max.h>
77#include <drizzled/function/num1.h>
78#include <drizzled/function/num_op.h>
79#include <drizzled/function/numhybrid.h>
80#include <drizzled/function/math/real.h>
81#include <drizzled/function/row_count.h>
82#include <drizzled/function/set_user_var.h>
83#include <drizzled/function/sign.h>
84#include <drizzled/function/math/tan.h>
85#include <drizzled/function/units.h>
86
87#include <drizzled/function/cast/boolean.h>
88#include <drizzled/function/cast/signed.h>
89#include <drizzled/function/cast/time.h>
90#include <drizzled/function/cast/unsigned.h>
91
92using namespace std;
93
94namespace drizzled {
95
96/*
97=============================================================================
98 LOCAL DECLARATIONS
99=============================================================================
100*/
101
109
118{
119 List<Item>::iterator it(params.begin());
120 while (Item* param= it++)
121 {
122 if (not param->is_autogenerated_name)
123 return true;
124 }
125 return false;
126}
127
129{
130public:
131 virtual Item* create(Session* session, str_ref name, List<Item>* item_list)
132 {
133 if (item_list && has_named_parameters(*item_list))
134 {
135 my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.data());
136 return NULL;
137 }
138 return create_native(session, name, item_list);
139 }
140
148 virtual Item* create_native(Session*, str_ref name, List<Item>*) = 0;
149};
150
151
155
157{
158public:
159 virtual Item* create(Session *session, str_ref name, List<Item> *item_list);
160
166 virtual Item* create(Session *session) = 0;
167};
168
169
173
175{
176public:
177 virtual Item* create(Session *session, str_ref name, List<Item> *item_list);
178
185 virtual Item* create(Session *session, Item *arg1) = 0;
186};
187
188
192
194{
195public:
196 virtual Item* create(Session *session, str_ref name, List<Item> *item_list);
197
205 virtual Item* create(Session *session, Item *arg1, Item *arg2) = 0;
206};
207
208
212
214{
215public:
216 virtual Item* create(Session *session, str_ref name, List<Item> *item_list);
217
226 virtual Item* create(Session *session, Item *arg1, Item *arg2, Item *arg3) = 0;
227};
228
229
233
234/*
235 Concrete functions builders (native functions).
236 Please keep this list sorted in alphabetical order,
237 it helps to compare code between versions, and helps with merges conflicts.
238*/
239
240
242{
243public:
245
246 virtual Item* create(Session *session, Item *arg1);
247
248 static Create_func_bin s_singleton;
249};
250
252{
253public:
254 virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
255
256 static Create_func_concat s_singleton;
257};
258
259
261{
262public:
263 virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
264
265 static Create_func_concat_ws s_singleton;
266};
267
268
270{
271public:
273
274 virtual Item* create(Session *session, Item *arg1, Item *arg2, Item *arg3)
275 {
276 return new (session->mem) Item_func_conv(arg1, arg2, arg3);
277 }
278
279 static Create_func_conv s_singleton;
280};
281
282Create_func_conv Create_func_conv::s_singleton;
283
285{
286public:
288
289 virtual Item* create(Session *session, Item *arg1);
290
291 static Create_func_cot s_singleton;
292};
293
295{
296public:
298
299 virtual Item* create(Session *session, Item *arg1, Item *arg2)
300 {
301 return new (session->mem) Item_func_date_format(arg1, arg2, 0);
302 }
303
304 static Create_func_date_format s_singleton;
305};
306
307Create_func_date_format Create_func_date_format::s_singleton;
308
310{
311public:
313
314 virtual Item* create(Session *session, Item *arg1, Item *arg2);
315
316 static Create_func_datediff s_singleton;
317};
318
319
321{
322public:
324
325 virtual Item* create(Session *session, Item *arg1)
326 {
327 return new (session->mem) Item_func_dayname(arg1);
328 }
329
330 static Create_func_dayname s_singleton;
331};
332
333Create_func_dayname Create_func_dayname::s_singleton;
334
336{
337public:
339
340 virtual Item* create(Session *session, Item *arg1)
341 {
342 return new (session->mem) Item_func_dayofmonth(arg1);
343 }
344
345 static Create_func_dayofmonth s_singleton;
346};
347
348Create_func_dayofmonth Create_func_dayofmonth::s_singleton;
349
351{
352public:
354
355 virtual Item* create(Session *session, Item *arg1)
356 {
357 return new (session->mem) Item_func_weekday(arg1, 1);
358 }
359
360 static Create_func_dayofweek s_singleton;
361};
362
363Create_func_dayofweek Create_func_dayofweek::s_singleton;
364
366{
367public:
369
370 virtual Item* create(Session *session, Item *arg1)
371 {
372 return new (session->mem) Item_func_dayofyear(arg1);
373 }
374
375 static Create_func_dayofyear s_singleton;
376};
377
378Create_func_dayofyear Create_func_dayofyear::s_singleton;
379
381{
382public:
384
385 virtual Item* create(Session *session, Item *arg1, Item *arg2);
386
387 static Create_func_decode s_singleton;
388};
389
390
392{
393public:
395
396 virtual Item* create(Session *session, Item *arg1)
397 {
398 return new (session->mem) Item_func_units("degrees", arg1, 180/M_PI, 0.0);
399 }
400
401 static Create_func_degrees s_singleton;
402};
403
404Create_func_degrees Create_func_degrees::s_singleton;
405
407{
408
409public:
410 virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
411
412 static Create_func_export_set s_singleton;
413};
414
415
417{
418public:
419 virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
420
421 static Create_func_field s_singleton;
422};
423
424
426{
427public:
429
430 virtual Item* create(Session *session, Item *arg1, Item *arg2)
431 {
432 return new (session->mem) Item_func_find_in_set(arg1, arg2);
433 }
434
435 static Create_func_find_in_set s_singleton;
436};
437
439{
440public:
442
443 virtual Item* create(Session *session)
444 {
445 return new (session->mem) Item_func_found_rows();
446 }
447
448 static Create_func_found_rows s_singleton;
449};
450
451
453{
454public:
456
457 virtual Item* create(Session *session, Item *arg1)
458 {
459 return new (session->mem) Item_func_from_days(arg1);
460 }
461
462 static Create_func_from_days s_singleton;
463};
464
465
467{
468public:
469 virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
470
471 static Create_func_from_unixtime s_singleton;
472};
473
474
476{
477public:
478 virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
479
480 static Create_func_greatest s_singleton;
481};
482
483
485{
486public:
488
489 virtual Item* create(Session *session, Item *arg1, Item *arg2)
490 {
491 return new (session->mem) Item_func_ifnull(arg1, arg2);
492 }
493
494 static Create_func_ifnull s_singleton;
495};
496
497
499{
500public:
502
503 virtual Item* create(Session *session, Item *arg1, Item *arg2)
504 {
505 return new (session->mem) Item_func_locate(arg1, arg2);
506 }
507
508 static Create_func_instr s_singleton;
509};
510
511
513{
514public:
516
517 virtual Item* create(Session *session, Item *arg1)
518 {
519 return new (session->mem) Item_func_isnull(arg1);
520 }
521
522 static Create_func_isnull s_singleton;
523};
524
525
527{
528public:
530
531 virtual Item* create(Session *session, Item *arg1)
532 {
533 return new (session->mem) Item_func_last_day(arg1);
534 }
535
536 static Create_func_last_day s_singleton;
537};
538
539
541{
542public:
543 virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
544
545 static Create_func_last_insert_id s_singleton;
546};
547
548
550{
551public:
553
554 virtual Item* create(Session *session, Item *arg1)
555 {
556 return new (session->mem) Item_func_lcase(arg1);
557 }
558
559 static Create_func_lcase s_singleton;
560};
561
562
564{
565public:
566 virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
567
568 static Create_func_least s_singleton;
569};
570
572{
573public:
575
576 virtual Item* create(Session *session, Item *arg1)
577 {
578 return new (session->mem) Item_load_file(*session, arg1);
579 }
580
581 static Create_func_load_file s_singleton;
582};
583
585{
586public:
587 virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
588
589 static Create_func_locate s_singleton;
590};
591
593{
594public:
596
597 virtual Item* create(Session *session, Item *arg1, Item *arg2, Item *arg3)
598 {
599 return new (session->mem) Item_func_lpad(*session, arg1, arg2, arg3);
600 }
601
602 static Create_func_lpad s_singleton;
603};
604
605Create_func_lpad Create_func_lpad::s_singleton;
606
608{
609public:
611
612 virtual Item* create(Session *session, Item *arg1)
613 {
614 return new (session->mem) Item_func_ltrim(arg1);
615 }
616
617 static Create_func_ltrim s_singleton;
618};
619
620Create_func_ltrim Create_func_ltrim::s_singleton;
621
623{
624public:
626
627 virtual Item* create(Session *session, Item *arg1, Item *arg2)
628 {
629 return new (session->mem) Item_func_makedate(arg1, arg2);
630 }
631
632 static Create_func_makedate s_singleton;
633};
634
635Create_func_makedate Create_func_makedate::s_singleton;
636
638{
639public:
640 virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
641
642 static Create_func_make_set s_singleton;
643};
644
645
647{
648public:
650
651 virtual Item* create(Session *session, Item *arg1)
652 {
653 return new (session->mem) Item_func_monthname(arg1);
654 }
655
656 static Create_func_monthname s_singleton;
657};
658
659Create_func_monthname Create_func_monthname::s_singleton;
660
662{
663public:
665
666 virtual Item* create(Session *session, Item *arg1, Item *arg2);
667
668 static Create_func_name_const s_singleton;
669};
670
671
673{
674public:
676
677 virtual Item* create(Session *session, Item *arg1, Item *arg2)
678 {
679 return new (session->mem) Item_func_nullif(arg1, arg2);
680 }
681
682 static Create_func_nullif s_singleton;
683};
684
685Create_func_nullif Create_func_nullif::s_singleton;
686
688{
689public:
691
692 virtual Item* create(Session *session, Item *arg1);
693
694 static Create_func_oct s_singleton;
695};
696
698{
699public:
701
702 virtual Item* create(Session *session, Item *arg1, Item *arg2)
703 {
704 return new (session->mem) Item_func_period_add(arg1, arg2);
705 }
706
707 static Create_func_period_add s_singleton;
708};
709
710
712{
713public:
715
716 virtual Item* create(Session *session, Item *arg1, Item *arg2)
717 {
718 return new (session->mem) Item_func_period_diff(arg1, arg2);
719 }
720
721 static Create_func_period_diff s_singleton;
722};
723
724
726{
727public:
729
730 virtual Item* create(Session *session)
731 {
732 return new (session->mem) Item_static_float_func("pi()", M_PI, 6, 8);
733 }
734
735 static Create_func_pi s_singleton;
736};
737
739{
740public:
742
743 virtual Item* create(Session *session, Item *arg1)
744 {
745 return new (session->mem) Item_func_units("radians", arg1, M_PI/180, 0.0);
746 }
747
748 static Create_func_radians s_singleton;
749};
750
751
753{
754public:
755 virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
756
757 static Create_func_round s_singleton;
758};
759
760
762{
763public:
765
766 virtual Item* create(Session *session)
767 {
768 return new (session->mem) Item_func_row_count();
769 }
770
771 static Create_func_row_count s_singleton;
772};
773
774Create_func_row_count Create_func_row_count::s_singleton;
775
777{
778public:
780
781 virtual Item* create(Session *session, Item *arg1, Item *arg2, Item *arg3)
782 {
783 return new (session->mem) Item_func_rpad(*session, arg1, arg2, arg3);
784 }
785
786 static Create_func_rpad s_singleton;
787};
788
789Create_func_rpad Create_func_rpad::s_singleton;
790
792{
793public:
795
796 virtual Item* create(Session *session, Item *arg1)
797 {
798 return new (session->mem) Item_func_rtrim(arg1);
799 }
800
801 static Create_func_rtrim s_singleton;
802};
803
804Create_func_rtrim Create_func_rtrim::s_singleton;
805
807{
808public:
810
811 virtual Item* create(Session *session, Item *arg1)
812 {
813 return new (session->mem) Item_func_sign(arg1);
814 }
815
816 static Create_func_sign s_singleton;
817};
818
819Create_func_sign Create_func_sign::s_singleton;
820
822{
823public:
825
826 virtual Item* create(Session *session, Item *arg1);
827
828 static Create_func_space s_singleton;
829};
830
832{
833public:
835
836 virtual Item* create(Session *session, Item *arg1, Item *arg2)
837 {
838 return new (session->mem) Item_func_strcmp(arg1, arg2);
839 }
840
841 static Create_func_strcmp s_singleton;
842};
843
844Create_func_strcmp Create_func_strcmp::s_singleton;
845
847{
848public:
850
851 virtual Item* create(Session *session, Item *arg1)
852 {
853 return new (session->mem) Item_func_tan(arg1);
854 }
855
856 static Create_func_tan s_singleton;
857};
858
859Create_func_tan Create_func_tan::s_singleton;
860
862{
863public:
865
866 virtual Item* create(Session *session, Item *arg1, Item *arg2)
867 {
868 return new (session->mem) Item_func_date_format(arg1, arg2, 1);
869 }
870
871 static Create_func_time_format s_singleton;
872};
873
874Create_func_time_format Create_func_time_format::s_singleton;
875
877{
878public:
880
881 virtual Item* create(Session *session, Item *arg1)
882 {
883 return new (session->mem) Item_func_to_days(arg1);
884 }
885
886 static Create_func_to_days s_singleton;
887};
888
889Create_func_to_days Create_func_to_days::s_singleton;
890
892{
893public:
895
896 virtual Item* create(Session *session, Item *arg1)
897 {
898 return new (session->mem) Item_func_ucase(arg1);
899 }
900
901 static Create_func_ucase s_singleton;
902};
903
904Create_func_ucase Create_func_ucase::s_singleton;
905
907{
908public:
909 virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
910
911 static Create_func_unix_timestamp s_singleton;
912};
913
914
916{
917public:
919
920 virtual Item* create(Session *session, Item *arg1)
921 {
922 return new (session->mem) Item_func_weekday(arg1, 0);
923 }
924
925 static Create_func_weekday s_singleton;
926};
927
928Create_func_weekday Create_func_weekday::s_singleton;
929
930/*
931=============================================================================
932 IMPLEMENTATION
933=============================================================================
934*/
935
936Create_udf_func Create_udf_func::s_singleton;
937
938Item* Create_udf_func::create(Session *session, str_ref name, List<Item> *item_list)
939{
940 return create(session, plugin::Function::get(to_string(name)), item_list);
941}
942
944{
945 assert(udf);
946 Item_func* func= (*udf)(&session->mem);
947 if (!func->check_argument_count(item_list ? item_list->size() : 0))
948 {
949 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), func->func_name());
950 return NULL;
951 }
952 if (item_list)
953 func->set_arguments(*item_list);
954 return func;
955}
956
957Item* Create_func_arg0::create(Session *session, str_ref name, List<Item> *item_list)
958{
959 if (not item_list || not item_list->size())
960 return create(session);
961 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
962 return NULL;
963}
964
965Item* Create_func_arg1::create(Session *session, str_ref name, List<Item> *item_list)
966{
967 if (not item_list || item_list->size() != 1)
968 {
969 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
970 return NULL;
971 }
972
973 Item *param_1= item_list->pop();
974 if (param_1->is_autogenerated_name)
975 return create(session, param_1);
976 my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.data());
977 return NULL;
978}
979
980Item* Create_func_arg2::create(Session *session, str_ref name, List<Item> *item_list)
981{
982 if (not item_list || item_list->size() != 2)
983 {
984 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
985 return NULL;
986 }
987
988 Item *param_1= item_list->pop();
989 Item *param_2= item_list->pop();
990
991 if (param_1->is_autogenerated_name
992 && param_2->is_autogenerated_name)
993 return create(session, param_1, param_2);
994 my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.data());
995 return NULL;
996}
997
998Item* Create_func_arg3::create(Session *session, str_ref name, List<Item> *item_list)
999{
1000 if (not item_list || item_list->size() != 3)
1001 {
1002 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1003 return NULL;
1004 }
1005
1006 Item *param_1= item_list->pop();
1007 Item *param_2= item_list->pop();
1008 Item *param_3= item_list->pop();
1009
1010 if (param_1->is_autogenerated_name
1011 && param_2->is_autogenerated_name
1012 && param_3->is_autogenerated_name)
1013 return create(session, param_1, param_2, param_3);
1014 my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.data());
1015 return NULL;
1016}
1017
1018Create_func_bin Create_func_bin::s_singleton;
1019
1021{
1022 Item *i10= new (session->mem) Item_int(10, 2);
1023 Item *i2= new (session->mem) Item_int(2, 1);
1024 return new (session->mem) Item_func_conv(arg1, i10, i2);
1025}
1026
1027Create_func_concat Create_func_concat::s_singleton;
1028
1029Item* Create_func_concat::create_native(Session *session, str_ref name, List<Item> *item_list)
1030{
1031 if (item_list && item_list->size() >= 1)
1032 return new (session->mem) Item_func_concat(*session, *item_list);
1033 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1034 return NULL;
1035}
1036
1037Create_func_concat_ws Create_func_concat_ws::s_singleton;
1038
1040{
1041 /* "WS" stands for "With Separator": this function takes 2+ arguments */
1042 if (item_list && item_list->size() >= 2)
1043 return new (session->mem) Item_func_concat_ws(*session, *item_list);
1044 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1045 return NULL;
1046}
1047
1048Create_func_cot Create_func_cot::s_singleton;
1049
1050Item*
1052{
1053 Item *i1= new (session->mem) Item_int("1", 1, 1);
1054 Item *i2= new (session->mem) Item_func_tan(arg1);
1055 return new (session->mem) Item_func_div(session, i1, i2);
1056}
1057
1058Create_func_datediff Create_func_datediff::s_singleton;
1059
1060Item*
1062{
1063 Item *i1= new (session->mem) Item_func_to_days(arg1);
1064 Item *i2= new (session->mem) Item_func_to_days(arg2);
1065 return new (session->mem) Item_func_minus(i1, i2);
1066}
1067
1068Create_func_export_set Create_func_export_set::s_singleton;
1069
1070Item*
1072{
1073 switch (item_list ? item_list->size() : 0)
1074 {
1075 case 3:
1076 {
1077 Item *param_1= item_list->pop();
1078 Item *param_2= item_list->pop();
1079 Item *param_3= item_list->pop();
1080 return new (session->mem) Item_func_export_set(param_1, param_2, param_3);
1081 }
1082 case 4:
1083 {
1084 Item *param_1= item_list->pop();
1085 Item *param_2= item_list->pop();
1086 Item *param_3= item_list->pop();
1087 Item *param_4= item_list->pop();
1088 return new (session->mem) Item_func_export_set(param_1, param_2, param_3, param_4);
1089 }
1090 case 5:
1091 {
1092 Item *param_1= item_list->pop();
1093 Item *param_2= item_list->pop();
1094 Item *param_3= item_list->pop();
1095 Item *param_4= item_list->pop();
1096 Item *param_5= item_list->pop();
1097 return new (session->mem) Item_func_export_set(param_1, param_2, param_3, param_4, param_5);
1098 }
1099 }
1100 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1101 return NULL;
1102}
1103
1104
1105Create_func_field Create_func_field::s_singleton;
1106
1107Item* Create_func_field::create_native(Session *session, str_ref name, List<Item> *item_list)
1108{
1109 if (item_list && item_list->size() >= 2)
1110 return new (session->mem) Item_func_field(*item_list);
1111 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1112 return NULL;
1113}
1114
1115Create_func_find_in_set Create_func_find_in_set::s_singleton;
1116Create_func_found_rows Create_func_found_rows::s_singleton;
1117Create_func_from_days Create_func_from_days::s_singleton;
1118Create_func_from_unixtime Create_func_from_unixtime::s_singleton;
1119
1121{
1122 switch (item_list ? item_list->size() : 0)
1123 {
1124 case 1:
1125 {
1126 Item *param_1= item_list->pop();
1127 return new (session->mem) Item_func_from_unixtime(param_1);
1128 }
1129 case 2:
1130 {
1131 Item *param_1= item_list->pop();
1132 Item *param_2= item_list->pop();
1133 Item *ut= new (session->mem) Item_func_from_unixtime(param_1);
1134 return new (session->mem) Item_func_date_format(ut, param_2, 0);
1135 }
1136 }
1137 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1138 return NULL;
1139}
1140
1141Create_func_greatest Create_func_greatest::s_singleton;
1142
1144{
1145 if (item_list && item_list->size() >= 2)
1146 return new (session->mem) Item_func_max(*item_list);
1147 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1148 return NULL;
1149}
1150
1151Create_func_ifnull Create_func_ifnull::s_singleton;
1152Create_func_instr Create_func_instr::s_singleton;
1153Create_func_isnull Create_func_isnull::s_singleton;
1154Create_func_last_day Create_func_last_day::s_singleton;
1155Create_func_last_insert_id Create_func_last_insert_id::s_singleton;
1156
1158{
1159 int arg_count= item_list ? item_list->size() : 0;
1160 switch (arg_count)
1161 {
1162 case 0:
1163 {
1164 return new (session->mem) Item_func_last_insert_id();
1165 }
1166 case 1:
1167 {
1168 Item *param_1= item_list->pop();
1169 return new (session->mem) Item_func_last_insert_id(param_1);
1170 }
1171 }
1172 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1173 return NULL;
1174}
1175
1176Create_func_lcase Create_func_lcase::s_singleton;
1177Create_func_least Create_func_least::s_singleton;
1178
1179Item* Create_func_least::create_native(Session *session, str_ref name, List<Item> *item_list)
1180{
1181 if (item_list && item_list->size() >= 2)
1182 return new (session->mem) Item_func_min(*item_list);
1183 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1184 return NULL;
1185}
1186
1187Create_func_load_file Create_func_load_file::s_singleton;
1188Create_func_locate Create_func_locate::s_singleton;
1189
1190Item* Create_func_locate::create_native(Session *session, str_ref name, List<Item> *item_list)
1191{
1192 switch (item_list ? item_list->size() : 0)
1193 {
1194 case 2:
1195 {
1196 Item *param_1= item_list->pop();
1197 Item *param_2= item_list->pop();
1198 /* Yes, parameters in that order : 2, 1 */
1199 return new (session->mem) Item_func_locate(param_2, param_1);
1200 }
1201 case 3:
1202 {
1203 Item *param_1= item_list->pop();
1204 Item *param_2= item_list->pop();
1205 Item *param_3= item_list->pop();
1206 /* Yes, parameters in that order : 2, 1, 3 */
1207 return new (session->mem) Item_func_locate(param_2, param_1, param_3);
1208 }
1209 }
1210 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1211 return NULL;
1212}
1213
1214Create_func_make_set Create_func_make_set::s_singleton;
1215
1216Item* Create_func_make_set::create_native(Session *session_arg, str_ref name, List<Item> *item_list)
1217{
1218 if (not item_list || item_list->size() < 2)
1219 {
1220 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1221 return NULL;
1222 }
1223
1224 Item *param_1= item_list->pop();
1225 return new (session_arg->mem) Item_func_make_set(*session_arg, param_1, *item_list);
1226}
1227
1228Create_func_oct Create_func_oct::s_singleton;
1229
1231{
1232 Item *i10= new (session->mem) Item_int((int32_t) 10,2);
1233 Item *i8= new (session->mem) Item_int((int32_t) 8,1);
1234 return new (session->mem) Item_func_conv(arg1, i10, i8);
1235}
1236
1237Create_func_period_add Create_func_period_add::s_singleton;
1238Create_func_period_diff Create_func_period_diff::s_singleton;
1239Create_func_pi Create_func_pi::s_singleton;
1240Create_func_radians Create_func_radians::s_singleton;
1241Create_func_round Create_func_round::s_singleton;
1242
1243Item* Create_func_round::create_native(Session *session, str_ref name, List<Item> *item_list)
1244{
1245 switch (item_list ? item_list->size() : 0)
1246 {
1247 case 1:
1248 {
1249 Item *param_1= item_list->pop();
1250 Item *i0 = new (session->mem) Item_int("0", 0, 1);
1251 return new (session->mem) Item_func_round(param_1, i0, 0);
1252 }
1253 case 2:
1254 {
1255 Item *param_1= item_list->pop();
1256 Item *param_2= item_list->pop();
1257 return new (session->mem) Item_func_round(param_1, param_2, 0);
1258 }
1259 }
1260 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1261 return NULL;
1262}
1263
1264Create_func_space Create_func_space::s_singleton;
1265
1267{
1273 const charset_info_st * const cs= session->variables.getCollation();
1274 Item *sp;
1275
1276 if (cs->mbminlen > 1)
1277 {
1278 sp= new (session->mem) Item_string(str_ref(""), cs, DERIVATION_COERCIBLE);
1279 sp->str_value.copy(" ", 1, cs);
1280 }
1281 else
1282 {
1283 sp= new (session->mem) Item_string(str_ref(" "), cs, DERIVATION_COERCIBLE);
1284 }
1285
1286 return new (session->mem) Item_func_repeat(*session, sp, arg1);
1287}
1288
1289Create_func_unix_timestamp Create_func_unix_timestamp::s_singleton;
1290
1292{
1293 switch (item_list ? item_list->size() : 0)
1294 {
1295 case 0:
1296 return new (session->mem) Item_func_unix_timestamp();
1297 case 1:
1298 return new (session->mem) Item_func_unix_timestamp(item_list->pop());
1299 }
1300 my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1301 return NULL;
1302}
1303
1304
1306{
1307 const char* name;
1308 Create_func *builder;
1309};
1310
1311#define BUILDER(F) & F::s_singleton
1312
1313/*
1314 MySQL native functions.
1315 MAINTAINER:
1316 - Keep sorted for human lookup. At runtime, a hash table is used.
1317 - keep 1 line per entry, it makes grep | sort easier
1318*/
1319
1320static Native_func_registry func_array[] =
1321{
1322 { "BIN", BUILDER(Create_func_bin)},
1323 { "CONCAT", BUILDER(Create_func_concat)},
1324 { "CONCAT_WS", BUILDER(Create_func_concat_ws)},
1325 { "CONV", BUILDER(Create_func_conv)},
1326 { "COT", BUILDER(Create_func_cot)},
1327 { "DATEDIFF", BUILDER(Create_func_datediff)},
1328 { "DATE_FORMAT", BUILDER(Create_func_date_format)},
1329 { "DAYNAME", BUILDER(Create_func_dayname)},
1330 { "DAYOFMONTH", BUILDER(Create_func_dayofmonth)},
1331 { "DAYOFWEEK", BUILDER(Create_func_dayofweek)},
1332 { "DAYOFYEAR", BUILDER(Create_func_dayofyear)},
1333 { "DEGREES", BUILDER(Create_func_degrees)},
1334 { "EXPORT_SET", BUILDER(Create_func_export_set)},
1335 { "FIELD", BUILDER(Create_func_field)},
1336 { "FIND_IN_SET", BUILDER(Create_func_find_in_set)},
1337 { "FOUND_ROWS", BUILDER(Create_func_found_rows)},
1338 { "FROM_DAYS", BUILDER(Create_func_from_days)},
1339 { "FROM_UNIXTIME", BUILDER(Create_func_from_unixtime)},
1340 { "GREATEST", BUILDER(Create_func_greatest)},
1341 { "IFNULL", BUILDER(Create_func_ifnull)},
1342 { "INSTR", BUILDER(Create_func_instr)},
1343 { "ISNULL", BUILDER(Create_func_isnull)},
1344 { "LAST_DAY", BUILDER(Create_func_last_day)},
1345 { "LAST_INSERT_ID", BUILDER(Create_func_last_insert_id)},
1346 { "LCASE", BUILDER(Create_func_lcase)},
1347 { "LEAST", BUILDER(Create_func_least)},
1348 { "LOAD_FILE", BUILDER(Create_func_load_file)},
1349 { "LOCATE", BUILDER(Create_func_locate)},
1350 { "LOWER", BUILDER(Create_func_lcase)},
1351 { "LPAD", BUILDER(Create_func_lpad)},
1352 { "LTRIM", BUILDER(Create_func_ltrim)},
1353 { "MAKEDATE", BUILDER(Create_func_makedate)},
1354 { "MAKE_SET", BUILDER(Create_func_make_set)},
1355 { "MONTHNAME", BUILDER(Create_func_monthname)},
1356 { "NULLIF", BUILDER(Create_func_nullif)},
1357 { "OCT", BUILDER(Create_func_oct)},
1358 { "PERIOD_ADD", BUILDER(Create_func_period_add)},
1359 { "PERIOD_DIFF", BUILDER(Create_func_period_diff)},
1360 { "PI", BUILDER(Create_func_pi)},
1361 { "RADIANS", BUILDER(Create_func_radians)},
1362 { "ROUND", BUILDER(Create_func_round)},
1363 { "ROW_COUNT", BUILDER(Create_func_row_count)},
1364 { "RPAD", BUILDER(Create_func_rpad)},
1365 { "RTRIM", BUILDER(Create_func_rtrim)},
1366 { "SIGN", BUILDER(Create_func_sign)},
1367 { "SPACE", BUILDER(Create_func_space)},
1368 { "STRCMP", BUILDER(Create_func_strcmp)},
1369 { "TAN", BUILDER(Create_func_tan)},
1370 { "TIME_FORMAT", BUILDER(Create_func_time_format)},
1371 { "TO_DAYS", BUILDER(Create_func_to_days)},
1372 { "UCASE", BUILDER(Create_func_ucase)},
1373 { "UNIX_TIMESTAMP", BUILDER(Create_func_unix_timestamp)},
1374 { "UPPER", BUILDER(Create_func_ucase)},
1375 { "WEEKDAY", BUILDER(Create_func_weekday)},
1376 { NULL, NULL}
1377};
1378
1379/*
1380 Load the hash table for native functions.
1381 Note: this code is not thread safe, and is intended to be used at server
1382 startup only (before going multi-threaded)
1383*/
1384
1385void item_create_init()
1386{
1387 for (Native_func_registry* func= func_array; func->builder; func++)
1388 FunctionContainer::getMutableMap()[func->name]= func->builder;
1389}
1390
1392{
1393 return find_ptr2(FunctionContainer::getMap(), name.data());
1394}
1395
1396Item* create_func_char_cast(Session *session, Item *a, int len, const charset_info_st* cs)
1397{
1398 return new (session->mem) Item_char_typecast(a, len, cs ? cs : session->variables.getCollation());
1399}
1400
1401Item* create_func_cast(Session *session, Item *a, Cast_target cast_type, const char *c_len, const char *c_dec, const charset_info_st * const cs)
1402{
1403 switch (cast_type)
1404 {
1405 case ITEM_CAST_SIGNED:
1406 return new (session->mem) function::cast::Signed(a);
1407 case ITEM_CAST_UNSIGNED:
1408 return new (session->mem) function::cast::Unsigned(a);
1409 case ITEM_CAST_BINARY:
1410 return new (session->mem) Item_func_binary(a);
1411 case ITEM_CAST_BOOLEAN:
1412 return new (session->mem) function::cast::Boolean(a);
1413 case ITEM_CAST_TIME:
1414 return new (session->mem) function::cast::Time(a);
1415 case ITEM_CAST_DATE:
1416 return new (session->mem) Item_date_typecast(a);
1417 case ITEM_CAST_DATETIME:
1418 return new (session->mem) Item_datetime_typecast(a);
1419 case ITEM_CAST_DECIMAL:
1420 {
1421 uint32_t len= c_len ? atoi(c_len) : 0;
1422 uint32_t dec= c_dec ? atoi(c_dec) : 0;
1423 class_decimal_trim(&len, &dec);
1424 if (len < dec)
1425 {
1426 my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
1427 return 0;
1428 }
1429 if (len > DECIMAL_MAX_PRECISION)
1430 {
1431 my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name, DECIMAL_MAX_PRECISION);
1432 return 0;
1433 }
1434 if (dec > DECIMAL_MAX_SCALE)
1435 {
1436 my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name, DECIMAL_MAX_SCALE);
1437 return 0;
1438 }
1439 return new (session->mem) Item_decimal_typecast(a, len, dec);
1440 }
1441 case ITEM_CAST_CHAR:
1442 return create_func_char_cast(session, a, c_len ? atoi(c_len) : -1, cs);
1443 }
1444 return NULL;
1445}
1446
1447} /* namespace drizzled */
virtual Item * create(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create(Session *session)=0
virtual Item * create(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create(Session *session, Item *arg1)=0
virtual Item * create(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create(Session *session, Item *arg1, Item *arg2)=0
virtual Item * create(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create(Session *session, Item *arg1, Item *arg2, Item *arg3)=0
virtual Item * create(Session *session, Item *arg1)
virtual Item * create_native(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create_native(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create(Session *session, Item *arg1, Item *arg2, Item *arg3)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create(Session *session, Item *arg1, Item *arg2)
virtual Item * create(Session *session, Item *arg1, Item *arg2)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create(Session *session, Item *arg1, Item *arg2)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create_native(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create_native(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create(Session *session, Item *arg1, Item *arg2)
virtual Item * create(Session *session)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create_native(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create_native(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create(Session *session, Item *arg1, Item *arg2)
virtual Item * create(Session *session, Item *arg1, Item *arg2)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create_native(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create_native(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create_native(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create(Session *session, Item *arg1, Item *arg2, Item *arg3)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create_native(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create(Session *session, Item *arg1, Item *arg2)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create(Session *session, Item *arg1, Item *arg2)
virtual Item * create(Session *session, Item *arg1, Item *arg2)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create(Session *session, Item *arg1, Item *arg2)
virtual Item * create(Session *session, Item *arg1, Item *arg2)
virtual Item * create(Session *session)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create_native(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create(Session *session)
virtual Item * create(Session *session, Item *arg1, Item *arg2, Item *arg3)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create(Session *session, Item *arg1, Item *arg2)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create(Session *session, Item *arg1, Item *arg2)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create_native(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create(Session *session, Item *arg1)
virtual Item * create(Session *session, str_ref name, List< Item > *item_list)
virtual Item * create_native(Session *, str_ref name, List< Item > *)=0
virtual Item * create(Session *, str_ref name, List< Item > *item_list)
static Create_udf_func s_singleton
virtual bool check_argument_count(int)
bool is_autogenerated_name
Definition item.h:138
const char * name
Definition item.h:112
String str_value
Definition item.h:109
TODO: Rename this file - func.h is stupid.
Item * create_func_cast(Session *session, Item *a, Cast_target cast_type, const char *c_len, const char *c_dec, const charset_info_st *const cs)
static bool has_named_parameters(List< Item > &params)
Create_func * find_native_function_builder(str_ref name)
STL namespace.