~drizzle-trunk/drizzle/development

1 by brian
clean slate
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
/**
17
  @file
18
19
  @brief
20
  Functions to create an item. Used by sql_yac.yy
21
*/
22
23
#include "mysql_priv.h"
24
#include "item_create.h"
25
26
/*
27
=============================================================================
28
  LOCAL DECLARATIONS
29
=============================================================================
30
*/
31
32
/**
33
  Adapter for native functions with a variable number of arguments.
34
  The main use of this class is to discard the following calls:
35
  <code>foo(expr1 AS name1, expr2 AS name2, ...)</code>
36
  which are syntactically correct (the syntax can refer to a UDF),
37
  but semantically invalid for native functions.
38
*/
39
40
class Create_native_func : public Create_func
41
{
42
public:
43
  virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
44
45
  /**
46
    Builder method, with no arguments.
47
    @param thd The current thread
48
    @param name The native function name
49
    @param item_list The function parameters, none of which are named
50
    @return An item representing the function call
51
  */
52
  virtual Item *create_native(THD *thd, LEX_STRING name,
53
                              List<Item> *item_list) = 0;
54
55
protected:
56
  /** Constructor. */
57
  Create_native_func() {}
58
  /** Destructor. */
59
  virtual ~Create_native_func() {}
60
};
61
62
63
/**
64
  Adapter for functions that takes exactly zero arguments.
65
*/
66
67
class Create_func_arg0 : public Create_func
68
{
69
public:
70
  virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
71
72
  /**
73
    Builder method, with no arguments.
74
    @param thd The current thread
75
    @return An item representing the function call
76
  */
77
  virtual Item *create(THD *thd) = 0;
78
79
protected:
80
  /** Constructor. */
81
  Create_func_arg0() {}
82
  /** Destructor. */
83
  virtual ~Create_func_arg0() {}
84
};
85
86
87
/**
88
  Adapter for functions that takes exactly one argument.
89
*/
90
91
class Create_func_arg1 : public Create_func
92
{
93
public:
94
  virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
95
96
  /**
97
    Builder method, with one argument.
98
    @param thd The current thread
99
    @param arg1 The first argument of the function
100
    @return An item representing the function call
101
  */
102
  virtual Item *create(THD *thd, Item *arg1) = 0;
103
104
protected:
105
  /** Constructor. */
106
  Create_func_arg1() {}
107
  /** Destructor. */
108
  virtual ~Create_func_arg1() {}
109
};
110
111
112
/**
113
  Adapter for functions that takes exactly two arguments.
114
*/
115
116
class Create_func_arg2 : public Create_func
117
{
118
public:
119
  virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
120
121
  /**
122
    Builder method, with two arguments.
123
    @param thd The current thread
124
    @param arg1 The first argument of the function
125
    @param arg2 The second argument of the function
126
    @return An item representing the function call
127
  */
128
  virtual Item *create(THD *thd, Item *arg1, Item *arg2) = 0;
129
130
protected:
131
  /** Constructor. */
132
  Create_func_arg2() {}
133
  /** Destructor. */
134
  virtual ~Create_func_arg2() {}
135
};
136
137
138
/**
139
  Adapter for functions that takes exactly three arguments.
140
*/
141
142
class Create_func_arg3 : public Create_func
143
{
144
public:
145
  virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
146
147
  /**
148
    Builder method, with three arguments.
149
    @param thd The current thread
150
    @param arg1 The first argument of the function
151
    @param arg2 The second argument of the function
152
    @param arg3 The third argument of the function
153
    @return An item representing the function call
154
  */
155
  virtual Item *create(THD *thd, Item *arg1, Item *arg2, Item *arg3) = 0;
156
157
protected:
158
  /** Constructor. */
159
  Create_func_arg3() {}
160
  /** Destructor. */
161
  virtual ~Create_func_arg3() {}
162
};
163
164
165
/**
166
  Function builder for Stored Functions.
167
*/
168
169
/*
170
  Concrete functions builders (native functions).
171
  Please keep this list sorted in alphabetical order,
172
  it helps to compare code between versions, and helps with merges conflicts.
173
*/
174
175
class Create_func_abs : public Create_func_arg1
176
{
177
public:
178
  virtual Item *create(THD *thd, Item *arg1);
179
180
  static Create_func_abs s_singleton;
181
182
protected:
183
  Create_func_abs() {}
184
  virtual ~Create_func_abs() {}
185
};
186
187
188
class Create_func_acos : public Create_func_arg1
189
{
190
public:
191
  virtual Item *create(THD *thd, Item *arg1);
192
193
  static Create_func_acos s_singleton;
194
195
protected:
196
  Create_func_acos() {}
197
  virtual ~Create_func_acos() {}
198
};
199
200
201
class Create_func_addtime : public Create_func_arg2
202
{
203
public:
204
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
205
206
  static Create_func_addtime s_singleton;
207
208
protected:
209
  Create_func_addtime() {}
210
  virtual ~Create_func_addtime() {}
211
};
212
213
214
class Create_func_asin : public Create_func_arg1
215
{
216
public:
217
  virtual Item *create(THD *thd, Item *arg1);
218
219
  static Create_func_asin s_singleton;
220
221
protected:
222
  Create_func_asin() {}
223
  virtual ~Create_func_asin() {}
224
};
225
226
227
class Create_func_atan : public Create_native_func
228
{
229
public:
230
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
231
232
  static Create_func_atan s_singleton;
233
234
protected:
235
  Create_func_atan() {}
236
  virtual ~Create_func_atan() {}
237
};
238
239
240
class Create_func_benchmark : public Create_func_arg2
241
{
242
public:
243
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
244
245
  static Create_func_benchmark s_singleton;
246
247
protected:
248
  Create_func_benchmark() {}
249
  virtual ~Create_func_benchmark() {}
250
};
251
252
253
class Create_func_bin : public Create_func_arg1
254
{
255
public:
256
  virtual Item *create(THD *thd, Item *arg1);
257
258
  static Create_func_bin s_singleton;
259
260
protected:
261
  Create_func_bin() {}
262
  virtual ~Create_func_bin() {}
263
};
264
265
266
class Create_func_bit_count : public Create_func_arg1
267
{
268
public:
269
  virtual Item *create(THD *thd, Item *arg1);
270
271
  static Create_func_bit_count s_singleton;
272
273
protected:
274
  Create_func_bit_count() {}
275
  virtual ~Create_func_bit_count() {}
276
};
277
278
279
class Create_func_bit_length : public Create_func_arg1
280
{
281
public:
282
  virtual Item *create(THD *thd, Item *arg1);
283
284
  static Create_func_bit_length s_singleton;
285
286
protected:
287
  Create_func_bit_length() {}
288
  virtual ~Create_func_bit_length() {}
289
};
290
291
292
class Create_func_ceiling : public Create_func_arg1
293
{
294
public:
295
  virtual Item *create(THD *thd, Item *arg1);
296
297
  static Create_func_ceiling s_singleton;
298
299
protected:
300
  Create_func_ceiling() {}
301
  virtual ~Create_func_ceiling() {}
302
};
303
304
305
class Create_func_char_length : public Create_func_arg1
306
{
307
public:
308
  virtual Item *create(THD *thd, Item *arg1);
309
310
  static Create_func_char_length s_singleton;
311
312
protected:
313
  Create_func_char_length() {}
314
  virtual ~Create_func_char_length() {}
315
};
316
317
318
class Create_func_coercibility : public Create_func_arg1
319
{
320
public:
321
  virtual Item *create(THD *thd, Item *arg1);
322
323
  static Create_func_coercibility s_singleton;
324
325
protected:
326
  Create_func_coercibility() {}
327
  virtual ~Create_func_coercibility() {}
328
};
329
330
331
class Create_func_concat : public Create_native_func
332
{
333
public:
334
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
335
336
  static Create_func_concat s_singleton;
337
338
protected:
339
  Create_func_concat() {}
340
  virtual ~Create_func_concat() {}
341
};
342
343
344
class Create_func_concat_ws : public Create_native_func
345
{
346
public:
347
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
348
349
  static Create_func_concat_ws s_singleton;
350
351
protected:
352
  Create_func_concat_ws() {}
353
  virtual ~Create_func_concat_ws() {}
354
};
355
356
357
class Create_func_connection_id : public Create_func_arg0
358
{
359
public:
360
  virtual Item *create(THD *thd);
361
362
  static Create_func_connection_id s_singleton;
363
364
protected:
365
  Create_func_connection_id() {}
366
  virtual ~Create_func_connection_id() {}
367
};
368
369
370
class Create_func_conv : public Create_func_arg3
371
{
372
public:
373
  virtual Item *create(THD *thd, Item *arg1, Item *arg2, Item *arg3);
374
375
  static Create_func_conv s_singleton;
376
377
protected:
378
  Create_func_conv() {}
379
  virtual ~Create_func_conv() {}
380
};
381
382
383
class Create_func_cos : public Create_func_arg1
384
{
385
public:
386
  virtual Item *create(THD *thd, Item *arg1);
387
388
  static Create_func_cos s_singleton;
389
390
protected:
391
  Create_func_cos() {}
392
  virtual ~Create_func_cos() {}
393
};
394
395
396
class Create_func_cot : public Create_func_arg1
397
{
398
public:
399
  virtual Item *create(THD *thd, Item *arg1);
400
401
  static Create_func_cot s_singleton;
402
403
protected:
404
  Create_func_cot() {}
405
  virtual ~Create_func_cot() {}
406
};
407
408
409
class Create_func_crc32 : public Create_func_arg1
410
{
411
public:
412
  virtual Item *create(THD *thd, Item *arg1);
413
414
  static Create_func_crc32 s_singleton;
415
416
protected:
417
  Create_func_crc32() {}
418
  virtual ~Create_func_crc32() {}
419
};
420
421
422
class Create_func_date_format : public Create_func_arg2
423
{
424
public:
425
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
426
427
  static Create_func_date_format s_singleton;
428
429
protected:
430
  Create_func_date_format() {}
431
  virtual ~Create_func_date_format() {}
432
};
433
434
435
class Create_func_datediff : public Create_func_arg2
436
{
437
public:
438
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
439
440
  static Create_func_datediff s_singleton;
441
442
protected:
443
  Create_func_datediff() {}
444
  virtual ~Create_func_datediff() {}
445
};
446
447
448
class Create_func_dayname : public Create_func_arg1
449
{
450
public:
451
  virtual Item *create(THD *thd, Item *arg1);
452
453
  static Create_func_dayname s_singleton;
454
455
protected:
456
  Create_func_dayname() {}
457
  virtual ~Create_func_dayname() {}
458
};
459
460
461
class Create_func_dayofmonth : public Create_func_arg1
462
{
463
public:
464
  virtual Item *create(THD *thd, Item *arg1);
465
466
  static Create_func_dayofmonth s_singleton;
467
468
protected:
469
  Create_func_dayofmonth() {}
470
  virtual ~Create_func_dayofmonth() {}
471
};
472
473
474
class Create_func_dayofweek : public Create_func_arg1
475
{
476
public:
477
  virtual Item *create(THD *thd, Item *arg1);
478
479
  static Create_func_dayofweek s_singleton;
480
481
protected:
482
  Create_func_dayofweek() {}
483
  virtual ~Create_func_dayofweek() {}
484
};
485
486
487
class Create_func_dayofyear : public Create_func_arg1
488
{
489
public:
490
  virtual Item *create(THD *thd, Item *arg1);
491
492
  static Create_func_dayofyear s_singleton;
493
494
protected:
495
  Create_func_dayofyear() {}
496
  virtual ~Create_func_dayofyear() {}
497
};
498
499
500
class Create_func_decode : public Create_func_arg2
501
{
502
public:
503
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
504
505
  static Create_func_decode s_singleton;
506
507
protected:
508
  Create_func_decode() {}
509
  virtual ~Create_func_decode() {}
510
};
511
512
513
class Create_func_degrees : public Create_func_arg1
514
{
515
public:
516
  virtual Item *create(THD *thd, Item *arg1);
517
518
  static Create_func_degrees s_singleton;
519
520
protected:
521
  Create_func_degrees() {}
522
  virtual ~Create_func_degrees() {}
523
};
524
525
526
class Create_func_elt : public Create_native_func
527
{
528
public:
529
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
530
531
  static Create_func_elt s_singleton;
532
533
protected:
534
  Create_func_elt() {}
535
  virtual ~Create_func_elt() {}
536
};
537
538
539
class Create_func_encode : public Create_func_arg2
540
{
541
public:
542
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
543
544
  static Create_func_encode s_singleton;
545
546
protected:
547
  Create_func_encode() {}
548
  virtual ~Create_func_encode() {}
549
};
550
551
552
class Create_func_encrypt : public Create_native_func
553
{
554
public:
555
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
556
557
  static Create_func_encrypt s_singleton;
558
559
protected:
560
  Create_func_encrypt() {}
561
  virtual ~Create_func_encrypt() {}
562
};
563
564
565
class Create_func_exp : public Create_func_arg1
566
{
567
public:
568
  virtual Item *create(THD *thd, Item *arg1);
569
570
  static Create_func_exp s_singleton;
571
572
protected:
573
  Create_func_exp() {}
574
  virtual ~Create_func_exp() {}
575
};
576
577
578
class Create_func_export_set : public Create_native_func
579
{
580
public:
581
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
582
583
  static Create_func_export_set s_singleton;
584
585
protected:
586
  Create_func_export_set() {}
587
  virtual ~Create_func_export_set() {}
588
};
589
590
591
class Create_func_field : public Create_native_func
592
{
593
public:
594
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
595
596
  static Create_func_field s_singleton;
597
598
protected:
599
  Create_func_field() {}
600
  virtual ~Create_func_field() {}
601
};
602
603
604
class Create_func_find_in_set : public Create_func_arg2
605
{
606
public:
607
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
608
609
  static Create_func_find_in_set s_singleton;
610
611
protected:
612
  Create_func_find_in_set() {}
613
  virtual ~Create_func_find_in_set() {}
614
};
615
616
617
class Create_func_floor : public Create_func_arg1
618
{
619
public:
620
  virtual Item *create(THD *thd, Item *arg1);
621
622
  static Create_func_floor s_singleton;
623
624
protected:
625
  Create_func_floor() {}
626
  virtual ~Create_func_floor() {}
627
};
628
629
630
class Create_func_format : public Create_func_arg2
631
{
632
public:
633
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
634
635
  static Create_func_format s_singleton;
636
637
protected:
638
  Create_func_format() {}
639
  virtual ~Create_func_format() {}
640
};
641
642
643
class Create_func_found_rows : public Create_func_arg0
644
{
645
public:
646
  virtual Item *create(THD *thd);
647
648
  static Create_func_found_rows s_singleton;
649
650
protected:
651
  Create_func_found_rows() {}
652
  virtual ~Create_func_found_rows() {}
653
};
654
655
656
class Create_func_from_days : public Create_func_arg1
657
{
658
public:
659
  virtual Item *create(THD *thd, Item *arg1);
660
661
  static Create_func_from_days s_singleton;
662
663
protected:
664
  Create_func_from_days() {}
665
  virtual ~Create_func_from_days() {}
666
};
667
668
669
class Create_func_from_unixtime : public Create_native_func
670
{
671
public:
672
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
673
674
  static Create_func_from_unixtime s_singleton;
675
676
protected:
677
  Create_func_from_unixtime() {}
678
  virtual ~Create_func_from_unixtime() {}
679
};
680
681
682
class Create_func_greatest : public Create_native_func
683
{
684
public:
685
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
686
687
  static Create_func_greatest s_singleton;
688
689
protected:
690
  Create_func_greatest() {}
691
  virtual ~Create_func_greatest() {}
692
};
693
694
695
class Create_func_hex : public Create_func_arg1
696
{
697
public:
698
  virtual Item *create(THD *thd, Item *arg1);
699
700
  static Create_func_hex s_singleton;
701
702
protected:
703
  Create_func_hex() {}
704
  virtual ~Create_func_hex() {}
705
};
706
707
708
class Create_func_ifnull : public Create_func_arg2
709
{
710
public:
711
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
712
713
  static Create_func_ifnull s_singleton;
714
715
protected:
716
  Create_func_ifnull() {}
717
  virtual ~Create_func_ifnull() {}
718
};
719
720
721
class Create_func_instr : public Create_func_arg2
722
{
723
public:
724
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
725
726
  static Create_func_instr s_singleton;
727
728
protected:
729
  Create_func_instr() {}
730
  virtual ~Create_func_instr() {}
731
};
732
733
734
class Create_func_isnull : public Create_func_arg1
735
{
736
public:
737
  virtual Item *create(THD *thd, Item *arg1);
738
739
  static Create_func_isnull s_singleton;
740
741
protected:
742
  Create_func_isnull() {}
743
  virtual ~Create_func_isnull() {}
744
};
745
746
747
class Create_func_last_day : public Create_func_arg1
748
{
749
public:
750
  virtual Item *create(THD *thd, Item *arg1);
751
752
  static Create_func_last_day s_singleton;
753
754
protected:
755
  Create_func_last_day() {}
756
  virtual ~Create_func_last_day() {}
757
};
758
759
760
class Create_func_last_insert_id : public Create_native_func
761
{
762
public:
763
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
764
765
  static Create_func_last_insert_id s_singleton;
766
767
protected:
768
  Create_func_last_insert_id() {}
769
  virtual ~Create_func_last_insert_id() {}
770
};
771
772
773
class Create_func_lcase : public Create_func_arg1
774
{
775
public:
776
  virtual Item *create(THD *thd, Item *arg1);
777
778
  static Create_func_lcase s_singleton;
779
780
protected:
781
  Create_func_lcase() {}
782
  virtual ~Create_func_lcase() {}
783
};
784
785
786
class Create_func_least : public Create_native_func
787
{
788
public:
789
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
790
791
  static Create_func_least s_singleton;
792
793
protected:
794
  Create_func_least() {}
795
  virtual ~Create_func_least() {}
796
};
797
798
799
class Create_func_length : public Create_func_arg1
800
{
801
public:
802
  virtual Item *create(THD *thd, Item *arg1);
803
804
  static Create_func_length s_singleton;
805
806
protected:
807
  Create_func_length() {}
808
  virtual ~Create_func_length() {}
809
};
810
811
812
class Create_func_ln : public Create_func_arg1
813
{
814
public:
815
  virtual Item *create(THD *thd, Item *arg1);
816
817
  static Create_func_ln s_singleton;
818
819
protected:
820
  Create_func_ln() {}
821
  virtual ~Create_func_ln() {}
822
};
823
824
825
class Create_func_load_file : public Create_func_arg1
826
{
827
public:
828
  virtual Item *create(THD *thd, Item *arg1);
829
830
  static Create_func_load_file s_singleton;
831
832
protected:
833
  Create_func_load_file() {}
834
  virtual ~Create_func_load_file() {}
835
};
836
837
838
class Create_func_locate : public Create_native_func
839
{
840
public:
841
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
842
843
  static Create_func_locate s_singleton;
844
845
protected:
846
  Create_func_locate() {}
847
  virtual ~Create_func_locate() {}
848
};
849
850
851
class Create_func_log : public Create_native_func
852
{
853
public:
854
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
855
856
  static Create_func_log s_singleton;
857
858
protected:
859
  Create_func_log() {}
860
  virtual ~Create_func_log() {}
861
};
862
863
864
class Create_func_log10 : public Create_func_arg1
865
{
866
public:
867
  virtual Item *create(THD *thd, Item *arg1);
868
869
  static Create_func_log10 s_singleton;
870
871
protected:
872
  Create_func_log10() {}
873
  virtual ~Create_func_log10() {}
874
};
875
876
877
class Create_func_log2 : public Create_func_arg1
878
{
879
public:
880
  virtual Item *create(THD *thd, Item *arg1);
881
882
  static Create_func_log2 s_singleton;
883
884
protected:
885
  Create_func_log2() {}
886
  virtual ~Create_func_log2() {}
887
};
888
889
890
class Create_func_lpad : public Create_func_arg3
891
{
892
public:
893
  virtual Item *create(THD *thd, Item *arg1, Item *arg2, Item *arg3);
894
895
  static Create_func_lpad s_singleton;
896
897
protected:
898
  Create_func_lpad() {}
899
  virtual ~Create_func_lpad() {}
900
};
901
902
903
class Create_func_ltrim : public Create_func_arg1
904
{
905
public:
906
  virtual Item *create(THD *thd, Item *arg1);
907
908
  static Create_func_ltrim s_singleton;
909
910
protected:
911
  Create_func_ltrim() {}
912
  virtual ~Create_func_ltrim() {}
913
};
914
915
916
class Create_func_makedate : public Create_func_arg2
917
{
918
public:
919
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
920
921
  static Create_func_makedate s_singleton;
922
923
protected:
924
  Create_func_makedate() {}
925
  virtual ~Create_func_makedate() {}
926
};
927
928
929
class Create_func_maketime : public Create_func_arg3
930
{
931
public:
932
  virtual Item *create(THD *thd, Item *arg1, Item *arg2, Item *arg3);
933
934
  static Create_func_maketime s_singleton;
935
936
protected:
937
  Create_func_maketime() {}
938
  virtual ~Create_func_maketime() {}
939
};
940
941
942
class Create_func_make_set : public Create_native_func
943
{
944
public:
945
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
946
947
  static Create_func_make_set s_singleton;
948
949
protected:
950
  Create_func_make_set() {}
951
  virtual ~Create_func_make_set() {}
952
};
953
954
955
class Create_func_master_pos_wait : public Create_native_func
956
{
957
public:
958
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
959
960
  static Create_func_master_pos_wait s_singleton;
961
962
protected:
963
  Create_func_master_pos_wait() {}
964
  virtual ~Create_func_master_pos_wait() {}
965
};
966
967
968
class Create_func_md5 : public Create_func_arg1
969
{
970
public:
971
  virtual Item *create(THD *thd, Item *arg1);
972
973
  static Create_func_md5 s_singleton;
974
975
protected:
976
  Create_func_md5() {}
977
  virtual ~Create_func_md5() {}
978
};
979
980
981
class Create_func_monthname : public Create_func_arg1
982
{
983
public:
984
  virtual Item *create(THD *thd, Item *arg1);
985
986
  static Create_func_monthname s_singleton;
987
988
protected:
989
  Create_func_monthname() {}
990
  virtual ~Create_func_monthname() {}
991
};
992
993
994
class Create_func_name_const : public Create_func_arg2
995
{
996
public:
997
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
998
999
  static Create_func_name_const s_singleton;
1000
1001
protected:
1002
  Create_func_name_const() {}
1003
  virtual ~Create_func_name_const() {}
1004
};
1005
1006
1007
class Create_func_nullif : public Create_func_arg2
1008
{
1009
public:
1010
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
1011
1012
  static Create_func_nullif s_singleton;
1013
1014
protected:
1015
  Create_func_nullif() {}
1016
  virtual ~Create_func_nullif() {}
1017
};
1018
1019
1020
class Create_func_oct : public Create_func_arg1
1021
{
1022
public:
1023
  virtual Item *create(THD *thd, Item *arg1);
1024
1025
  static Create_func_oct s_singleton;
1026
1027
protected:
1028
  Create_func_oct() {}
1029
  virtual ~Create_func_oct() {}
1030
};
1031
1032
1033
class Create_func_ord : public Create_func_arg1
1034
{
1035
public:
1036
  virtual Item *create(THD *thd, Item *arg1);
1037
1038
  static Create_func_ord s_singleton;
1039
1040
protected:
1041
  Create_func_ord() {}
1042
  virtual ~Create_func_ord() {}
1043
};
1044
1045
1046
class Create_func_period_add : public Create_func_arg2
1047
{
1048
public:
1049
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
1050
1051
  static Create_func_period_add s_singleton;
1052
1053
protected:
1054
  Create_func_period_add() {}
1055
  virtual ~Create_func_period_add() {}
1056
};
1057
1058
1059
class Create_func_period_diff : public Create_func_arg2
1060
{
1061
public:
1062
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
1063
1064
  static Create_func_period_diff s_singleton;
1065
1066
protected:
1067
  Create_func_period_diff() {}
1068
  virtual ~Create_func_period_diff() {}
1069
};
1070
1071
1072
class Create_func_pi : public Create_func_arg0
1073
{
1074
public:
1075
  virtual Item *create(THD *thd);
1076
1077
  static Create_func_pi s_singleton;
1078
1079
protected:
1080
  Create_func_pi() {}
1081
  virtual ~Create_func_pi() {}
1082
};
1083
1084
1085
class Create_func_pow : public Create_func_arg2
1086
{
1087
public:
1088
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
1089
1090
  static Create_func_pow s_singleton;
1091
1092
protected:
1093
  Create_func_pow() {}
1094
  virtual ~Create_func_pow() {}
1095
};
1096
1097
1098
class Create_func_quote : public Create_func_arg1
1099
{
1100
public:
1101
  virtual Item *create(THD *thd, Item *arg1);
1102
1103
  static Create_func_quote s_singleton;
1104
1105
protected:
1106
  Create_func_quote() {}
1107
  virtual ~Create_func_quote() {}
1108
};
1109
1110
1111
class Create_func_radians : public Create_func_arg1
1112
{
1113
public:
1114
  virtual Item *create(THD *thd, Item *arg1);
1115
1116
  static Create_func_radians s_singleton;
1117
1118
protected:
1119
  Create_func_radians() {}
1120
  virtual ~Create_func_radians() {}
1121
};
1122
1123
1124
class Create_func_rand : public Create_native_func
1125
{
1126
public:
1127
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
1128
1129
  static Create_func_rand s_singleton;
1130
1131
protected:
1132
  Create_func_rand() {}
1133
  virtual ~Create_func_rand() {}
1134
};
1135
1136
1137
class Create_func_round : public Create_native_func
1138
{
1139
public:
1140
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
1141
1142
  static Create_func_round s_singleton;
1143
1144
protected:
1145
  Create_func_round() {}
1146
  virtual ~Create_func_round() {}
1147
};
1148
1149
1150
class Create_func_row_count : public Create_func_arg0
1151
{
1152
public:
1153
  virtual Item *create(THD *thd);
1154
1155
  static Create_func_row_count s_singleton;
1156
1157
protected:
1158
  Create_func_row_count() {}
1159
  virtual ~Create_func_row_count() {}
1160
};
1161
1162
1163
class Create_func_rpad : public Create_func_arg3
1164
{
1165
public:
1166
  virtual Item *create(THD *thd, Item *arg1, Item *arg2, Item *arg3);
1167
1168
  static Create_func_rpad s_singleton;
1169
1170
protected:
1171
  Create_func_rpad() {}
1172
  virtual ~Create_func_rpad() {}
1173
};
1174
1175
1176
class Create_func_rtrim : public Create_func_arg1
1177
{
1178
public:
1179
  virtual Item *create(THD *thd, Item *arg1);
1180
1181
  static Create_func_rtrim s_singleton;
1182
1183
protected:
1184
  Create_func_rtrim() {}
1185
  virtual ~Create_func_rtrim() {}
1186
};
1187
1188
1189
class Create_func_sec_to_time : public Create_func_arg1
1190
{
1191
public:
1192
  virtual Item *create(THD *thd, Item *arg1);
1193
1194
  static Create_func_sec_to_time s_singleton;
1195
1196
protected:
1197
  Create_func_sec_to_time() {}
1198
  virtual ~Create_func_sec_to_time() {}
1199
};
1200
1201
1202
class Create_func_sign : public Create_func_arg1
1203
{
1204
public:
1205
  virtual Item *create(THD *thd, Item *arg1);
1206
1207
  static Create_func_sign s_singleton;
1208
1209
protected:
1210
  Create_func_sign() {}
1211
  virtual ~Create_func_sign() {}
1212
};
1213
1214
1215
class Create_func_sin : public Create_func_arg1
1216
{
1217
public:
1218
  virtual Item *create(THD *thd, Item *arg1);
1219
1220
  static Create_func_sin s_singleton;
1221
1222
protected:
1223
  Create_func_sin() {}
1224
  virtual ~Create_func_sin() {}
1225
};
1226
1227
1228
class Create_func_space : public Create_func_arg1
1229
{
1230
public:
1231
  virtual Item *create(THD *thd, Item *arg1);
1232
1233
  static Create_func_space s_singleton;
1234
1235
protected:
1236
  Create_func_space() {}
1237
  virtual ~Create_func_space() {}
1238
};
1239
1240
1241
class Create_func_sqrt : public Create_func_arg1
1242
{
1243
public:
1244
  virtual Item *create(THD *thd, Item *arg1);
1245
1246
  static Create_func_sqrt s_singleton;
1247
1248
protected:
1249
  Create_func_sqrt() {}
1250
  virtual ~Create_func_sqrt() {}
1251
};
1252
1253
1254
class Create_func_str_to_date : public Create_func_arg2
1255
{
1256
public:
1257
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
1258
1259
  static Create_func_str_to_date s_singleton;
1260
1261
protected:
1262
  Create_func_str_to_date() {}
1263
  virtual ~Create_func_str_to_date() {}
1264
};
1265
1266
1267
class Create_func_strcmp : public Create_func_arg2
1268
{
1269
public:
1270
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
1271
1272
  static Create_func_strcmp s_singleton;
1273
1274
protected:
1275
  Create_func_strcmp() {}
1276
  virtual ~Create_func_strcmp() {}
1277
};
1278
1279
1280
class Create_func_substr_index : public Create_func_arg3
1281
{
1282
public:
1283
  virtual Item *create(THD *thd, Item *arg1, Item *arg2, Item *arg3);
1284
1285
  static Create_func_substr_index s_singleton;
1286
1287
protected:
1288
  Create_func_substr_index() {}
1289
  virtual ~Create_func_substr_index() {}
1290
};
1291
1292
1293
class Create_func_subtime : public Create_func_arg2
1294
{
1295
public:
1296
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
1297
1298
  static Create_func_subtime s_singleton;
1299
1300
protected:
1301
  Create_func_subtime() {}
1302
  virtual ~Create_func_subtime() {}
1303
};
1304
1305
1306
class Create_func_tan : public Create_func_arg1
1307
{
1308
public:
1309
  virtual Item *create(THD *thd, Item *arg1);
1310
1311
  static Create_func_tan s_singleton;
1312
1313
protected:
1314
  Create_func_tan() {}
1315
  virtual ~Create_func_tan() {}
1316
};
1317
1318
1319
class Create_func_time_format : public Create_func_arg2
1320
{
1321
public:
1322
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
1323
1324
  static Create_func_time_format s_singleton;
1325
1326
protected:
1327
  Create_func_time_format() {}
1328
  virtual ~Create_func_time_format() {}
1329
};
1330
1331
1332
class Create_func_time_to_sec : public Create_func_arg1
1333
{
1334
public:
1335
  virtual Item *create(THD *thd, Item *arg1);
1336
1337
  static Create_func_time_to_sec s_singleton;
1338
1339
protected:
1340
  Create_func_time_to_sec() {}
1341
  virtual ~Create_func_time_to_sec() {}
1342
};
1343
1344
1345
class Create_func_timediff : public Create_func_arg2
1346
{
1347
public:
1348
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
1349
1350
  static Create_func_timediff s_singleton;
1351
1352
protected:
1353
  Create_func_timediff() {}
1354
  virtual ~Create_func_timediff() {}
1355
};
1356
1357
1358
class Create_func_to_days : public Create_func_arg1
1359
{
1360
public:
1361
  virtual Item *create(THD *thd, Item *arg1);
1362
1363
  static Create_func_to_days s_singleton;
1364
1365
protected:
1366
  Create_func_to_days() {}
1367
  virtual ~Create_func_to_days() {}
1368
};
1369
1370
1371
class Create_func_ucase : public Create_func_arg1
1372
{
1373
public:
1374
  virtual Item *create(THD *thd, Item *arg1);
1375
1376
  static Create_func_ucase s_singleton;
1377
1378
protected:
1379
  Create_func_ucase() {}
1380
  virtual ~Create_func_ucase() {}
1381
};
1382
1383
1384
class Create_func_unhex : public Create_func_arg1
1385
{
1386
public:
1387
  virtual Item *create(THD *thd, Item *arg1);
1388
1389
  static Create_func_unhex s_singleton;
1390
1391
protected:
1392
  Create_func_unhex() {}
1393
  virtual ~Create_func_unhex() {}
1394
};
1395
1396
1397
class Create_func_unix_timestamp : public Create_native_func
1398
{
1399
public:
1400
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
1401
1402
  static Create_func_unix_timestamp s_singleton;
1403
1404
protected:
1405
  Create_func_unix_timestamp() {}
1406
  virtual ~Create_func_unix_timestamp() {}
1407
};
1408
1409
1410
class Create_func_uuid : public Create_func_arg0
1411
{
1412
public:
1413
  virtual Item *create(THD *thd);
1414
1415
  static Create_func_uuid s_singleton;
1416
1417
protected:
1418
  Create_func_uuid() {}
1419
  virtual ~Create_func_uuid() {}
1420
};
1421
1422
1423
class Create_func_uuid_short : public Create_func_arg0
1424
{
1425
public:
1426
  virtual Item *create(THD *thd);
1427
1428
  static Create_func_uuid_short s_singleton;
1429
1430
protected:
1431
  Create_func_uuid_short() {}
1432
  virtual ~Create_func_uuid_short() {}
1433
};
1434
1435
1436
class Create_func_version : public Create_func_arg0
1437
{
1438
public:
1439
  virtual Item *create(THD *thd);
1440
1441
  static Create_func_version s_singleton;
1442
1443
protected:
1444
  Create_func_version() {}
1445
  virtual ~Create_func_version() {}
1446
};
1447
1448
1449
class Create_func_weekday : public Create_func_arg1
1450
{
1451
public:
1452
  virtual Item *create(THD *thd, Item *arg1);
1453
1454
  static Create_func_weekday s_singleton;
1455
1456
protected:
1457
  Create_func_weekday() {}
1458
  virtual ~Create_func_weekday() {}
1459
};
1460
1461
1462
class Create_func_weekofyear : public Create_func_arg1
1463
{
1464
public:
1465
  virtual Item *create(THD *thd, Item *arg1);
1466
1467
  static Create_func_weekofyear s_singleton;
1468
1469
protected:
1470
  Create_func_weekofyear() {}
1471
  virtual ~Create_func_weekofyear() {}
1472
};
1473
1474
1475
class Create_func_year_week : public Create_native_func
1476
{
1477
public:
1478
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
1479
1480
  static Create_func_year_week s_singleton;
1481
1482
protected:
1483
  Create_func_year_week() {}
1484
  virtual ~Create_func_year_week() {}
1485
};
1486
1487
1488
/*
1489
=============================================================================
1490
  IMPLEMENTATION
1491
=============================================================================
1492
*/
1493
1494
/**
1495
  Checks if there are named parameters in a parameter list.
1496
  The syntax to name parameters in a function call is as follow:
1497
  <code>foo(expr AS named, expr named, expr AS "named", expr "named")</code>
1498
  @param params The parameter list, can be null
1499
  @return true if one or more parameter is named
1500
*/
1501
static bool has_named_parameters(List<Item> *params)
1502
{
1503
  if (params)
1504
  {
1505
    Item *param;
1506
    List_iterator<Item> it(*params);
1507
    while ((param= it++))
1508
    {
1509
      if (! param->is_autogenerated_name)
1510
        return true;
1511
    }
1512
  }
1513
1514
  return false;
1515
}
1516
1517
1518
#ifdef HAVE_DLOPEN
1519
Create_udf_func Create_udf_func::s_singleton;
1520
1521
Item*
1522
Create_udf_func::create(THD *thd, LEX_STRING name, List<Item> *item_list)
1523
{
1524
  udf_func *udf= find_udf(name.str, name.length);
1525
  DBUG_ASSERT(udf);
1526
  return create(thd, udf, item_list);
1527
}
1528
1529
1530
Item*
1531
Create_udf_func::create(THD *thd, udf_func *udf, List<Item> *item_list)
1532
{
1533
  Item *func= NULL;
1534
  int arg_count= 0;
1535
1536
  if (item_list != NULL)
1537
    arg_count= item_list->elements;
1538
1539
  thd->lex->set_stmt_unsafe();
1540
1541
  DBUG_ASSERT(   (udf->type == UDFTYPE_FUNCTION)
1542
              || (udf->type == UDFTYPE_AGGREGATE));
1543
1544
  switch(udf->returns) {
1545
  case STRING_RESULT:
1546
  {
1547
    if (udf->type == UDFTYPE_FUNCTION)
1548
    {
1549
      if (arg_count)
1550
        func= new (thd->mem_root) Item_func_udf_str(udf, *item_list);
1551
      else
1552
        func= new (thd->mem_root) Item_func_udf_str(udf);
1553
    }
1554
    else
1555
    {
1556
      if (arg_count)
1557
        func= new (thd->mem_root) Item_sum_udf_str(udf, *item_list);
1558
      else
1559
        func= new (thd->mem_root) Item_sum_udf_str(udf);
1560
    }
1561
    break;
1562
  }
1563
  case REAL_RESULT:
1564
  {
1565
    if (udf->type == UDFTYPE_FUNCTION)
1566
    {
1567
      if (arg_count)
1568
        func= new (thd->mem_root) Item_func_udf_float(udf, *item_list);
1569
      else
1570
        func= new (thd->mem_root) Item_func_udf_float(udf);
1571
    }
1572
    else
1573
    {
1574
      if (arg_count)
1575
        func= new (thd->mem_root) Item_sum_udf_float(udf, *item_list);
1576
      else
1577
        func= new (thd->mem_root) Item_sum_udf_float(udf);
1578
    }
1579
    break;
1580
  }
1581
  case INT_RESULT:
1582
  {
1583
    if (udf->type == UDFTYPE_FUNCTION)
1584
    {
1585
      if (arg_count)
1586
        func= new (thd->mem_root) Item_func_udf_int(udf, *item_list);
1587
      else
1588
        func= new (thd->mem_root) Item_func_udf_int(udf);
1589
    }
1590
    else
1591
    {
1592
      if (arg_count)
1593
        func= new (thd->mem_root) Item_sum_udf_int(udf, *item_list);
1594
      else
1595
        func= new (thd->mem_root) Item_sum_udf_int(udf);
1596
    }
1597
    break;
1598
  }
1599
  case DECIMAL_RESULT:
1600
  {
1601
    if (udf->type == UDFTYPE_FUNCTION)
1602
    {
1603
      if (arg_count)
1604
        func= new (thd->mem_root) Item_func_udf_decimal(udf, *item_list);
1605
      else
1606
        func= new (thd->mem_root) Item_func_udf_decimal(udf);
1607
    }
1608
    else
1609
    {
1610
      if (arg_count)
1611
        func= new (thd->mem_root) Item_sum_udf_decimal(udf, *item_list);
1612
      else
1613
        func= new (thd->mem_root) Item_sum_udf_decimal(udf);
1614
    }
1615
    break;
1616
  }
1617
  default:
1618
  {
1619
    my_error(ER_NOT_SUPPORTED_YET, MYF(0), "UDF return type");
1620
  }
1621
  }
1622
  return func;
1623
}
1624
#endif
1625
1626
1627
Item*
1628
Create_native_func::create(THD *thd, LEX_STRING name, List<Item> *item_list)
1629
{
1630
  if (has_named_parameters(item_list))
1631
  {
1632
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1633
    return NULL;
1634
  }
1635
1636
  return create_native(thd, name, item_list);
1637
}
1638
1639
1640
Item*
1641
Create_func_arg0::create(THD *thd, LEX_STRING name, List<Item> *item_list)
1642
{
1643
  int arg_count= 0;
1644
1645
  if (item_list != NULL)
1646
    arg_count= item_list->elements;
1647
1648
  if (arg_count != 0)
1649
  {
1650
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1651
    return NULL;
1652
  }
1653
1654
  return create(thd);
1655
}
1656
1657
1658
Item*
1659
Create_func_arg1::create(THD *thd, LEX_STRING name, List<Item> *item_list)
1660
{
1661
  int arg_count= 0;
1662
1663
  if (item_list)
1664
    arg_count= item_list->elements;
1665
1666
  if (arg_count != 1)
1667
  {
1668
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1669
    return NULL;
1670
  }
1671
1672
  Item *param_1= item_list->pop();
1673
1674
  if (! param_1->is_autogenerated_name)
1675
  {
1676
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1677
    return NULL;
1678
  }
1679
1680
  return create(thd, param_1);
1681
}
1682
1683
1684
Item*
1685
Create_func_arg2::create(THD *thd, LEX_STRING name, List<Item> *item_list)
1686
{
1687
  int arg_count= 0;
1688
1689
  if (item_list)
1690
    arg_count= item_list->elements;
1691
1692
  if (arg_count != 2)
1693
  {
1694
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1695
    return NULL;
1696
  }
1697
1698
  Item *param_1= item_list->pop();
1699
  Item *param_2= item_list->pop();
1700
1701
  if (   (! param_1->is_autogenerated_name)
1702
      || (! param_2->is_autogenerated_name))
1703
  {
1704
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1705
    return NULL;
1706
  }
1707
1708
  return create(thd, param_1, param_2);
1709
}
1710
1711
1712
Item*
1713
Create_func_arg3::create(THD *thd, LEX_STRING name, List<Item> *item_list)
1714
{
1715
  int arg_count= 0;
1716
1717
  if (item_list)
1718
    arg_count= item_list->elements;
1719
1720
  if (arg_count != 3)
1721
  {
1722
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1723
    return NULL;
1724
  }
1725
1726
  Item *param_1= item_list->pop();
1727
  Item *param_2= item_list->pop();
1728
  Item *param_3= item_list->pop();
1729
1730
  if (   (! param_1->is_autogenerated_name)
1731
      || (! param_2->is_autogenerated_name)
1732
      || (! param_3->is_autogenerated_name))
1733
  {
1734
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1735
    return NULL;
1736
  }
1737
1738
  return create(thd, param_1, param_2, param_3);
1739
}
1740
1741
1742
Create_func_abs Create_func_abs::s_singleton;
1743
1744
Item*
1745
Create_func_abs::create(THD *thd, Item *arg1)
1746
{
1747
  return new (thd->mem_root) Item_func_abs(arg1);
1748
}
1749
1750
1751
Create_func_acos Create_func_acos::s_singleton;
1752
1753
Item*
1754
Create_func_acos::create(THD *thd, Item *arg1)
1755
{
1756
  return new (thd->mem_root) Item_func_acos(arg1);
1757
}
1758
1759
1760
Create_func_addtime Create_func_addtime::s_singleton;
1761
1762
Item*
1763
Create_func_addtime::create(THD *thd, Item *arg1, Item *arg2)
1764
{
1765
  return new (thd->mem_root) Item_func_add_time(arg1, arg2, 0, 0);
1766
}
1767
1768
1769
Create_func_asin Create_func_asin::s_singleton;
1770
1771
Item*
1772
Create_func_asin::create(THD *thd, Item *arg1)
1773
{
1774
  return new (thd->mem_root) Item_func_asin(arg1);
1775
}
1776
1777
1778
Create_func_atan Create_func_atan::s_singleton;
1779
1780
Item*
1781
Create_func_atan::create_native(THD *thd, LEX_STRING name,
1782
                                List<Item> *item_list)
1783
{
1784
  Item* func= NULL;
1785
  int arg_count= 0;
1786
1787
  if (item_list != NULL)
1788
    arg_count= item_list->elements;
1789
1790
  switch (arg_count) {
1791
  case 1:
1792
  {
1793
    Item *param_1= item_list->pop();
1794
    func= new (thd->mem_root) Item_func_atan(param_1);
1795
    break;
1796
  }
1797
  case 2:
1798
  {
1799
    Item *param_1= item_list->pop();
1800
    Item *param_2= item_list->pop();
1801
    func= new (thd->mem_root) Item_func_atan(param_1, param_2);
1802
    break;
1803
  }
1804
  default:
1805
  {
1806
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1807
    break;
1808
  }
1809
  }
1810
1811
  return func;
1812
}
1813
1814
1815
Create_func_benchmark Create_func_benchmark::s_singleton;
1816
1817
Item*
1818
Create_func_benchmark::create(THD *thd, Item *arg1, Item *arg2)
1819
{
1820
  return new (thd->mem_root) Item_func_benchmark(arg1, arg2);
1821
}
1822
1823
1824
Create_func_bin Create_func_bin::s_singleton;
1825
1826
Item*
1827
Create_func_bin::create(THD *thd, Item *arg1)
1828
{
1829
  Item *i10= new (thd->mem_root) Item_int((int32) 10,2);
1830
  Item *i2= new (thd->mem_root) Item_int((int32) 2,1);
1831
  return new (thd->mem_root) Item_func_conv(arg1, i10, i2);
1832
}
1833
1834
1835
Create_func_bit_count Create_func_bit_count::s_singleton;
1836
1837
Item*
1838
Create_func_bit_count::create(THD *thd, Item *arg1)
1839
{
1840
  return new (thd->mem_root) Item_func_bit_count(arg1);
1841
}
1842
1843
1844
Create_func_bit_length Create_func_bit_length::s_singleton;
1845
1846
Item*
1847
Create_func_bit_length::create(THD *thd, Item *arg1)
1848
{
1849
  return new (thd->mem_root) Item_func_bit_length(arg1);
1850
}
1851
1852
1853
Create_func_ceiling Create_func_ceiling::s_singleton;
1854
1855
Item*
1856
Create_func_ceiling::create(THD *thd, Item *arg1)
1857
{
1858
  return new (thd->mem_root) Item_func_ceiling(arg1);
1859
}
1860
1861
1862
Create_func_char_length Create_func_char_length::s_singleton;
1863
1864
Item*
1865
Create_func_char_length::create(THD *thd, Item *arg1)
1866
{
1867
  return new (thd->mem_root) Item_func_char_length(arg1);
1868
}
1869
1870
1871
Create_func_coercibility Create_func_coercibility::s_singleton;
1872
1873
Item*
1874
Create_func_coercibility::create(THD *thd, Item *arg1)
1875
{
1876
  return new (thd->mem_root) Item_func_coercibility(arg1);
1877
}
1878
1879
1880
Create_func_concat Create_func_concat::s_singleton;
1881
1882
Item*
1883
Create_func_concat::create_native(THD *thd, LEX_STRING name,
1884
                                  List<Item> *item_list)
1885
{
1886
  int arg_count= 0;
1887
1888
  if (item_list != NULL)
1889
    arg_count= item_list->elements;
1890
1891
  if (arg_count < 1)
1892
  {
1893
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1894
    return NULL;
1895
  }
1896
1897
  return new (thd->mem_root) Item_func_concat(*item_list);
1898
}
1899
1900
1901
Create_func_concat_ws Create_func_concat_ws::s_singleton;
1902
1903
Item*
1904
Create_func_concat_ws::create_native(THD *thd, LEX_STRING name,
1905
                                     List<Item> *item_list)
1906
{
1907
  int arg_count= 0;
1908
1909
  if (item_list != NULL)
1910
    arg_count= item_list->elements;
1911
1912
  /* "WS" stands for "With Separator": this function takes 2+ arguments */
1913
  if (arg_count < 2)
1914
  {
1915
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1916
    return NULL;
1917
  }
1918
1919
  return new (thd->mem_root) Item_func_concat_ws(*item_list);
1920
}
1921
1922
1923
Create_func_connection_id Create_func_connection_id::s_singleton;
1924
1925
Item*
1926
Create_func_connection_id::create(THD *thd)
1927
{
1928
  return new (thd->mem_root) Item_func_connection_id();
1929
}
1930
1931
1932
Create_func_conv Create_func_conv::s_singleton;
1933
1934
Item*
1935
Create_func_conv::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
1936
{
1937
  return new (thd->mem_root) Item_func_conv(arg1, arg2, arg3);
1938
}
1939
1940
1941
Create_func_cos Create_func_cos::s_singleton;
1942
1943
Item*
1944
Create_func_cos::create(THD *thd, Item *arg1)
1945
{
1946
  return new (thd->mem_root) Item_func_cos(arg1);
1947
}
1948
1949
1950
Create_func_cot Create_func_cot::s_singleton;
1951
1952
Item*
1953
Create_func_cot::create(THD *thd, Item *arg1)
1954
{
1955
  Item *i1= new (thd->mem_root) Item_int((char*) "1", 1, 1);
1956
  Item *i2= new (thd->mem_root) Item_func_tan(arg1);
1957
  return new (thd->mem_root) Item_func_div(i1, i2);
1958
}
1959
1960
1961
Create_func_crc32 Create_func_crc32::s_singleton;
1962
1963
Item*
1964
Create_func_crc32::create(THD *thd, Item *arg1)
1965
{
1966
  return new (thd->mem_root) Item_func_crc32(arg1);
1967
}
1968
1969
1970
Create_func_date_format Create_func_date_format::s_singleton;
1971
1972
Item*
1973
Create_func_date_format::create(THD *thd, Item *arg1, Item *arg2)
1974
{
1975
  return new (thd->mem_root) Item_func_date_format(arg1, arg2, 0);
1976
}
1977
1978
1979
Create_func_datediff Create_func_datediff::s_singleton;
1980
1981
Item*
1982
Create_func_datediff::create(THD *thd, Item *arg1, Item *arg2)
1983
{
1984
  Item *i1= new (thd->mem_root) Item_func_to_days(arg1);
1985
  Item *i2= new (thd->mem_root) Item_func_to_days(arg2);
1986
1987
  return new (thd->mem_root) Item_func_minus(i1, i2);
1988
}
1989
1990
1991
Create_func_dayname Create_func_dayname::s_singleton;
1992
1993
Item*
1994
Create_func_dayname::create(THD *thd, Item *arg1)
1995
{
1996
  return new (thd->mem_root) Item_func_dayname(arg1);
1997
}
1998
1999
2000
Create_func_dayofmonth Create_func_dayofmonth::s_singleton;
2001
2002
Item*
2003
Create_func_dayofmonth::create(THD *thd, Item *arg1)
2004
{
2005
  return new (thd->mem_root) Item_func_dayofmonth(arg1);
2006
}
2007
2008
2009
Create_func_dayofweek Create_func_dayofweek::s_singleton;
2010
2011
Item*
2012
Create_func_dayofweek::create(THD *thd, Item *arg1)
2013
{
2014
  return new (thd->mem_root) Item_func_weekday(arg1, 1);
2015
}
2016
2017
2018
Create_func_dayofyear Create_func_dayofyear::s_singleton;
2019
2020
Item*
2021
Create_func_dayofyear::create(THD *thd, Item *arg1)
2022
{
2023
  return new (thd->mem_root) Item_func_dayofyear(arg1);
2024
}
2025
2026
2027
Create_func_decode Create_func_decode::s_singleton;
2028
2029
Item*
2030
Create_func_decode::create(THD *thd, Item *arg1, Item *arg2)
2031
{
2032
  return new (thd->mem_root) Item_func_decode(arg1, arg2);
2033
}
2034
2035
2036
Create_func_degrees Create_func_degrees::s_singleton;
2037
2038
Item*
2039
Create_func_degrees::create(THD *thd, Item *arg1)
2040
{
2041
  return new (thd->mem_root) Item_func_units((char*) "degrees", arg1,
2042
                                             180/M_PI, 0.0);
2043
}
2044
2045
2046
Create_func_elt Create_func_elt::s_singleton;
2047
2048
Item*
2049
Create_func_elt::create_native(THD *thd, LEX_STRING name,
2050
                               List<Item> *item_list)
2051
{
2052
  int arg_count= 0;
2053
2054
  if (item_list != NULL)
2055
    arg_count= item_list->elements;
2056
2057
  if (arg_count < 2)
2058
  {
2059
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2060
    return NULL;
2061
  }
2062
2063
  return new (thd->mem_root) Item_func_elt(*item_list);
2064
}
2065
2066
2067
Create_func_encode Create_func_encode::s_singleton;
2068
2069
Item*
2070
Create_func_encode::create(THD *thd, Item *arg1, Item *arg2)
2071
{
2072
  return new (thd->mem_root) Item_func_encode(arg1, arg2);
2073
}
2074
2075
2076
Create_func_encrypt Create_func_encrypt::s_singleton;
2077
2078
Item*
2079
Create_func_encrypt::create_native(THD *thd, LEX_STRING name,
2080
                                   List<Item> *item_list)
2081
{
2082
  Item *func= NULL;
2083
  int arg_count= 0;
2084
2085
  if (item_list != NULL)
2086
    arg_count= item_list->elements;
2087
2088
  switch (arg_count) {
2089
  case 1:
2090
  {
2091
    Item *param_1= item_list->pop();
2092
    func= new (thd->mem_root) Item_func_encrypt(param_1);
2093
    break;
2094
  }
2095
  case 2:
2096
  {
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);
2100
    break;
2101
  }
2102
  default:
2103
  {
2104
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2105
    break;
2106
  }
2107
  }
2108
2109
  return func;
2110
}
2111
2112
2113
Create_func_exp Create_func_exp::s_singleton;
2114
2115
Item*
2116
Create_func_exp::create(THD *thd, Item *arg1)
2117
{
2118
  return new (thd->mem_root) Item_func_exp(arg1);
2119
}
2120
2121
2122
Create_func_export_set Create_func_export_set::s_singleton;
2123
2124
Item*
2125
Create_func_export_set::create_native(THD *thd, LEX_STRING name,
2126
                                      List<Item> *item_list)
2127
{
2128
  Item *func= NULL;
2129
  int arg_count= 0;
2130
2131
  if (item_list != NULL)
2132
    arg_count= item_list->elements;
2133
2134
  switch (arg_count) {
2135
  case 3:
2136
  {
2137
    Item *param_1= item_list->pop();
2138
    Item *param_2= item_list->pop();
2139
    Item *param_3= item_list->pop();
2140
    func= new (thd->mem_root) Item_func_export_set(param_1, param_2, param_3);
2141
    break;
2142
  }
2143
  case 4:
2144
  {
2145
    Item *param_1= item_list->pop();
2146
    Item *param_2= item_list->pop();
2147
    Item *param_3= item_list->pop();
2148
    Item *param_4= item_list->pop();
2149
    func= new (thd->mem_root) Item_func_export_set(param_1, param_2, param_3,
2150
                                                   param_4);
2151
    break;
2152
  }
2153
  case 5:
2154
  {
2155
    Item *param_1= item_list->pop();
2156
    Item *param_2= item_list->pop();
2157
    Item *param_3= item_list->pop();
2158
    Item *param_4= item_list->pop();
2159
    Item *param_5= item_list->pop();
2160
    func= new (thd->mem_root) Item_func_export_set(param_1, param_2, param_3,
2161
                                                   param_4, param_5);
2162
    break;
2163
  }
2164
  default:
2165
  {
2166
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2167
    break;
2168
  }
2169
  }
2170
2171
  return func;
2172
}
2173
2174
2175
Create_func_field Create_func_field::s_singleton;
2176
2177
Item*
2178
Create_func_field::create_native(THD *thd, LEX_STRING name,
2179
                                 List<Item> *item_list)
2180
{
2181
  int arg_count= 0;
2182
2183
  if (item_list != NULL)
2184
    arg_count= item_list->elements;
2185
2186
  if (arg_count < 2)
2187
  {
2188
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2189
    return NULL;
2190
  }
2191
2192
  return new (thd->mem_root) Item_func_field(*item_list);
2193
}
2194
2195
2196
Create_func_find_in_set Create_func_find_in_set::s_singleton;
2197
2198
Item*
2199
Create_func_find_in_set::create(THD *thd, Item *arg1, Item *arg2)
2200
{
2201
  return new (thd->mem_root) Item_func_find_in_set(arg1, arg2);
2202
}
2203
2204
2205
Create_func_floor Create_func_floor::s_singleton;
2206
2207
Item*
2208
Create_func_floor::create(THD *thd, Item *arg1)
2209
{
2210
  return new (thd->mem_root) Item_func_floor(arg1);
2211
}
2212
2213
2214
Create_func_format Create_func_format::s_singleton;
2215
2216
Item*
2217
Create_func_format::create(THD *thd, Item *arg1, Item *arg2)
2218
{
2219
  return new (thd->mem_root) Item_func_format(arg1, arg2);
2220
}
2221
2222
2223
Create_func_found_rows Create_func_found_rows::s_singleton;
2224
2225
Item*
2226
Create_func_found_rows::create(THD *thd)
2227
{
2228
  thd->lex->set_stmt_unsafe();
2229
  return new (thd->mem_root) Item_func_found_rows();
2230
}
2231
2232
2233
Create_func_from_days Create_func_from_days::s_singleton;
2234
2235
Item*
2236
Create_func_from_days::create(THD *thd, Item *arg1)
2237
{
2238
  return new (thd->mem_root) Item_func_from_days(arg1);
2239
}
2240
2241
2242
Create_func_from_unixtime Create_func_from_unixtime::s_singleton;
2243
2244
Item*
2245
Create_func_from_unixtime::create_native(THD *thd, LEX_STRING name,
2246
                                         List<Item> *item_list)
2247
{
2248
  Item *func= NULL;
2249
  int arg_count= 0;
2250
2251
  if (item_list != NULL)
2252
    arg_count= item_list->elements;
2253
2254
  switch (arg_count) {
2255
  case 1:
2256
  {
2257
    Item *param_1= item_list->pop();
2258
    func= new (thd->mem_root) Item_func_from_unixtime(param_1);
2259
    break;
2260
  }
2261
  case 2:
2262
  {
2263
    Item *param_1= item_list->pop();
2264
    Item *param_2= item_list->pop();
2265
    Item *ut= new (thd->mem_root) Item_func_from_unixtime(param_1);
2266
    func= new (thd->mem_root) Item_func_date_format(ut, param_2, 0);
2267
    break;
2268
  }
2269
  default:
2270
  {
2271
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2272
    break;
2273
  }
2274
  }
2275
2276
  return func;
2277
}
2278
2279
2280
Create_func_greatest Create_func_greatest::s_singleton;
2281
2282
Item*
2283
Create_func_greatest::create_native(THD *thd, LEX_STRING name,
2284
                                    List<Item> *item_list)
2285
{
2286
  int arg_count= 0;
2287
2288
  if (item_list != NULL)
2289
    arg_count= item_list->elements;
2290
2291
  if (arg_count < 2)
2292
  {
2293
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2294
    return NULL;
2295
  }
2296
2297
  return new (thd->mem_root) Item_func_max(*item_list);
2298
}
2299
2300
2301
Create_func_hex Create_func_hex::s_singleton;
2302
2303
Item*
2304
Create_func_hex::create(THD *thd, Item *arg1)
2305
{
2306
  return new (thd->mem_root) Item_func_hex(arg1);
2307
}
2308
2309
2310
Create_func_ifnull Create_func_ifnull::s_singleton;
2311
2312
Item*
2313
Create_func_ifnull::create(THD *thd, Item *arg1, Item *arg2)
2314
{
2315
  return new (thd->mem_root) Item_func_ifnull(arg1, arg2);
2316
}
2317
2318
2319
Create_func_instr Create_func_instr::s_singleton;
2320
2321
Item*
2322
Create_func_instr::create(THD *thd, Item *arg1, Item *arg2)
2323
{
2324
  return new (thd->mem_root) Item_func_locate(arg1, arg2);
2325
}
2326
2327
2328
Create_func_isnull Create_func_isnull::s_singleton;
2329
2330
Item*
2331
Create_func_isnull::create(THD *thd, Item *arg1)
2332
{
2333
  return new (thd->mem_root) Item_func_isnull(arg1);
2334
}
2335
2336
2337
Create_func_last_day Create_func_last_day::s_singleton;
2338
2339
Item*
2340
Create_func_last_day::create(THD *thd, Item *arg1)
2341
{
2342
  return new (thd->mem_root) Item_func_last_day(arg1);
2343
}
2344
2345
2346
Create_func_last_insert_id Create_func_last_insert_id::s_singleton;
2347
2348
Item*
2349
Create_func_last_insert_id::create_native(THD *thd, LEX_STRING name,
2350
                                          List<Item> *item_list)
2351
{
2352
  Item *func= NULL;
2353
  int arg_count= 0;
2354
2355
  if (item_list != NULL)
2356
    arg_count= item_list->elements;
2357
2358
  switch (arg_count) {
2359
  case 0:
2360
  {
2361
    func= new (thd->mem_root) Item_func_last_insert_id();
2362
    break;
2363
  }
2364
  case 1:
2365
  {
2366
    Item *param_1= item_list->pop();
2367
    func= new (thd->mem_root) Item_func_last_insert_id(param_1);
2368
    break;
2369
  }
2370
  default:
2371
  {
2372
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2373
    break;
2374
  }
2375
  }
2376
2377
  return func;
2378
}
2379
2380
2381
Create_func_lcase Create_func_lcase::s_singleton;
2382
2383
Item*
2384
Create_func_lcase::create(THD *thd, Item *arg1)
2385
{
2386
  return new (thd->mem_root) Item_func_lcase(arg1);
2387
}
2388
2389
2390
Create_func_least Create_func_least::s_singleton;
2391
2392
Item*
2393
Create_func_least::create_native(THD *thd, LEX_STRING name,
2394
                                 List<Item> *item_list)
2395
{
2396
  int arg_count= 0;
2397
2398
  if (item_list != NULL)
2399
    arg_count= item_list->elements;
2400
2401
  if (arg_count < 2)
2402
  {
2403
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2404
    return NULL;
2405
  }
2406
2407
  return new (thd->mem_root) Item_func_min(*item_list);
2408
}
2409
2410
2411
Create_func_length Create_func_length::s_singleton;
2412
2413
Item*
2414
Create_func_length::create(THD *thd, Item *arg1)
2415
{
2416
  return new (thd->mem_root) Item_func_length(arg1);
2417
}
2418
2419
2420
Create_func_ln Create_func_ln::s_singleton;
2421
2422
Item*
2423
Create_func_ln::create(THD *thd, Item *arg1)
2424
{
2425
  return new (thd->mem_root) Item_func_ln(arg1);
2426
}
2427
2428
2429
Create_func_load_file Create_func_load_file::s_singleton;
2430
2431
Item*
2432
Create_func_load_file::create(THD *thd, Item *arg1)
2433
{
2434
  return new (thd->mem_root) Item_load_file(arg1);
2435
}
2436
2437
2438
Create_func_locate Create_func_locate::s_singleton;
2439
2440
Item*
2441
Create_func_locate::create_native(THD *thd, LEX_STRING name,
2442
                                  List<Item> *item_list)
2443
{
2444
  Item *func= NULL;
2445
  int arg_count= 0;
2446
2447
  if (item_list != NULL)
2448
    arg_count= item_list->elements;
2449
2450
  switch (arg_count) {
2451
  case 2:
2452
  {
2453
    Item *param_1= item_list->pop();
2454
    Item *param_2= item_list->pop();
2455
    /* Yes, parameters in that order : 2, 1 */
2456
    func= new (thd->mem_root) Item_func_locate(param_2, param_1);
2457
    break;
2458
  }
2459
  case 3:
2460
  {
2461
    Item *param_1= item_list->pop();
2462
    Item *param_2= item_list->pop();
2463
    Item *param_3= item_list->pop();
2464
    /* Yes, parameters in that order : 2, 1, 3 */
2465
    func= new (thd->mem_root) Item_func_locate(param_2, param_1, param_3);
2466
    break;
2467
  }
2468
  default:
2469
  {
2470
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2471
    break;
2472
  }
2473
  }
2474
2475
  return func;
2476
}
2477
2478
2479
Create_func_log Create_func_log::s_singleton;
2480
2481
Item*
2482
Create_func_log::create_native(THD *thd, LEX_STRING name,
2483
                               List<Item> *item_list)
2484
{
2485
  Item *func= NULL;
2486
  int arg_count= 0;
2487
2488
  if (item_list != NULL)
2489
    arg_count= item_list->elements;
2490
2491
  switch (arg_count) {
2492
  case 1:
2493
  {
2494
    Item *param_1= item_list->pop();
2495
    func= new (thd->mem_root) Item_func_log(param_1);
2496
    break;
2497
  }
2498
  case 2:
2499
  {
2500
    Item *param_1= item_list->pop();
2501
    Item *param_2= item_list->pop();
2502
    func= new (thd->mem_root) Item_func_log(param_1, param_2);
2503
    break;
2504
  }
2505
  default:
2506
  {
2507
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2508
    break;
2509
  }
2510
  }
2511
2512
  return func;
2513
}
2514
2515
2516
Create_func_log10 Create_func_log10::s_singleton;
2517
2518
Item*
2519
Create_func_log10::create(THD *thd, Item *arg1)
2520
{
2521
  return new (thd->mem_root) Item_func_log10(arg1);
2522
}
2523
2524
2525
Create_func_log2 Create_func_log2::s_singleton;
2526
2527
Item*
2528
Create_func_log2::create(THD *thd, Item *arg1)
2529
{
2530
  return new (thd->mem_root) Item_func_log2(arg1);
2531
}
2532
2533
2534
Create_func_lpad Create_func_lpad::s_singleton;
2535
2536
Item*
2537
Create_func_lpad::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
2538
{
2539
  return new (thd->mem_root) Item_func_lpad(arg1, arg2, arg3);
2540
}
2541
2542
2543
Create_func_ltrim Create_func_ltrim::s_singleton;
2544
2545
Item*
2546
Create_func_ltrim::create(THD *thd, Item *arg1)
2547
{
2548
  return new (thd->mem_root) Item_func_ltrim(arg1);
2549
}
2550
2551
2552
Create_func_makedate Create_func_makedate::s_singleton;
2553
2554
Item*
2555
Create_func_makedate::create(THD *thd, Item *arg1, Item *arg2)
2556
{
2557
  return new (thd->mem_root) Item_func_makedate(arg1, arg2);
2558
}
2559
2560
2561
Create_func_maketime Create_func_maketime::s_singleton;
2562
2563
Item*
2564
Create_func_maketime::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
2565
{
2566
  return new (thd->mem_root) Item_func_maketime(arg1, arg2, arg3);
2567
}
2568
2569
2570
Create_func_make_set Create_func_make_set::s_singleton;
2571
2572
Item*
2573
Create_func_make_set::create_native(THD *thd, LEX_STRING name,
2574
                                    List<Item> *item_list)
2575
{
2576
  int arg_count= 0;
2577
2578
  if (item_list != NULL)
2579
    arg_count= item_list->elements;
2580
2581
  if (arg_count < 2)
2582
  {
2583
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2584
    return NULL;
2585
  }
2586
2587
  Item *param_1= item_list->pop();
2588
  return new (thd->mem_root) Item_func_make_set(param_1, *item_list);
2589
}
2590
2591
2592
Create_func_master_pos_wait Create_func_master_pos_wait::s_singleton;
2593
2594
Item*
2595
Create_func_master_pos_wait::create_native(THD *thd, LEX_STRING name,
2596
                                           List<Item> *item_list)
2597
2598
{
2599
  Item *func= NULL;
2600
  int arg_count= 0;
2601
2602
  if (item_list != NULL)
2603
    arg_count= item_list->elements;
2604
2605
  switch (arg_count) {
2606
  case 2:
2607
  {
2608
    Item *param_1= item_list->pop();
2609
    Item *param_2= item_list->pop();
2610
    func= new (thd->mem_root) Item_master_pos_wait(param_1, param_2);
2611
    break;
2612
  }
2613
  case 3:
2614
  {
2615
    Item *param_1= item_list->pop();
2616
    Item *param_2= item_list->pop();
2617
    Item *param_3= item_list->pop();
2618
    func= new (thd->mem_root) Item_master_pos_wait(param_1, param_2, param_3);
2619
    break;
2620
  }
2621
  default:
2622
  {
2623
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2624
    break;
2625
  }
2626
  }
2627
2628
  return func;
2629
}
2630
2631
2632
Create_func_md5 Create_func_md5::s_singleton;
2633
2634
Item*
2635
Create_func_md5::create(THD *thd, Item *arg1)
2636
{
2637
  return new (thd->mem_root) Item_func_md5(arg1);
2638
}
2639
2640
2641
Create_func_monthname Create_func_monthname::s_singleton;
2642
2643
Item*
2644
Create_func_monthname::create(THD *thd, Item *arg1)
2645
{
2646
  return new (thd->mem_root) Item_func_monthname(arg1);
2647
}
2648
2649
2650
Create_func_nullif Create_func_nullif::s_singleton;
2651
2652
Item*
2653
Create_func_nullif::create(THD *thd, Item *arg1, Item *arg2)
2654
{
2655
  return new (thd->mem_root) Item_func_nullif(arg1, arg2);
2656
}
2657
2658
2659
Create_func_oct Create_func_oct::s_singleton;
2660
2661
Item*
2662
Create_func_oct::create(THD *thd, Item *arg1)
2663
{
2664
  Item *i10= new (thd->mem_root) Item_int((int32) 10,2);
2665
  Item *i8= new (thd->mem_root) Item_int((int32) 8,1);
2666
  return new (thd->mem_root) Item_func_conv(arg1, i10, i8);
2667
}
2668
2669
2670
Create_func_ord Create_func_ord::s_singleton;
2671
2672
Item*
2673
Create_func_ord::create(THD *thd, Item *arg1)
2674
{
2675
  return new (thd->mem_root) Item_func_ord(arg1);
2676
}
2677
2678
2679
Create_func_period_add Create_func_period_add::s_singleton;
2680
2681
Item*
2682
Create_func_period_add::create(THD *thd, Item *arg1, Item *arg2)
2683
{
2684
  return new (thd->mem_root) Item_func_period_add(arg1, arg2);
2685
}
2686
2687
2688
Create_func_period_diff Create_func_period_diff::s_singleton;
2689
2690
Item*
2691
Create_func_period_diff::create(THD *thd, Item *arg1, Item *arg2)
2692
{
2693
  return new (thd->mem_root) Item_func_period_diff(arg1, arg2);
2694
}
2695
2696
2697
Create_func_pi Create_func_pi::s_singleton;
2698
2699
Item*
2700
Create_func_pi::create(THD *thd)
2701
{
2702
  return new (thd->mem_root) Item_static_float_func("pi()", M_PI, 6, 8);
2703
}
2704
2705
2706
Create_func_pow Create_func_pow::s_singleton;
2707
2708
Item*
2709
Create_func_pow::create(THD *thd, Item *arg1, Item *arg2)
2710
{
2711
  return new (thd->mem_root) Item_func_pow(arg1, arg2);
2712
}
2713
2714
2715
Create_func_quote Create_func_quote::s_singleton;
2716
2717
Item*
2718
Create_func_quote::create(THD *thd, Item *arg1)
2719
{
2720
  return new (thd->mem_root) Item_func_quote(arg1);
2721
}
2722
2723
2724
Create_func_radians Create_func_radians::s_singleton;
2725
2726
Item*
2727
Create_func_radians::create(THD *thd, Item *arg1)
2728
{
2729
  return new (thd->mem_root) Item_func_units((char*) "radians", arg1,
2730
                                             M_PI/180, 0.0);
2731
}
2732
2733
2734
Create_func_rand Create_func_rand::s_singleton;
2735
2736
Item*
2737
Create_func_rand::create_native(THD *thd, LEX_STRING name,
2738
                                List<Item> *item_list)
2739
{
2740
  Item *func= NULL;
2741
  int arg_count= 0;
2742
2743
  if (item_list != NULL)
2744
    arg_count= item_list->elements;
2745
2746
  switch (arg_count) {
2747
  case 0:
2748
  {
2749
    func= new (thd->mem_root) Item_func_rand();
2750
    break;
2751
  }
2752
  case 1:
2753
  {
2754
    Item *param_1= item_list->pop();
2755
    func= new (thd->mem_root) Item_func_rand(param_1);
2756
    break;
2757
  }
2758
  default:
2759
  {
2760
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2761
    break;
2762
  }
2763
  }
2764
2765
  return func;
2766
}
2767
2768
2769
Create_func_round Create_func_round::s_singleton;
2770
2771
Item*
2772
Create_func_round::create_native(THD *thd, LEX_STRING name,
2773
                                 List<Item> *item_list)
2774
{
2775
  Item *func= NULL;
2776
  int arg_count= 0;
2777
2778
  if (item_list != NULL)
2779
    arg_count= item_list->elements;
2780
2781
  switch (arg_count) {
2782
  case 1:
2783
  {
2784
    Item *param_1= item_list->pop();
2785
    Item *i0 = new (thd->mem_root) Item_int((char*)"0", 0, 1);
2786
    func= new (thd->mem_root) Item_func_round(param_1, i0, 0);
2787
    break;
2788
  }
2789
  case 2:
2790
  {
2791
    Item *param_1= item_list->pop();
2792
    Item *param_2= item_list->pop();
2793
    func= new (thd->mem_root) Item_func_round(param_1, param_2, 0);
2794
    break;
2795
  }
2796
  default:
2797
  {
2798
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2799
    break;
2800
  }
2801
  }
2802
2803
  return func;
2804
}
2805
2806
2807
Create_func_row_count Create_func_row_count::s_singleton;
2808
2809
Item*
2810
Create_func_row_count::create(THD *thd)
2811
{
2812
  thd->lex->set_stmt_unsafe();
2813
  return new (thd->mem_root) Item_func_row_count();
2814
}
2815
2816
2817
Create_func_rpad Create_func_rpad::s_singleton;
2818
2819
Item*
2820
Create_func_rpad::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
2821
{
2822
  return new (thd->mem_root) Item_func_rpad(arg1, arg2, arg3);
2823
}
2824
2825
2826
Create_func_rtrim Create_func_rtrim::s_singleton;
2827
2828
Item*
2829
Create_func_rtrim::create(THD *thd, Item *arg1)
2830
{
2831
  return new (thd->mem_root) Item_func_rtrim(arg1);
2832
}
2833
2834
2835
Create_func_sec_to_time Create_func_sec_to_time::s_singleton;
2836
2837
Item*
2838
Create_func_sec_to_time::create(THD *thd, Item *arg1)
2839
{
2840
  return new (thd->mem_root) Item_func_sec_to_time(arg1);
2841
}
2842
2843
2844
Create_func_sign Create_func_sign::s_singleton;
2845
2846
Item*
2847
Create_func_sign::create(THD *thd, Item *arg1)
2848
{
2849
  return new (thd->mem_root) Item_func_sign(arg1);
2850
}
2851
2852
2853
Create_func_sin Create_func_sin::s_singleton;
2854
2855
Item*
2856
Create_func_sin::create(THD *thd, Item *arg1)
2857
{
2858
  return new (thd->mem_root) Item_func_sin(arg1);
2859
}
2860
2861
2862
Create_func_space Create_func_space::s_singleton;
2863
2864
Item*
2865
Create_func_space::create(THD *thd, Item *arg1)
2866
{
2867
  /**
2868
    TODO: Fix Bug#23637
2869
    The parsed item tree should not depend on
2870
    <code>thd->variables.collation_connection</code>.
2871
  */
2872
  CHARSET_INFO *cs= thd->variables.collation_connection;
2873
  Item *sp;
2874
2875
  if (cs->mbminlen > 1)
2876
  {
2877
    uint dummy_errors;
2878
    sp= new (thd->mem_root) Item_string("", 0, cs, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
2879
    sp->str_value.copy(" ", 1, &my_charset_latin1, cs, &dummy_errors);
2880
  }
2881
  else
2882
  {
2883
    sp= new (thd->mem_root) Item_string(" ", 1, cs, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
2884
  }
2885
2886
  return new (thd->mem_root) Item_func_repeat(sp, arg1);
2887
}
2888
2889
2890
Create_func_sqrt Create_func_sqrt::s_singleton;
2891
2892
Item*
2893
Create_func_sqrt::create(THD *thd, Item *arg1)
2894
{
2895
  return new (thd->mem_root) Item_func_sqrt(arg1);
2896
}
2897
2898
2899
Create_func_str_to_date Create_func_str_to_date::s_singleton;
2900
2901
Item*
2902
Create_func_str_to_date::create(THD *thd, Item *arg1, Item *arg2)
2903
{
2904
  return new (thd->mem_root) Item_func_str_to_date(arg1, arg2);
2905
}
2906
2907
2908
Create_func_strcmp Create_func_strcmp::s_singleton;
2909
2910
Item*
2911
Create_func_strcmp::create(THD *thd, Item *arg1, Item *arg2)
2912
{
2913
  return new (thd->mem_root) Item_func_strcmp(arg1, arg2);
2914
}
2915
2916
2917
Create_func_substr_index Create_func_substr_index::s_singleton;
2918
2919
Item*
2920
Create_func_substr_index::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
2921
{
2922
  return new (thd->mem_root) Item_func_substr_index(arg1, arg2, arg3);
2923
}
2924
2925
2926
Create_func_subtime Create_func_subtime::s_singleton;
2927
2928
Item*
2929
Create_func_subtime::create(THD *thd, Item *arg1, Item *arg2)
2930
{
2931
  return new (thd->mem_root) Item_func_add_time(arg1, arg2, 0, 1);
2932
}
2933
2934
2935
Create_func_tan Create_func_tan::s_singleton;
2936
2937
Item*
2938
Create_func_tan::create(THD *thd, Item *arg1)
2939
{
2940
  return new (thd->mem_root) Item_func_tan(arg1);
2941
}
2942
2943
2944
Create_func_time_format Create_func_time_format::s_singleton;
2945
2946
Item*
2947
Create_func_time_format::create(THD *thd, Item *arg1, Item *arg2)
2948
{
2949
  return new (thd->mem_root) Item_func_date_format(arg1, arg2, 1);
2950
}
2951
2952
2953
Create_func_time_to_sec Create_func_time_to_sec::s_singleton;
2954
2955
Item*
2956
Create_func_time_to_sec::create(THD *thd, Item *arg1)
2957
{
2958
  return new (thd->mem_root) Item_func_time_to_sec(arg1);
2959
}
2960
2961
2962
Create_func_timediff Create_func_timediff::s_singleton;
2963
2964
Item*
2965
Create_func_timediff::create(THD *thd, Item *arg1, Item *arg2)
2966
{
2967
  return new (thd->mem_root) Item_func_timediff(arg1, arg2);
2968
}
2969
2970
2971
Create_func_to_days Create_func_to_days::s_singleton;
2972
2973
Item*
2974
Create_func_to_days::create(THD *thd, Item *arg1)
2975
{
2976
  return new (thd->mem_root) Item_func_to_days(arg1);
2977
}
2978
2979
2980
Create_func_ucase Create_func_ucase::s_singleton;
2981
2982
Item*
2983
Create_func_ucase::create(THD *thd, Item *arg1)
2984
{
2985
  return new (thd->mem_root) Item_func_ucase(arg1);
2986
}
2987
2988
2989
Create_func_unhex Create_func_unhex::s_singleton;
2990
2991
Item*
2992
Create_func_unhex::create(THD *thd, Item *arg1)
2993
{
2994
  return new (thd->mem_root) Item_func_unhex(arg1);
2995
}
2996
2997
2998
Create_func_unix_timestamp Create_func_unix_timestamp::s_singleton;
2999
3000
Item*
3001
Create_func_unix_timestamp::create_native(THD *thd, LEX_STRING name,
3002
                                          List<Item> *item_list)
3003
{
3004
  Item *func= NULL;
3005
  int arg_count= 0;
3006
3007
  if (item_list != NULL)
3008
    arg_count= item_list->elements;
3009
3010
  switch (arg_count) {
3011
  case 0:
3012
  {
3013
    func= new (thd->mem_root) Item_func_unix_timestamp();
3014
    break;
3015
  }
3016
  case 1:
3017
  {
3018
    Item *param_1= item_list->pop();
3019
    func= new (thd->mem_root) Item_func_unix_timestamp(param_1);
3020
    break;
3021
  }
3022
  default:
3023
  {
3024
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
3025
    break;
3026
  }
3027
  }
3028
3029
  return func;
3030
}
3031
3032
3033
Create_func_uuid Create_func_uuid::s_singleton;
3034
3035
Item*
3036
Create_func_uuid::create(THD *thd)
3037
{
3038
  thd->lex->set_stmt_unsafe();
3039
  return new (thd->mem_root) Item_func_uuid();
3040
}
3041
3042
3043
Create_func_uuid_short Create_func_uuid_short::s_singleton;
3044
3045
Item*
3046
Create_func_uuid_short::create(THD *thd)
3047
{
3048
  thd->lex->set_stmt_unsafe();
3049
  return new (thd->mem_root) Item_func_uuid_short();
3050
}
3051
3052
3053
Create_func_version Create_func_version::s_singleton;
3054
3055
Item*
3056
Create_func_version::create(THD *thd)
3057
{
3058
  return new (thd->mem_root) Item_static_string_func("version()",
3059
                                                     server_version,
3060
                                                     (uint) strlen(server_version),
3061
                                                     system_charset_info,
3062
                                                     DERIVATION_SYSCONST);
3063
}
3064
3065
3066
Create_func_weekday Create_func_weekday::s_singleton;
3067
3068
Item*
3069
Create_func_weekday::create(THD *thd, Item *arg1)
3070
{
3071
  return new (thd->mem_root) Item_func_weekday(arg1, 0);
3072
}
3073
3074
3075
Create_func_weekofyear Create_func_weekofyear::s_singleton;
3076
3077
Item*
3078
Create_func_weekofyear::create(THD *thd, Item *arg1)
3079
{
3080
  Item *i1= new (thd->mem_root) Item_int((char*) "0", 3, 1);
3081
  return new (thd->mem_root) Item_func_week(arg1, i1);
3082
}
3083
3084
3085
Create_func_year_week Create_func_year_week::s_singleton;
3086
3087
Item*
3088
Create_func_year_week::create_native(THD *thd, LEX_STRING name,
3089
                                     List<Item> *item_list)
3090
{
3091
  Item *func= NULL;
3092
  int arg_count= 0;
3093
3094
  if (item_list != NULL)
3095
    arg_count= item_list->elements;
3096
3097
  switch (arg_count) {
3098
  case 1:
3099
  {
3100
    Item *param_1= item_list->pop();
3101
    Item *i0= new (thd->mem_root) Item_int((char*) "0", 0, 1);
3102
    func= new (thd->mem_root) Item_func_yearweek(param_1, i0);
3103
    break;
3104
  }
3105
  case 2:
3106
  {
3107
    Item *param_1= item_list->pop();
3108
    Item *param_2= item_list->pop();
3109
    func= new (thd->mem_root) Item_func_yearweek(param_1, param_2);
3110
    break;
3111
  }
3112
  default:
3113
  {
3114
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
3115
    break;
3116
  }
3117
  }
3118
3119
  return func;
3120
}
3121
3122
3123
struct Native_func_registry
3124
{
3125
  LEX_STRING name;
3126
  Create_func *builder;
3127
};
3128
3129
#define BUILDER(F) & F::s_singleton
3130
3131
/*
3132
  MySQL native functions.
3133
  MAINTAINER:
3134
  - Keep sorted for human lookup. At runtime, a hash table is used.
3135
  - keep 1 line per entry, it makes grep | sort easier
3136
*/
3137
3138
static Native_func_registry func_array[] =
3139
{
3140
  { { C_STRING_WITH_LEN("ABS") }, BUILDER(Create_func_abs)},
3141
  { { C_STRING_WITH_LEN("ACOS") }, BUILDER(Create_func_acos)},
3142
  { { C_STRING_WITH_LEN("ADDTIME") }, BUILDER(Create_func_addtime)},
3143
  { { C_STRING_WITH_LEN("ASIN") }, BUILDER(Create_func_asin)},
3144
  { { C_STRING_WITH_LEN("ATAN") }, BUILDER(Create_func_atan)},
3145
  { { C_STRING_WITH_LEN("ATAN2") }, BUILDER(Create_func_atan)},
3146
  { { C_STRING_WITH_LEN("BENCHMARK") }, BUILDER(Create_func_benchmark)},
3147
  { { C_STRING_WITH_LEN("BIN") }, BUILDER(Create_func_bin)},
3148
  { { C_STRING_WITH_LEN("BIT_COUNT") }, BUILDER(Create_func_bit_count)},
3149
  { { C_STRING_WITH_LEN("BIT_LENGTH") }, BUILDER(Create_func_bit_length)},
3150
  { { C_STRING_WITH_LEN("CEIL") }, BUILDER(Create_func_ceiling)},
3151
  { { C_STRING_WITH_LEN("CEILING") }, BUILDER(Create_func_ceiling)},
3152
  { { C_STRING_WITH_LEN("CHARACTER_LENGTH") }, BUILDER(Create_func_char_length)},
3153
  { { C_STRING_WITH_LEN("CHAR_LENGTH") }, BUILDER(Create_func_char_length)},
3154
  { { C_STRING_WITH_LEN("COERCIBILITY") }, BUILDER(Create_func_coercibility)},
3155
  { { C_STRING_WITH_LEN("CONCAT") }, BUILDER(Create_func_concat)},
3156
  { { C_STRING_WITH_LEN("CONCAT_WS") }, BUILDER(Create_func_concat_ws)},
3157
  { { C_STRING_WITH_LEN("CONNECTION_ID") }, BUILDER(Create_func_connection_id)},
3158
  { { C_STRING_WITH_LEN("CONV") }, BUILDER(Create_func_conv)},
3159
  { { C_STRING_WITH_LEN("COS") }, BUILDER(Create_func_cos)},
3160
  { { C_STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)},
3161
  { { C_STRING_WITH_LEN("CRC32") }, BUILDER(Create_func_crc32)},
3162
  { { C_STRING_WITH_LEN("DATEDIFF") }, BUILDER(Create_func_datediff)},
3163
  { { C_STRING_WITH_LEN("DATE_FORMAT") }, BUILDER(Create_func_date_format)},
3164
  { { C_STRING_WITH_LEN("DAYNAME") }, BUILDER(Create_func_dayname)},
3165
  { { C_STRING_WITH_LEN("DAYOFMONTH") }, BUILDER(Create_func_dayofmonth)},
3166
  { { C_STRING_WITH_LEN("DAYOFWEEK") }, BUILDER(Create_func_dayofweek)},
3167
  { { C_STRING_WITH_LEN("DAYOFYEAR") }, BUILDER(Create_func_dayofyear)},
3168
  { { C_STRING_WITH_LEN("DECODE") }, BUILDER(Create_func_decode)},
3169
  { { C_STRING_WITH_LEN("DEGREES") }, BUILDER(Create_func_degrees)},
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)},
3173
  { { C_STRING_WITH_LEN("EXP") }, BUILDER(Create_func_exp)},
3174
  { { C_STRING_WITH_LEN("EXPORT_SET") }, BUILDER(Create_func_export_set)},
3175
  { { C_STRING_WITH_LEN("FIELD") }, BUILDER(Create_func_field)},
3176
  { { C_STRING_WITH_LEN("FIND_IN_SET") }, BUILDER(Create_func_find_in_set)},
3177
  { { C_STRING_WITH_LEN("FLOOR") }, BUILDER(Create_func_floor)},
3178
  { { C_STRING_WITH_LEN("FORMAT") }, BUILDER(Create_func_format)},
3179
  { { C_STRING_WITH_LEN("FOUND_ROWS") }, BUILDER(Create_func_found_rows)},
3180
  { { C_STRING_WITH_LEN("FROM_DAYS") }, BUILDER(Create_func_from_days)},
3181
  { { C_STRING_WITH_LEN("FROM_UNIXTIME") }, BUILDER(Create_func_from_unixtime)},
3182
  { { C_STRING_WITH_LEN("GREATEST") }, BUILDER(Create_func_greatest)},
3183
  { { C_STRING_WITH_LEN("HEX") }, BUILDER(Create_func_hex)},
3184
  { { C_STRING_WITH_LEN("IFNULL") }, BUILDER(Create_func_ifnull)},
3185
  { { C_STRING_WITH_LEN("INSTR") }, BUILDER(Create_func_instr)},
3186
  { { C_STRING_WITH_LEN("ISNULL") }, BUILDER(Create_func_isnull)},
3187
  { { C_STRING_WITH_LEN("LAST_DAY") }, BUILDER(Create_func_last_day)},
3188
  { { C_STRING_WITH_LEN("LAST_INSERT_ID") }, BUILDER(Create_func_last_insert_id)},
3189
  { { C_STRING_WITH_LEN("LCASE") }, BUILDER(Create_func_lcase)},
3190
  { { C_STRING_WITH_LEN("LEAST") }, BUILDER(Create_func_least)},
3191
  { { C_STRING_WITH_LEN("LENGTH") }, BUILDER(Create_func_length)},
3192
  { { C_STRING_WITH_LEN("LN") }, BUILDER(Create_func_ln)},
3193
  { { C_STRING_WITH_LEN("LOAD_FILE") }, BUILDER(Create_func_load_file)},
3194
  { { C_STRING_WITH_LEN("LOCATE") }, BUILDER(Create_func_locate)},
3195
  { { C_STRING_WITH_LEN("LOG") }, BUILDER(Create_func_log)},
3196
  { { C_STRING_WITH_LEN("LOG10") }, BUILDER(Create_func_log10)},
3197
  { { C_STRING_WITH_LEN("LOG2") }, BUILDER(Create_func_log2)},
3198
  { { C_STRING_WITH_LEN("LOWER") }, BUILDER(Create_func_lcase)},
3199
  { { C_STRING_WITH_LEN("LPAD") }, BUILDER(Create_func_lpad)},
3200
  { { C_STRING_WITH_LEN("LTRIM") }, BUILDER(Create_func_ltrim)},
3201
  { { C_STRING_WITH_LEN("MAKEDATE") }, BUILDER(Create_func_makedate)},
3202
  { { C_STRING_WITH_LEN("MAKETIME") }, BUILDER(Create_func_maketime)},
3203
  { { C_STRING_WITH_LEN("MAKE_SET") }, BUILDER(Create_func_make_set)},
3204
  { { C_STRING_WITH_LEN("MASTER_POS_WAIT") }, BUILDER(Create_func_master_pos_wait)},
3205
  { { C_STRING_WITH_LEN("MD5") }, BUILDER(Create_func_md5)},
3206
  { { C_STRING_WITH_LEN("MONTHNAME") }, BUILDER(Create_func_monthname)},
3207
  { { C_STRING_WITH_LEN("NULLIF") }, BUILDER(Create_func_nullif)},
3208
  { { C_STRING_WITH_LEN("OCT") }, BUILDER(Create_func_oct)},
3209
  { { C_STRING_WITH_LEN("OCTET_LENGTH") }, BUILDER(Create_func_length)},
3210
  { { C_STRING_WITH_LEN("ORD") }, BUILDER(Create_func_ord)},
3211
  { { C_STRING_WITH_LEN("PERIOD_ADD") }, BUILDER(Create_func_period_add)},
3212
  { { C_STRING_WITH_LEN("PERIOD_DIFF") }, BUILDER(Create_func_period_diff)},
3213
  { { C_STRING_WITH_LEN("PI") }, BUILDER(Create_func_pi)},
3214
  { { C_STRING_WITH_LEN("POW") }, BUILDER(Create_func_pow)},
3215
  { { C_STRING_WITH_LEN("POWER") }, BUILDER(Create_func_pow)},
3216
  { { C_STRING_WITH_LEN("QUOTE") }, BUILDER(Create_func_quote)},
3217
  { { C_STRING_WITH_LEN("RADIANS") }, BUILDER(Create_func_radians)},
3218
  { { C_STRING_WITH_LEN("RAND") }, BUILDER(Create_func_rand)},
3219
  { { C_STRING_WITH_LEN("ROUND") }, BUILDER(Create_func_round)},
3220
  { { C_STRING_WITH_LEN("ROW_COUNT") }, BUILDER(Create_func_row_count)},
3221
  { { C_STRING_WITH_LEN("RPAD") }, BUILDER(Create_func_rpad)},
3222
  { { C_STRING_WITH_LEN("RTRIM") }, BUILDER(Create_func_rtrim)},
3223
  { { C_STRING_WITH_LEN("SEC_TO_TIME") }, BUILDER(Create_func_sec_to_time)},
3224
  { { C_STRING_WITH_LEN("SIGN") }, BUILDER(Create_func_sign)},
3225
  { { C_STRING_WITH_LEN("SIN") }, BUILDER(Create_func_sin)},
3226
  { { C_STRING_WITH_LEN("SPACE") }, BUILDER(Create_func_space)},
3227
  { { C_STRING_WITH_LEN("SQRT") }, BUILDER(Create_func_sqrt)},
3228
  { { C_STRING_WITH_LEN("STRCMP") }, BUILDER(Create_func_strcmp)},
3229
  { { C_STRING_WITH_LEN("STR_TO_DATE") }, BUILDER(Create_func_str_to_date)},
3230
  { { C_STRING_WITH_LEN("SUBSTRING_INDEX") }, BUILDER(Create_func_substr_index)},
3231
  { { C_STRING_WITH_LEN("SUBTIME") }, BUILDER(Create_func_subtime)},
3232
  { { C_STRING_WITH_LEN("TAN") }, BUILDER(Create_func_tan)},
3233
  { { C_STRING_WITH_LEN("TIMEDIFF") }, BUILDER(Create_func_timediff)},
3234
  { { C_STRING_WITH_LEN("TIME_FORMAT") }, BUILDER(Create_func_time_format)},
3235
  { { C_STRING_WITH_LEN("TIME_TO_SEC") }, BUILDER(Create_func_time_to_sec)},
3236
  { { C_STRING_WITH_LEN("TO_DAYS") }, BUILDER(Create_func_to_days)},
3237
  { { C_STRING_WITH_LEN("UCASE") }, BUILDER(Create_func_ucase)},
3238
  { { C_STRING_WITH_LEN("UNHEX") }, BUILDER(Create_func_unhex)},
3239
  { { C_STRING_WITH_LEN("UNIX_TIMESTAMP") }, BUILDER(Create_func_unix_timestamp)},
3240
  { { C_STRING_WITH_LEN("UPPER") }, BUILDER(Create_func_ucase)},
3241
  { { C_STRING_WITH_LEN("UUID") }, BUILDER(Create_func_uuid)},
3242
  { { C_STRING_WITH_LEN("UUID_SHORT") }, BUILDER(Create_func_uuid_short)},
3243
  { { C_STRING_WITH_LEN("VERSION") }, BUILDER(Create_func_version)},
3244
  { { C_STRING_WITH_LEN("WEEKDAY") }, BUILDER(Create_func_weekday)},
3245
  { { C_STRING_WITH_LEN("WEEKOFYEAR") }, BUILDER(Create_func_weekofyear)},
3246
  { { C_STRING_WITH_LEN("YEARWEEK") }, BUILDER(Create_func_year_week)},
3247
3248
  { {0, 0}, NULL}
3249
};
3250
3251
static HASH native_functions_hash;
3252
3253
extern "C" uchar*
3254
get_native_fct_hash_key(const uchar *buff, size_t *length,
3255
                        my_bool /* unused */)
3256
{
3257
  Native_func_registry *func= (Native_func_registry*) buff;
3258
  *length= func->name.length;
3259
  return (uchar*) func->name.str;
3260
}
3261
3262
/*
3263
  Load the hash table for native functions.
3264
  Note: this code is not thread safe, and is intended to be used at server
3265
  startup only (before going multi-threaded)
3266
*/
3267
3268
int item_create_init()
3269
{
3270
  Native_func_registry *func;
3271
3272
  DBUG_ENTER("item_create_init");
3273
3274
  if (hash_init(& native_functions_hash,
3275
                system_charset_info,
3276
                array_elements(func_array),
3277
                0,
3278
                0,
3279
                (hash_get_key) get_native_fct_hash_key,
3280
                NULL,                          /* Nothing to free */
3281
                MYF(0)))
3282
    DBUG_RETURN(1);
3283
3284
  for (func= func_array; func->builder != NULL; func++)
3285
  {
3286
    if (my_hash_insert(& native_functions_hash, (uchar*) func))
3287
      DBUG_RETURN(1);
3288
  }
3289
3290
#ifndef DBUG_OFF
3291
  for (uint i=0 ; i < native_functions_hash.records ; i++)
3292
  {
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));
3296
  }
3297
#endif
3298
3299
  DBUG_RETURN(0);
3300
}
3301
3302
/*
3303
  Empty the hash table for native functions.
3304
  Note: this code is not thread safe, and is intended to be used at server
3305
  shutdown only (after thread requests have been executed).
3306
*/
3307
3308
void item_create_cleanup()
3309
{
3310
  DBUG_ENTER("item_create_cleanup");
3311
  hash_free(& native_functions_hash);
3312
  DBUG_VOID_RETURN;
3313
}
3314
3315
Create_func *
3316
find_native_function_builder(THD *thd, LEX_STRING name)
3317
{
3318
  Native_func_registry *func;
3319
  Create_func *builder= NULL;
3320
3321
  /* Thread safe */
3322
  func= (Native_func_registry*) hash_search(& native_functions_hash,
3323
                                            (uchar*) name.str,
3324
                                             name.length);
3325
3326
  if (func)
3327
  {
3328
    builder= func->builder;
3329
  }
3330
3331
  return builder;
3332
}
3333
3334
3335
Item*
3336
create_func_char_cast(THD *thd, Item *a, int len, CHARSET_INFO *cs)
3337
{
3338
  CHARSET_INFO *real_cs= (cs ? cs : thd->variables.collation_connection);
3339
  return new (thd->mem_root) Item_char_typecast(a, len, real_cs);
3340
}
3341
3342
3343
Item *
3344
create_func_cast(THD *thd, Item *a, Cast_target cast_type,
3345
                 const char *c_len, const char *c_dec,
3346
                 CHARSET_INFO *cs)
3347
{
3348
  Item *res;
3349
  ulong len;
3350
  uint dec;
3351
3352
  switch (cast_type) {
3353
  case ITEM_CAST_BINARY:
3354
    res= new (thd->mem_root) Item_func_binary(a);
3355
    break;
3356
  case ITEM_CAST_SIGNED_INT:
3357
    res= new (thd->mem_root) Item_func_signed(a);
3358
    break;
3359
  case ITEM_CAST_UNSIGNED_INT:
3360
    res= new (thd->mem_root) Item_func_unsigned(a);
3361
    break;
3362
  case ITEM_CAST_DATE:
3363
    res= new (thd->mem_root) Item_date_typecast(a);
3364
    break;
3365
  case ITEM_CAST_TIME:
3366
    res= new (thd->mem_root) Item_time_typecast(a);
3367
    break;
3368
  case ITEM_CAST_DATETIME:
3369
    res= new (thd->mem_root) Item_datetime_typecast(a);
3370
    break;
3371
  case ITEM_CAST_DECIMAL:
3372
  {
3373
    len= c_len ? atoi(c_len) : 0;
3374
    dec= c_dec ? atoi(c_dec) : 0;
3375
    my_decimal_trim(&len, &dec);
3376
    if (len < dec)
3377
    {
3378
      my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
3379
      return 0;
3380
    }
3381
    if (len > DECIMAL_MAX_PRECISION)
3382
    {
3383
      my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name,
3384
               DECIMAL_MAX_PRECISION);
3385
      return 0;
3386
    }
3387
    if (dec > DECIMAL_MAX_SCALE)
3388
    {
3389
      my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name,
3390
               DECIMAL_MAX_SCALE);
3391
      return 0;
3392
    }
3393
    res= new (thd->mem_root) Item_decimal_typecast(a, len, dec);
3394
    break;
3395
  }
3396
  case ITEM_CAST_CHAR:
3397
  {
3398
    len= c_len ? atoi(c_len) : -1;
3399
    res= create_func_char_cast(thd, a, len, cs);
3400
    break;
3401
  }
3402
  default:
3403
  {
3404
    DBUG_ASSERT(0);
3405
    res= 0;
3406
    break;
3407
  }
3408
  }
3409
  return res;
3410
}