~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_version : public Create_func_arg0
1424
{
1425
public:
1426
  virtual Item *create(THD *thd);
1427
1428
  static Create_func_version s_singleton;
1429
1430
protected:
1431
  Create_func_version() {}
1432
  virtual ~Create_func_version() {}
1433
};
1434
1435
1436
class Create_func_weekday : public Create_func_arg1
1437
{
1438
public:
1439
  virtual Item *create(THD *thd, Item *arg1);
1440
1441
  static Create_func_weekday s_singleton;
1442
1443
protected:
1444
  Create_func_weekday() {}
1445
  virtual ~Create_func_weekday() {}
1446
};
1447
1448
1449
class Create_func_weekofyear : public Create_func_arg1
1450
{
1451
public:
1452
  virtual Item *create(THD *thd, Item *arg1);
1453
1454
  static Create_func_weekofyear s_singleton;
1455
1456
protected:
1457
  Create_func_weekofyear() {}
1458
  virtual ~Create_func_weekofyear() {}
1459
};
1460
1461
1462
class Create_func_year_week : public Create_native_func
1463
{
1464
public:
1465
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
1466
1467
  static Create_func_year_week s_singleton;
1468
1469
protected:
1470
  Create_func_year_week() {}
1471
  virtual ~Create_func_year_week() {}
1472
};
1473
1474
1475
/*
1476
=============================================================================
1477
  IMPLEMENTATION
1478
=============================================================================
1479
*/
1480
1481
/**
1482
  Checks if there are named parameters in a parameter list.
1483
  The syntax to name parameters in a function call is as follow:
1484
  <code>foo(expr AS named, expr named, expr AS "named", expr "named")</code>
1485
  @param params The parameter list, can be null
1486
  @return true if one or more parameter is named
1487
*/
1488
static bool has_named_parameters(List<Item> *params)
1489
{
1490
  if (params)
1491
  {
1492
    Item *param;
1493
    List_iterator<Item> it(*params);
1494
    while ((param= it++))
1495
    {
1496
      if (! param->is_autogenerated_name)
1497
        return true;
1498
    }
1499
  }
1500
1501
  return false;
1502
}
1503
1504
1505
Create_udf_func Create_udf_func::s_singleton;
1506
1507
Item*
1508
Create_udf_func::create(THD *thd, LEX_STRING name, List<Item> *item_list)
1509
{
1510
  udf_func *udf= find_udf(name.str, name.length);
51.1.19 by Jay Pipes
Removed/replace DBUG symbols
1511
  assert(udf);
1 by brian
clean slate
1512
  return create(thd, udf, item_list);
1513
}
1514
1515
1516
Item*
1517
Create_udf_func::create(THD *thd, udf_func *udf, List<Item> *item_list)
1518
{
1519
  Item *func= NULL;
1520
  int arg_count= 0;
1521
1522
  if (item_list != NULL)
1523
    arg_count= item_list->elements;
1524
1525
  thd->lex->set_stmt_unsafe();
1526
51.1.19 by Jay Pipes
Removed/replace DBUG symbols
1527
  assert(   (udf->type == UDFTYPE_FUNCTION)
1 by brian
clean slate
1528
              || (udf->type == UDFTYPE_AGGREGATE));
1529
1530
  switch(udf->returns) {
1531
  case STRING_RESULT:
1532
  {
1533
    if (udf->type == UDFTYPE_FUNCTION)
1534
    {
1535
      if (arg_count)
1536
        func= new (thd->mem_root) Item_func_udf_str(udf, *item_list);
1537
      else
1538
        func= new (thd->mem_root) Item_func_udf_str(udf);
1539
    }
1540
    else
1541
    {
1542
      if (arg_count)
1543
        func= new (thd->mem_root) Item_sum_udf_str(udf, *item_list);
1544
      else
1545
        func= new (thd->mem_root) Item_sum_udf_str(udf);
1546
    }
1547
    break;
1548
  }
1549
  case REAL_RESULT:
1550
  {
1551
    if (udf->type == UDFTYPE_FUNCTION)
1552
    {
1553
      if (arg_count)
1554
        func= new (thd->mem_root) Item_func_udf_float(udf, *item_list);
1555
      else
1556
        func= new (thd->mem_root) Item_func_udf_float(udf);
1557
    }
1558
    else
1559
    {
1560
      if (arg_count)
1561
        func= new (thd->mem_root) Item_sum_udf_float(udf, *item_list);
1562
      else
1563
        func= new (thd->mem_root) Item_sum_udf_float(udf);
1564
    }
1565
    break;
1566
  }
1567
  case INT_RESULT:
1568
  {
1569
    if (udf->type == UDFTYPE_FUNCTION)
1570
    {
1571
      if (arg_count)
1572
        func= new (thd->mem_root) Item_func_udf_int(udf, *item_list);
1573
      else
1574
        func= new (thd->mem_root) Item_func_udf_int(udf);
1575
    }
1576
    else
1577
    {
1578
      if (arg_count)
1579
        func= new (thd->mem_root) Item_sum_udf_int(udf, *item_list);
1580
      else
1581
        func= new (thd->mem_root) Item_sum_udf_int(udf);
1582
    }
1583
    break;
1584
  }
1585
  case DECIMAL_RESULT:
1586
  {
1587
    if (udf->type == UDFTYPE_FUNCTION)
1588
    {
1589
      if (arg_count)
1590
        func= new (thd->mem_root) Item_func_udf_decimal(udf, *item_list);
1591
      else
1592
        func= new (thd->mem_root) Item_func_udf_decimal(udf);
1593
    }
1594
    else
1595
    {
1596
      if (arg_count)
1597
        func= new (thd->mem_root) Item_sum_udf_decimal(udf, *item_list);
1598
      else
1599
        func= new (thd->mem_root) Item_sum_udf_decimal(udf);
1600
    }
1601
    break;
1602
  }
1603
  default:
1604
  {
1605
    my_error(ER_NOT_SUPPORTED_YET, MYF(0), "UDF return type");
1606
  }
1607
  }
1608
  return func;
1609
}
1610
1611
1612
Item*
1613
Create_native_func::create(THD *thd, LEX_STRING name, List<Item> *item_list)
1614
{
1615
  if (has_named_parameters(item_list))
1616
  {
1617
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1618
    return NULL;
1619
  }
1620
1621
  return create_native(thd, name, item_list);
1622
}
1623
1624
1625
Item*
1626
Create_func_arg0::create(THD *thd, LEX_STRING name, List<Item> *item_list)
1627
{
1628
  int arg_count= 0;
1629
1630
  if (item_list != NULL)
1631
    arg_count= item_list->elements;
1632
1633
  if (arg_count != 0)
1634
  {
1635
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1636
    return NULL;
1637
  }
1638
1639
  return create(thd);
1640
}
1641
1642
1643
Item*
1644
Create_func_arg1::create(THD *thd, LEX_STRING name, List<Item> *item_list)
1645
{
1646
  int arg_count= 0;
1647
1648
  if (item_list)
1649
    arg_count= item_list->elements;
1650
1651
  if (arg_count != 1)
1652
  {
1653
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1654
    return NULL;
1655
  }
1656
1657
  Item *param_1= item_list->pop();
1658
1659
  if (! param_1->is_autogenerated_name)
1660
  {
1661
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1662
    return NULL;
1663
  }
1664
1665
  return create(thd, param_1);
1666
}
1667
1668
1669
Item*
1670
Create_func_arg2::create(THD *thd, LEX_STRING name, List<Item> *item_list)
1671
{
1672
  int arg_count= 0;
1673
1674
  if (item_list)
1675
    arg_count= item_list->elements;
1676
1677
  if (arg_count != 2)
1678
  {
1679
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1680
    return NULL;
1681
  }
1682
1683
  Item *param_1= item_list->pop();
1684
  Item *param_2= item_list->pop();
1685
1686
  if (   (! param_1->is_autogenerated_name)
1687
      || (! param_2->is_autogenerated_name))
1688
  {
1689
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1690
    return NULL;
1691
  }
1692
1693
  return create(thd, param_1, param_2);
1694
}
1695
1696
1697
Item*
1698
Create_func_arg3::create(THD *thd, LEX_STRING name, List<Item> *item_list)
1699
{
1700
  int arg_count= 0;
1701
1702
  if (item_list)
1703
    arg_count= item_list->elements;
1704
1705
  if (arg_count != 3)
1706
  {
1707
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1708
    return NULL;
1709
  }
1710
1711
  Item *param_1= item_list->pop();
1712
  Item *param_2= item_list->pop();
1713
  Item *param_3= item_list->pop();
1714
1715
  if (   (! param_1->is_autogenerated_name)
1716
      || (! param_2->is_autogenerated_name)
1717
      || (! param_3->is_autogenerated_name))
1718
  {
1719
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1720
    return NULL;
1721
  }
1722
1723
  return create(thd, param_1, param_2, param_3);
1724
}
1725
1726
1727
Create_func_abs Create_func_abs::s_singleton;
1728
1729
Item*
1730
Create_func_abs::create(THD *thd, Item *arg1)
1731
{
1732
  return new (thd->mem_root) Item_func_abs(arg1);
1733
}
1734
1735
1736
Create_func_acos Create_func_acos::s_singleton;
1737
1738
Item*
1739
Create_func_acos::create(THD *thd, Item *arg1)
1740
{
1741
  return new (thd->mem_root) Item_func_acos(arg1);
1742
}
1743
1744
1745
Create_func_addtime Create_func_addtime::s_singleton;
1746
1747
Item*
1748
Create_func_addtime::create(THD *thd, Item *arg1, Item *arg2)
1749
{
1750
  return new (thd->mem_root) Item_func_add_time(arg1, arg2, 0, 0);
1751
}
1752
1753
1754
Create_func_asin Create_func_asin::s_singleton;
1755
1756
Item*
1757
Create_func_asin::create(THD *thd, Item *arg1)
1758
{
1759
  return new (thd->mem_root) Item_func_asin(arg1);
1760
}
1761
1762
1763
Create_func_atan Create_func_atan::s_singleton;
1764
1765
Item*
1766
Create_func_atan::create_native(THD *thd, LEX_STRING name,
1767
                                List<Item> *item_list)
1768
{
1769
  Item* func= NULL;
1770
  int arg_count= 0;
1771
1772
  if (item_list != NULL)
1773
    arg_count= item_list->elements;
1774
1775
  switch (arg_count) {
1776
  case 1:
1777
  {
1778
    Item *param_1= item_list->pop();
1779
    func= new (thd->mem_root) Item_func_atan(param_1);
1780
    break;
1781
  }
1782
  case 2:
1783
  {
1784
    Item *param_1= item_list->pop();
1785
    Item *param_2= item_list->pop();
1786
    func= new (thd->mem_root) Item_func_atan(param_1, param_2);
1787
    break;
1788
  }
1789
  default:
1790
  {
1791
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1792
    break;
1793
  }
1794
  }
1795
1796
  return func;
1797
}
1798
1799
1800
Create_func_benchmark Create_func_benchmark::s_singleton;
1801
1802
Item*
1803
Create_func_benchmark::create(THD *thd, Item *arg1, Item *arg2)
1804
{
1805
  return new (thd->mem_root) Item_func_benchmark(arg1, arg2);
1806
}
1807
1808
1809
Create_func_bin Create_func_bin::s_singleton;
1810
1811
Item*
1812
Create_func_bin::create(THD *thd, Item *arg1)
1813
{
1814
  Item *i10= new (thd->mem_root) Item_int((int32) 10,2);
1815
  Item *i2= new (thd->mem_root) Item_int((int32) 2,1);
1816
  return new (thd->mem_root) Item_func_conv(arg1, i10, i2);
1817
}
1818
1819
1820
Create_func_bit_count Create_func_bit_count::s_singleton;
1821
1822
Item*
1823
Create_func_bit_count::create(THD *thd, Item *arg1)
1824
{
1825
  return new (thd->mem_root) Item_func_bit_count(arg1);
1826
}
1827
1828
1829
Create_func_bit_length Create_func_bit_length::s_singleton;
1830
1831
Item*
1832
Create_func_bit_length::create(THD *thd, Item *arg1)
1833
{
1834
  return new (thd->mem_root) Item_func_bit_length(arg1);
1835
}
1836
1837
1838
Create_func_ceiling Create_func_ceiling::s_singleton;
1839
1840
Item*
1841
Create_func_ceiling::create(THD *thd, Item *arg1)
1842
{
1843
  return new (thd->mem_root) Item_func_ceiling(arg1);
1844
}
1845
1846
1847
Create_func_char_length Create_func_char_length::s_singleton;
1848
1849
Item*
1850
Create_func_char_length::create(THD *thd, Item *arg1)
1851
{
1852
  return new (thd->mem_root) Item_func_char_length(arg1);
1853
}
1854
1855
1856
Create_func_coercibility Create_func_coercibility::s_singleton;
1857
1858
Item*
1859
Create_func_coercibility::create(THD *thd, Item *arg1)
1860
{
1861
  return new (thd->mem_root) Item_func_coercibility(arg1);
1862
}
1863
1864
1865
Create_func_concat Create_func_concat::s_singleton;
1866
1867
Item*
1868
Create_func_concat::create_native(THD *thd, LEX_STRING name,
1869
                                  List<Item> *item_list)
1870
{
1871
  int arg_count= 0;
1872
1873
  if (item_list != NULL)
1874
    arg_count= item_list->elements;
1875
1876
  if (arg_count < 1)
1877
  {
1878
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1879
    return NULL;
1880
  }
1881
1882
  return new (thd->mem_root) Item_func_concat(*item_list);
1883
}
1884
1885
1886
Create_func_concat_ws Create_func_concat_ws::s_singleton;
1887
1888
Item*
1889
Create_func_concat_ws::create_native(THD *thd, LEX_STRING name,
1890
                                     List<Item> *item_list)
1891
{
1892
  int arg_count= 0;
1893
1894
  if (item_list != NULL)
1895
    arg_count= item_list->elements;
1896
1897
  /* "WS" stands for "With Separator": this function takes 2+ arguments */
1898
  if (arg_count < 2)
1899
  {
1900
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1901
    return NULL;
1902
  }
1903
1904
  return new (thd->mem_root) Item_func_concat_ws(*item_list);
1905
}
1906
1907
1908
Create_func_connection_id Create_func_connection_id::s_singleton;
1909
1910
Item*
1911
Create_func_connection_id::create(THD *thd)
1912
{
1913
  return new (thd->mem_root) Item_func_connection_id();
1914
}
1915
1916
1917
Create_func_conv Create_func_conv::s_singleton;
1918
1919
Item*
1920
Create_func_conv::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
1921
{
1922
  return new (thd->mem_root) Item_func_conv(arg1, arg2, arg3);
1923
}
1924
1925
1926
Create_func_cos Create_func_cos::s_singleton;
1927
1928
Item*
1929
Create_func_cos::create(THD *thd, Item *arg1)
1930
{
1931
  return new (thd->mem_root) Item_func_cos(arg1);
1932
}
1933
1934
1935
Create_func_cot Create_func_cot::s_singleton;
1936
1937
Item*
1938
Create_func_cot::create(THD *thd, Item *arg1)
1939
{
1940
  Item *i1= new (thd->mem_root) Item_int((char*) "1", 1, 1);
1941
  Item *i2= new (thd->mem_root) Item_func_tan(arg1);
1942
  return new (thd->mem_root) Item_func_div(i1, i2);
1943
}
1944
1945
1946
Create_func_crc32 Create_func_crc32::s_singleton;
1947
1948
Item*
1949
Create_func_crc32::create(THD *thd, Item *arg1)
1950
{
1951
  return new (thd->mem_root) Item_func_crc32(arg1);
1952
}
1953
1954
1955
Create_func_date_format Create_func_date_format::s_singleton;
1956
1957
Item*
1958
Create_func_date_format::create(THD *thd, Item *arg1, Item *arg2)
1959
{
1960
  return new (thd->mem_root) Item_func_date_format(arg1, arg2, 0);
1961
}
1962
1963
1964
Create_func_datediff Create_func_datediff::s_singleton;
1965
1966
Item*
1967
Create_func_datediff::create(THD *thd, Item *arg1, Item *arg2)
1968
{
1969
  Item *i1= new (thd->mem_root) Item_func_to_days(arg1);
1970
  Item *i2= new (thd->mem_root) Item_func_to_days(arg2);
1971
1972
  return new (thd->mem_root) Item_func_minus(i1, i2);
1973
}
1974
1975
1976
Create_func_dayname Create_func_dayname::s_singleton;
1977
1978
Item*
1979
Create_func_dayname::create(THD *thd, Item *arg1)
1980
{
1981
  return new (thd->mem_root) Item_func_dayname(arg1);
1982
}
1983
1984
1985
Create_func_dayofmonth Create_func_dayofmonth::s_singleton;
1986
1987
Item*
1988
Create_func_dayofmonth::create(THD *thd, Item *arg1)
1989
{
1990
  return new (thd->mem_root) Item_func_dayofmonth(arg1);
1991
}
1992
1993
1994
Create_func_dayofweek Create_func_dayofweek::s_singleton;
1995
1996
Item*
1997
Create_func_dayofweek::create(THD *thd, Item *arg1)
1998
{
1999
  return new (thd->mem_root) Item_func_weekday(arg1, 1);
2000
}
2001
2002
2003
Create_func_dayofyear Create_func_dayofyear::s_singleton;
2004
2005
Item*
2006
Create_func_dayofyear::create(THD *thd, Item *arg1)
2007
{
2008
  return new (thd->mem_root) Item_func_dayofyear(arg1);
2009
}
2010
2011
2012
Create_func_decode Create_func_decode::s_singleton;
2013
2014
Item*
2015
Create_func_decode::create(THD *thd, Item *arg1, Item *arg2)
2016
{
2017
  return new (thd->mem_root) Item_func_decode(arg1, arg2);
2018
}
2019
2020
2021
Create_func_degrees Create_func_degrees::s_singleton;
2022
2023
Item*
2024
Create_func_degrees::create(THD *thd, Item *arg1)
2025
{
2026
  return new (thd->mem_root) Item_func_units((char*) "degrees", arg1,
2027
                                             180/M_PI, 0.0);
2028
}
2029
2030
2031
Create_func_elt Create_func_elt::s_singleton;
2032
2033
Item*
2034
Create_func_elt::create_native(THD *thd, LEX_STRING name,
2035
                               List<Item> *item_list)
2036
{
2037
  int arg_count= 0;
2038
2039
  if (item_list != NULL)
2040
    arg_count= item_list->elements;
2041
2042
  if (arg_count < 2)
2043
  {
2044
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2045
    return NULL;
2046
  }
2047
2048
  return new (thd->mem_root) Item_func_elt(*item_list);
2049
}
2050
2051
2052
Create_func_encode Create_func_encode::s_singleton;
2053
2054
Item*
2055
Create_func_encode::create(THD *thd, Item *arg1, Item *arg2)
2056
{
2057
  return new (thd->mem_root) Item_func_encode(arg1, arg2);
2058
}
2059
2060
2061
Create_func_encrypt Create_func_encrypt::s_singleton;
2062
2063
Item*
2064
Create_func_encrypt::create_native(THD *thd, LEX_STRING name,
2065
                                   List<Item> *item_list)
2066
{
2067
  Item *func= NULL;
2068
  int arg_count= 0;
2069
2070
  if (item_list != NULL)
2071
    arg_count= item_list->elements;
2072
2073
  switch (arg_count) {
2074
  case 1:
2075
  {
2076
    Item *param_1= item_list->pop();
2077
    func= new (thd->mem_root) Item_func_encrypt(param_1);
2078
    break;
2079
  }
2080
  case 2:
2081
  {
2082
    Item *param_1= item_list->pop();
2083
    Item *param_2= item_list->pop();
2084
    func= new (thd->mem_root) Item_func_encrypt(param_1, param_2);
2085
    break;
2086
  }
2087
  default:
2088
  {
2089
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2090
    break;
2091
  }
2092
  }
2093
2094
  return func;
2095
}
2096
2097
2098
Create_func_exp Create_func_exp::s_singleton;
2099
2100
Item*
2101
Create_func_exp::create(THD *thd, Item *arg1)
2102
{
2103
  return new (thd->mem_root) Item_func_exp(arg1);
2104
}
2105
2106
2107
Create_func_export_set Create_func_export_set::s_singleton;
2108
2109
Item*
2110
Create_func_export_set::create_native(THD *thd, LEX_STRING name,
2111
                                      List<Item> *item_list)
2112
{
2113
  Item *func= NULL;
2114
  int arg_count= 0;
2115
2116
  if (item_list != NULL)
2117
    arg_count= item_list->elements;
2118
2119
  switch (arg_count) {
2120
  case 3:
2121
  {
2122
    Item *param_1= item_list->pop();
2123
    Item *param_2= item_list->pop();
2124
    Item *param_3= item_list->pop();
2125
    func= new (thd->mem_root) Item_func_export_set(param_1, param_2, param_3);
2126
    break;
2127
  }
2128
  case 4:
2129
  {
2130
    Item *param_1= item_list->pop();
2131
    Item *param_2= item_list->pop();
2132
    Item *param_3= item_list->pop();
2133
    Item *param_4= item_list->pop();
2134
    func= new (thd->mem_root) Item_func_export_set(param_1, param_2, param_3,
2135
                                                   param_4);
2136
    break;
2137
  }
2138
  case 5:
2139
  {
2140
    Item *param_1= item_list->pop();
2141
    Item *param_2= item_list->pop();
2142
    Item *param_3= item_list->pop();
2143
    Item *param_4= item_list->pop();
2144
    Item *param_5= item_list->pop();
2145
    func= new (thd->mem_root) Item_func_export_set(param_1, param_2, param_3,
2146
                                                   param_4, param_5);
2147
    break;
2148
  }
2149
  default:
2150
  {
2151
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2152
    break;
2153
  }
2154
  }
2155
2156
  return func;
2157
}
2158
2159
2160
Create_func_field Create_func_field::s_singleton;
2161
2162
Item*
2163
Create_func_field::create_native(THD *thd, LEX_STRING name,
2164
                                 List<Item> *item_list)
2165
{
2166
  int arg_count= 0;
2167
2168
  if (item_list != NULL)
2169
    arg_count= item_list->elements;
2170
2171
  if (arg_count < 2)
2172
  {
2173
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2174
    return NULL;
2175
  }
2176
2177
  return new (thd->mem_root) Item_func_field(*item_list);
2178
}
2179
2180
2181
Create_func_find_in_set Create_func_find_in_set::s_singleton;
2182
2183
Item*
2184
Create_func_find_in_set::create(THD *thd, Item *arg1, Item *arg2)
2185
{
2186
  return new (thd->mem_root) Item_func_find_in_set(arg1, arg2);
2187
}
2188
2189
2190
Create_func_floor Create_func_floor::s_singleton;
2191
2192
Item*
2193
Create_func_floor::create(THD *thd, Item *arg1)
2194
{
2195
  return new (thd->mem_root) Item_func_floor(arg1);
2196
}
2197
2198
2199
Create_func_format Create_func_format::s_singleton;
2200
2201
Item*
2202
Create_func_format::create(THD *thd, Item *arg1, Item *arg2)
2203
{
2204
  return new (thd->mem_root) Item_func_format(arg1, arg2);
2205
}
2206
2207
2208
Create_func_found_rows Create_func_found_rows::s_singleton;
2209
2210
Item*
2211
Create_func_found_rows::create(THD *thd)
2212
{
2213
  thd->lex->set_stmt_unsafe();
2214
  return new (thd->mem_root) Item_func_found_rows();
2215
}
2216
2217
2218
Create_func_from_days Create_func_from_days::s_singleton;
2219
2220
Item*
2221
Create_func_from_days::create(THD *thd, Item *arg1)
2222
{
2223
  return new (thd->mem_root) Item_func_from_days(arg1);
2224
}
2225
2226
2227
Create_func_from_unixtime Create_func_from_unixtime::s_singleton;
2228
2229
Item*
2230
Create_func_from_unixtime::create_native(THD *thd, LEX_STRING name,
2231
                                         List<Item> *item_list)
2232
{
2233
  Item *func= NULL;
2234
  int arg_count= 0;
2235
2236
  if (item_list != NULL)
2237
    arg_count= item_list->elements;
2238
2239
  switch (arg_count) {
2240
  case 1:
2241
  {
2242
    Item *param_1= item_list->pop();
2243
    func= new (thd->mem_root) Item_func_from_unixtime(param_1);
2244
    break;
2245
  }
2246
  case 2:
2247
  {
2248
    Item *param_1= item_list->pop();
2249
    Item *param_2= item_list->pop();
2250
    Item *ut= new (thd->mem_root) Item_func_from_unixtime(param_1);
2251
    func= new (thd->mem_root) Item_func_date_format(ut, param_2, 0);
2252
    break;
2253
  }
2254
  default:
2255
  {
2256
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2257
    break;
2258
  }
2259
  }
2260
2261
  return func;
2262
}
2263
2264
2265
Create_func_greatest Create_func_greatest::s_singleton;
2266
2267
Item*
2268
Create_func_greatest::create_native(THD *thd, LEX_STRING name,
2269
                                    List<Item> *item_list)
2270
{
2271
  int arg_count= 0;
2272
2273
  if (item_list != NULL)
2274
    arg_count= item_list->elements;
2275
2276
  if (arg_count < 2)
2277
  {
2278
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2279
    return NULL;
2280
  }
2281
2282
  return new (thd->mem_root) Item_func_max(*item_list);
2283
}
2284
2285
2286
Create_func_hex Create_func_hex::s_singleton;
2287
2288
Item*
2289
Create_func_hex::create(THD *thd, Item *arg1)
2290
{
2291
  return new (thd->mem_root) Item_func_hex(arg1);
2292
}
2293
2294
2295
Create_func_ifnull Create_func_ifnull::s_singleton;
2296
2297
Item*
2298
Create_func_ifnull::create(THD *thd, Item *arg1, Item *arg2)
2299
{
2300
  return new (thd->mem_root) Item_func_ifnull(arg1, arg2);
2301
}
2302
2303
2304
Create_func_instr Create_func_instr::s_singleton;
2305
2306
Item*
2307
Create_func_instr::create(THD *thd, Item *arg1, Item *arg2)
2308
{
2309
  return new (thd->mem_root) Item_func_locate(arg1, arg2);
2310
}
2311
2312
2313
Create_func_isnull Create_func_isnull::s_singleton;
2314
2315
Item*
2316
Create_func_isnull::create(THD *thd, Item *arg1)
2317
{
2318
  return new (thd->mem_root) Item_func_isnull(arg1);
2319
}
2320
2321
2322
Create_func_last_day Create_func_last_day::s_singleton;
2323
2324
Item*
2325
Create_func_last_day::create(THD *thd, Item *arg1)
2326
{
2327
  return new (thd->mem_root) Item_func_last_day(arg1);
2328
}
2329
2330
2331
Create_func_last_insert_id Create_func_last_insert_id::s_singleton;
2332
2333
Item*
2334
Create_func_last_insert_id::create_native(THD *thd, LEX_STRING name,
2335
                                          List<Item> *item_list)
2336
{
2337
  Item *func= NULL;
2338
  int arg_count= 0;
2339
2340
  if (item_list != NULL)
2341
    arg_count= item_list->elements;
2342
2343
  switch (arg_count) {
2344
  case 0:
2345
  {
2346
    func= new (thd->mem_root) Item_func_last_insert_id();
2347
    break;
2348
  }
2349
  case 1:
2350
  {
2351
    Item *param_1= item_list->pop();
2352
    func= new (thd->mem_root) Item_func_last_insert_id(param_1);
2353
    break;
2354
  }
2355
  default:
2356
  {
2357
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2358
    break;
2359
  }
2360
  }
2361
2362
  return func;
2363
}
2364
2365
2366
Create_func_lcase Create_func_lcase::s_singleton;
2367
2368
Item*
2369
Create_func_lcase::create(THD *thd, Item *arg1)
2370
{
2371
  return new (thd->mem_root) Item_func_lcase(arg1);
2372
}
2373
2374
2375
Create_func_least Create_func_least::s_singleton;
2376
2377
Item*
2378
Create_func_least::create_native(THD *thd, LEX_STRING name,
2379
                                 List<Item> *item_list)
2380
{
2381
  int arg_count= 0;
2382
2383
  if (item_list != NULL)
2384
    arg_count= item_list->elements;
2385
2386
  if (arg_count < 2)
2387
  {
2388
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2389
    return NULL;
2390
  }
2391
2392
  return new (thd->mem_root) Item_func_min(*item_list);
2393
}
2394
2395
2396
Create_func_length Create_func_length::s_singleton;
2397
2398
Item*
2399
Create_func_length::create(THD *thd, Item *arg1)
2400
{
2401
  return new (thd->mem_root) Item_func_length(arg1);
2402
}
2403
2404
2405
Create_func_ln Create_func_ln::s_singleton;
2406
2407
Item*
2408
Create_func_ln::create(THD *thd, Item *arg1)
2409
{
2410
  return new (thd->mem_root) Item_func_ln(arg1);
2411
}
2412
2413
2414
Create_func_load_file Create_func_load_file::s_singleton;
2415
2416
Item*
2417
Create_func_load_file::create(THD *thd, Item *arg1)
2418
{
2419
  return new (thd->mem_root) Item_load_file(arg1);
2420
}
2421
2422
2423
Create_func_locate Create_func_locate::s_singleton;
2424
2425
Item*
2426
Create_func_locate::create_native(THD *thd, LEX_STRING name,
2427
                                  List<Item> *item_list)
2428
{
2429
  Item *func= NULL;
2430
  int arg_count= 0;
2431
2432
  if (item_list != NULL)
2433
    arg_count= item_list->elements;
2434
2435
  switch (arg_count) {
2436
  case 2:
2437
  {
2438
    Item *param_1= item_list->pop();
2439
    Item *param_2= item_list->pop();
2440
    /* Yes, parameters in that order : 2, 1 */
2441
    func= new (thd->mem_root) Item_func_locate(param_2, param_1);
2442
    break;
2443
  }
2444
  case 3:
2445
  {
2446
    Item *param_1= item_list->pop();
2447
    Item *param_2= item_list->pop();
2448
    Item *param_3= item_list->pop();
2449
    /* Yes, parameters in that order : 2, 1, 3 */
2450
    func= new (thd->mem_root) Item_func_locate(param_2, param_1, param_3);
2451
    break;
2452
  }
2453
  default:
2454
  {
2455
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2456
    break;
2457
  }
2458
  }
2459
2460
  return func;
2461
}
2462
2463
2464
Create_func_log Create_func_log::s_singleton;
2465
2466
Item*
2467
Create_func_log::create_native(THD *thd, LEX_STRING name,
2468
                               List<Item> *item_list)
2469
{
2470
  Item *func= NULL;
2471
  int arg_count= 0;
2472
2473
  if (item_list != NULL)
2474
    arg_count= item_list->elements;
2475
2476
  switch (arg_count) {
2477
  case 1:
2478
  {
2479
    Item *param_1= item_list->pop();
2480
    func= new (thd->mem_root) Item_func_log(param_1);
2481
    break;
2482
  }
2483
  case 2:
2484
  {
2485
    Item *param_1= item_list->pop();
2486
    Item *param_2= item_list->pop();
2487
    func= new (thd->mem_root) Item_func_log(param_1, param_2);
2488
    break;
2489
  }
2490
  default:
2491
  {
2492
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2493
    break;
2494
  }
2495
  }
2496
2497
  return func;
2498
}
2499
2500
2501
Create_func_log10 Create_func_log10::s_singleton;
2502
2503
Item*
2504
Create_func_log10::create(THD *thd, Item *arg1)
2505
{
2506
  return new (thd->mem_root) Item_func_log10(arg1);
2507
}
2508
2509
2510
Create_func_log2 Create_func_log2::s_singleton;
2511
2512
Item*
2513
Create_func_log2::create(THD *thd, Item *arg1)
2514
{
2515
  return new (thd->mem_root) Item_func_log2(arg1);
2516
}
2517
2518
2519
Create_func_lpad Create_func_lpad::s_singleton;
2520
2521
Item*
2522
Create_func_lpad::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
2523
{
2524
  return new (thd->mem_root) Item_func_lpad(arg1, arg2, arg3);
2525
}
2526
2527
2528
Create_func_ltrim Create_func_ltrim::s_singleton;
2529
2530
Item*
2531
Create_func_ltrim::create(THD *thd, Item *arg1)
2532
{
2533
  return new (thd->mem_root) Item_func_ltrim(arg1);
2534
}
2535
2536
2537
Create_func_makedate Create_func_makedate::s_singleton;
2538
2539
Item*
2540
Create_func_makedate::create(THD *thd, Item *arg1, Item *arg2)
2541
{
2542
  return new (thd->mem_root) Item_func_makedate(arg1, arg2);
2543
}
2544
2545
2546
Create_func_maketime Create_func_maketime::s_singleton;
2547
2548
Item*
2549
Create_func_maketime::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
2550
{
2551
  return new (thd->mem_root) Item_func_maketime(arg1, arg2, arg3);
2552
}
2553
2554
2555
Create_func_make_set Create_func_make_set::s_singleton;
2556
2557
Item*
2558
Create_func_make_set::create_native(THD *thd, LEX_STRING name,
2559
                                    List<Item> *item_list)
2560
{
2561
  int arg_count= 0;
2562
2563
  if (item_list != NULL)
2564
    arg_count= item_list->elements;
2565
2566
  if (arg_count < 2)
2567
  {
2568
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2569
    return NULL;
2570
  }
2571
2572
  Item *param_1= item_list->pop();
2573
  return new (thd->mem_root) Item_func_make_set(param_1, *item_list);
2574
}
2575
2576
2577
Create_func_master_pos_wait Create_func_master_pos_wait::s_singleton;
2578
2579
Item*
2580
Create_func_master_pos_wait::create_native(THD *thd, LEX_STRING name,
2581
                                           List<Item> *item_list)
2582
2583
{
2584
  Item *func= NULL;
2585
  int arg_count= 0;
2586
2587
  if (item_list != NULL)
2588
    arg_count= item_list->elements;
2589
2590
  switch (arg_count) {
2591
  case 2:
2592
  {
2593
    Item *param_1= item_list->pop();
2594
    Item *param_2= item_list->pop();
2595
    func= new (thd->mem_root) Item_master_pos_wait(param_1, param_2);
2596
    break;
2597
  }
2598
  case 3:
2599
  {
2600
    Item *param_1= item_list->pop();
2601
    Item *param_2= item_list->pop();
2602
    Item *param_3= item_list->pop();
2603
    func= new (thd->mem_root) Item_master_pos_wait(param_1, param_2, param_3);
2604
    break;
2605
  }
2606
  default:
2607
  {
2608
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2609
    break;
2610
  }
2611
  }
2612
2613
  return func;
2614
}
2615
2616
2617
Create_func_md5 Create_func_md5::s_singleton;
2618
2619
Item*
2620
Create_func_md5::create(THD *thd, Item *arg1)
2621
{
2622
  return new (thd->mem_root) Item_func_md5(arg1);
2623
}
2624
2625
2626
Create_func_monthname Create_func_monthname::s_singleton;
2627
2628
Item*
2629
Create_func_monthname::create(THD *thd, Item *arg1)
2630
{
2631
  return new (thd->mem_root) Item_func_monthname(arg1);
2632
}
2633
2634
2635
Create_func_nullif Create_func_nullif::s_singleton;
2636
2637
Item*
2638
Create_func_nullif::create(THD *thd, Item *arg1, Item *arg2)
2639
{
2640
  return new (thd->mem_root) Item_func_nullif(arg1, arg2);
2641
}
2642
2643
2644
Create_func_oct Create_func_oct::s_singleton;
2645
2646
Item*
2647
Create_func_oct::create(THD *thd, Item *arg1)
2648
{
2649
  Item *i10= new (thd->mem_root) Item_int((int32) 10,2);
2650
  Item *i8= new (thd->mem_root) Item_int((int32) 8,1);
2651
  return new (thd->mem_root) Item_func_conv(arg1, i10, i8);
2652
}
2653
2654
2655
Create_func_ord Create_func_ord::s_singleton;
2656
2657
Item*
2658
Create_func_ord::create(THD *thd, Item *arg1)
2659
{
2660
  return new (thd->mem_root) Item_func_ord(arg1);
2661
}
2662
2663
2664
Create_func_period_add Create_func_period_add::s_singleton;
2665
2666
Item*
2667
Create_func_period_add::create(THD *thd, Item *arg1, Item *arg2)
2668
{
2669
  return new (thd->mem_root) Item_func_period_add(arg1, arg2);
2670
}
2671
2672
2673
Create_func_period_diff Create_func_period_diff::s_singleton;
2674
2675
Item*
2676
Create_func_period_diff::create(THD *thd, Item *arg1, Item *arg2)
2677
{
2678
  return new (thd->mem_root) Item_func_period_diff(arg1, arg2);
2679
}
2680
2681
2682
Create_func_pi Create_func_pi::s_singleton;
2683
2684
Item*
2685
Create_func_pi::create(THD *thd)
2686
{
2687
  return new (thd->mem_root) Item_static_float_func("pi()", M_PI, 6, 8);
2688
}
2689
2690
2691
Create_func_pow Create_func_pow::s_singleton;
2692
2693
Item*
2694
Create_func_pow::create(THD *thd, Item *arg1, Item *arg2)
2695
{
2696
  return new (thd->mem_root) Item_func_pow(arg1, arg2);
2697
}
2698
2699
2700
Create_func_quote Create_func_quote::s_singleton;
2701
2702
Item*
2703
Create_func_quote::create(THD *thd, Item *arg1)
2704
{
2705
  return new (thd->mem_root) Item_func_quote(arg1);
2706
}
2707
2708
2709
Create_func_radians Create_func_radians::s_singleton;
2710
2711
Item*
2712
Create_func_radians::create(THD *thd, Item *arg1)
2713
{
2714
  return new (thd->mem_root) Item_func_units((char*) "radians", arg1,
2715
                                             M_PI/180, 0.0);
2716
}
2717
2718
2719
Create_func_rand Create_func_rand::s_singleton;
2720
2721
Item*
2722
Create_func_rand::create_native(THD *thd, LEX_STRING name,
2723
                                List<Item> *item_list)
2724
{
2725
  Item *func= NULL;
2726
  int arg_count= 0;
2727
2728
  if (item_list != NULL)
2729
    arg_count= item_list->elements;
2730
2731
  switch (arg_count) {
2732
  case 0:
2733
  {
2734
    func= new (thd->mem_root) Item_func_rand();
2735
    break;
2736
  }
2737
  case 1:
2738
  {
2739
    Item *param_1= item_list->pop();
2740
    func= new (thd->mem_root) Item_func_rand(param_1);
2741
    break;
2742
  }
2743
  default:
2744
  {
2745
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2746
    break;
2747
  }
2748
  }
2749
2750
  return func;
2751
}
2752
2753
2754
Create_func_round Create_func_round::s_singleton;
2755
2756
Item*
2757
Create_func_round::create_native(THD *thd, LEX_STRING name,
2758
                                 List<Item> *item_list)
2759
{
2760
  Item *func= NULL;
2761
  int arg_count= 0;
2762
2763
  if (item_list != NULL)
2764
    arg_count= item_list->elements;
2765
2766
  switch (arg_count) {
2767
  case 1:
2768
  {
2769
    Item *param_1= item_list->pop();
2770
    Item *i0 = new (thd->mem_root) Item_int((char*)"0", 0, 1);
2771
    func= new (thd->mem_root) Item_func_round(param_1, i0, 0);
2772
    break;
2773
  }
2774
  case 2:
2775
  {
2776
    Item *param_1= item_list->pop();
2777
    Item *param_2= item_list->pop();
2778
    func= new (thd->mem_root) Item_func_round(param_1, param_2, 0);
2779
    break;
2780
  }
2781
  default:
2782
  {
2783
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2784
    break;
2785
  }
2786
  }
2787
2788
  return func;
2789
}
2790
2791
2792
Create_func_row_count Create_func_row_count::s_singleton;
2793
2794
Item*
2795
Create_func_row_count::create(THD *thd)
2796
{
2797
  thd->lex->set_stmt_unsafe();
2798
  return new (thd->mem_root) Item_func_row_count();
2799
}
2800
2801
2802
Create_func_rpad Create_func_rpad::s_singleton;
2803
2804
Item*
2805
Create_func_rpad::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
2806
{
2807
  return new (thd->mem_root) Item_func_rpad(arg1, arg2, arg3);
2808
}
2809
2810
2811
Create_func_rtrim Create_func_rtrim::s_singleton;
2812
2813
Item*
2814
Create_func_rtrim::create(THD *thd, Item *arg1)
2815
{
2816
  return new (thd->mem_root) Item_func_rtrim(arg1);
2817
}
2818
2819
2820
Create_func_sec_to_time Create_func_sec_to_time::s_singleton;
2821
2822
Item*
2823
Create_func_sec_to_time::create(THD *thd, Item *arg1)
2824
{
2825
  return new (thd->mem_root) Item_func_sec_to_time(arg1);
2826
}
2827
2828
2829
Create_func_sign Create_func_sign::s_singleton;
2830
2831
Item*
2832
Create_func_sign::create(THD *thd, Item *arg1)
2833
{
2834
  return new (thd->mem_root) Item_func_sign(arg1);
2835
}
2836
2837
2838
Create_func_sin Create_func_sin::s_singleton;
2839
2840
Item*
2841
Create_func_sin::create(THD *thd, Item *arg1)
2842
{
2843
  return new (thd->mem_root) Item_func_sin(arg1);
2844
}
2845
2846
2847
Create_func_space Create_func_space::s_singleton;
2848
2849
Item*
2850
Create_func_space::create(THD *thd, Item *arg1)
2851
{
2852
  /**
2853
    TODO: Fix Bug#23637
2854
    The parsed item tree should not depend on
2855
    <code>thd->variables.collation_connection</code>.
2856
  */
2857
  CHARSET_INFO *cs= thd->variables.collation_connection;
2858
  Item *sp;
2859
2860
  if (cs->mbminlen > 1)
2861
  {
2862
    uint dummy_errors;
2863
    sp= new (thd->mem_root) Item_string("", 0, cs, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
2864
    sp->str_value.copy(" ", 1, &my_charset_latin1, cs, &dummy_errors);
2865
  }
2866
  else
2867
  {
2868
    sp= new (thd->mem_root) Item_string(" ", 1, cs, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
2869
  }
2870
2871
  return new (thd->mem_root) Item_func_repeat(sp, arg1);
2872
}
2873
2874
2875
Create_func_sqrt Create_func_sqrt::s_singleton;
2876
2877
Item*
2878
Create_func_sqrt::create(THD *thd, Item *arg1)
2879
{
2880
  return new (thd->mem_root) Item_func_sqrt(arg1);
2881
}
2882
2883
2884
Create_func_str_to_date Create_func_str_to_date::s_singleton;
2885
2886
Item*
2887
Create_func_str_to_date::create(THD *thd, Item *arg1, Item *arg2)
2888
{
2889
  return new (thd->mem_root) Item_func_str_to_date(arg1, arg2);
2890
}
2891
2892
2893
Create_func_strcmp Create_func_strcmp::s_singleton;
2894
2895
Item*
2896
Create_func_strcmp::create(THD *thd, Item *arg1, Item *arg2)
2897
{
2898
  return new (thd->mem_root) Item_func_strcmp(arg1, arg2);
2899
}
2900
2901
2902
Create_func_substr_index Create_func_substr_index::s_singleton;
2903
2904
Item*
2905
Create_func_substr_index::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
2906
{
2907
  return new (thd->mem_root) Item_func_substr_index(arg1, arg2, arg3);
2908
}
2909
2910
2911
Create_func_subtime Create_func_subtime::s_singleton;
2912
2913
Item*
2914
Create_func_subtime::create(THD *thd, Item *arg1, Item *arg2)
2915
{
2916
  return new (thd->mem_root) Item_func_add_time(arg1, arg2, 0, 1);
2917
}
2918
2919
2920
Create_func_tan Create_func_tan::s_singleton;
2921
2922
Item*
2923
Create_func_tan::create(THD *thd, Item *arg1)
2924
{
2925
  return new (thd->mem_root) Item_func_tan(arg1);
2926
}
2927
2928
2929
Create_func_time_format Create_func_time_format::s_singleton;
2930
2931
Item*
2932
Create_func_time_format::create(THD *thd, Item *arg1, Item *arg2)
2933
{
2934
  return new (thd->mem_root) Item_func_date_format(arg1, arg2, 1);
2935
}
2936
2937
2938
Create_func_time_to_sec Create_func_time_to_sec::s_singleton;
2939
2940
Item*
2941
Create_func_time_to_sec::create(THD *thd, Item *arg1)
2942
{
2943
  return new (thd->mem_root) Item_func_time_to_sec(arg1);
2944
}
2945
2946
2947
Create_func_timediff Create_func_timediff::s_singleton;
2948
2949
Item*
2950
Create_func_timediff::create(THD *thd, Item *arg1, Item *arg2)
2951
{
2952
  return new (thd->mem_root) Item_func_timediff(arg1, arg2);
2953
}
2954
2955
2956
Create_func_to_days Create_func_to_days::s_singleton;
2957
2958
Item*
2959
Create_func_to_days::create(THD *thd, Item *arg1)
2960
{
2961
  return new (thd->mem_root) Item_func_to_days(arg1);
2962
}
2963
2964
2965
Create_func_ucase Create_func_ucase::s_singleton;
2966
2967
Item*
2968
Create_func_ucase::create(THD *thd, Item *arg1)
2969
{
2970
  return new (thd->mem_root) Item_func_ucase(arg1);
2971
}
2972
2973
2974
Create_func_unhex Create_func_unhex::s_singleton;
2975
2976
Item*
2977
Create_func_unhex::create(THD *thd, Item *arg1)
2978
{
2979
  return new (thd->mem_root) Item_func_unhex(arg1);
2980
}
2981
2982
2983
Create_func_unix_timestamp Create_func_unix_timestamp::s_singleton;
2984
2985
Item*
2986
Create_func_unix_timestamp::create_native(THD *thd, LEX_STRING name,
2987
                                          List<Item> *item_list)
2988
{
2989
  Item *func= NULL;
2990
  int arg_count= 0;
2991
2992
  if (item_list != NULL)
2993
    arg_count= item_list->elements;
2994
2995
  switch (arg_count) {
2996
  case 0:
2997
  {
2998
    func= new (thd->mem_root) Item_func_unix_timestamp();
2999
    break;
3000
  }
3001
  case 1:
3002
  {
3003
    Item *param_1= item_list->pop();
3004
    func= new (thd->mem_root) Item_func_unix_timestamp(param_1);
3005
    break;
3006
  }
3007
  default:
3008
  {
3009
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
3010
    break;
3011
  }
3012
  }
3013
3014
  return func;
3015
}
3016
3017
3018
Create_func_uuid Create_func_uuid::s_singleton;
3019
3020
Item*
3021
Create_func_uuid::create(THD *thd)
3022
{
3023
  thd->lex->set_stmt_unsafe();
3024
  return new (thd->mem_root) Item_func_uuid();
3025
}
3026
3027
3028
Create_func_version Create_func_version::s_singleton;
3029
3030
Item*
3031
Create_func_version::create(THD *thd)
3032
{
3033
  return new (thd->mem_root) Item_static_string_func("version()",
3034
                                                     server_version,
3035
                                                     (uint) strlen(server_version),
3036
                                                     system_charset_info,
3037
                                                     DERIVATION_SYSCONST);
3038
}
3039
3040
3041
Create_func_weekday Create_func_weekday::s_singleton;
3042
3043
Item*
3044
Create_func_weekday::create(THD *thd, Item *arg1)
3045
{
3046
  return new (thd->mem_root) Item_func_weekday(arg1, 0);
3047
}
3048
3049
3050
Create_func_weekofyear Create_func_weekofyear::s_singleton;
3051
3052
Item*
3053
Create_func_weekofyear::create(THD *thd, Item *arg1)
3054
{
3055
  Item *i1= new (thd->mem_root) Item_int((char*) "0", 3, 1);
3056
  return new (thd->mem_root) Item_func_week(arg1, i1);
3057
}
3058
3059
3060
Create_func_year_week Create_func_year_week::s_singleton;
3061
3062
Item*
3063
Create_func_year_week::create_native(THD *thd, LEX_STRING name,
3064
                                     List<Item> *item_list)
3065
{
3066
  Item *func= NULL;
3067
  int arg_count= 0;
3068
3069
  if (item_list != NULL)
3070
    arg_count= item_list->elements;
3071
3072
  switch (arg_count) {
3073
  case 1:
3074
  {
3075
    Item *param_1= item_list->pop();
3076
    Item *i0= new (thd->mem_root) Item_int((char*) "0", 0, 1);
3077
    func= new (thd->mem_root) Item_func_yearweek(param_1, i0);
3078
    break;
3079
  }
3080
  case 2:
3081
  {
3082
    Item *param_1= item_list->pop();
3083
    Item *param_2= item_list->pop();
3084
    func= new (thd->mem_root) Item_func_yearweek(param_1, param_2);
3085
    break;
3086
  }
3087
  default:
3088
  {
3089
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
3090
    break;
3091
  }
3092
  }
3093
3094
  return func;
3095
}
3096
3097
3098
struct Native_func_registry
3099
{
3100
  LEX_STRING name;
3101
  Create_func *builder;
3102
};
3103
3104
#define BUILDER(F) & F::s_singleton
3105
3106
/*
3107
  MySQL native functions.
3108
  MAINTAINER:
3109
  - Keep sorted for human lookup. At runtime, a hash table is used.
3110
  - keep 1 line per entry, it makes grep | sort easier
3111
*/
3112
3113
static Native_func_registry func_array[] =
3114
{
3115
  { { C_STRING_WITH_LEN("ABS") }, BUILDER(Create_func_abs)},
3116
  { { C_STRING_WITH_LEN("ACOS") }, BUILDER(Create_func_acos)},
3117
  { { C_STRING_WITH_LEN("ADDTIME") }, BUILDER(Create_func_addtime)},
3118
  { { C_STRING_WITH_LEN("ASIN") }, BUILDER(Create_func_asin)},
3119
  { { C_STRING_WITH_LEN("ATAN") }, BUILDER(Create_func_atan)},
3120
  { { C_STRING_WITH_LEN("ATAN2") }, BUILDER(Create_func_atan)},
3121
  { { C_STRING_WITH_LEN("BENCHMARK") }, BUILDER(Create_func_benchmark)},
3122
  { { C_STRING_WITH_LEN("BIN") }, BUILDER(Create_func_bin)},
3123
  { { C_STRING_WITH_LEN("BIT_COUNT") }, BUILDER(Create_func_bit_count)},
3124
  { { C_STRING_WITH_LEN("BIT_LENGTH") }, BUILDER(Create_func_bit_length)},
3125
  { { C_STRING_WITH_LEN("CEIL") }, BUILDER(Create_func_ceiling)},
3126
  { { C_STRING_WITH_LEN("CEILING") }, BUILDER(Create_func_ceiling)},
3127
  { { C_STRING_WITH_LEN("CHARACTER_LENGTH") }, BUILDER(Create_func_char_length)},
3128
  { { C_STRING_WITH_LEN("CHAR_LENGTH") }, BUILDER(Create_func_char_length)},
3129
  { { C_STRING_WITH_LEN("COERCIBILITY") }, BUILDER(Create_func_coercibility)},
3130
  { { C_STRING_WITH_LEN("CONCAT") }, BUILDER(Create_func_concat)},
3131
  { { C_STRING_WITH_LEN("CONCAT_WS") }, BUILDER(Create_func_concat_ws)},
3132
  { { C_STRING_WITH_LEN("CONNECTION_ID") }, BUILDER(Create_func_connection_id)},
3133
  { { C_STRING_WITH_LEN("CONV") }, BUILDER(Create_func_conv)},
3134
  { { C_STRING_WITH_LEN("COS") }, BUILDER(Create_func_cos)},
3135
  { { C_STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)},
3136
  { { C_STRING_WITH_LEN("CRC32") }, BUILDER(Create_func_crc32)},
3137
  { { C_STRING_WITH_LEN("DATEDIFF") }, BUILDER(Create_func_datediff)},
3138
  { { C_STRING_WITH_LEN("DATE_FORMAT") }, BUILDER(Create_func_date_format)},
3139
  { { C_STRING_WITH_LEN("DAYNAME") }, BUILDER(Create_func_dayname)},
3140
  { { C_STRING_WITH_LEN("DAYOFMONTH") }, BUILDER(Create_func_dayofmonth)},
3141
  { { C_STRING_WITH_LEN("DAYOFWEEK") }, BUILDER(Create_func_dayofweek)},
3142
  { { C_STRING_WITH_LEN("DAYOFYEAR") }, BUILDER(Create_func_dayofyear)},
3143
  { { C_STRING_WITH_LEN("DECODE") }, BUILDER(Create_func_decode)},
3144
  { { C_STRING_WITH_LEN("DEGREES") }, BUILDER(Create_func_degrees)},
3145
  { { C_STRING_WITH_LEN("ELT") }, BUILDER(Create_func_elt)},
3146
  { { C_STRING_WITH_LEN("ENCODE") }, BUILDER(Create_func_encode)},
3147
  { { C_STRING_WITH_LEN("ENCRYPT") }, BUILDER(Create_func_encrypt)},
3148
  { { C_STRING_WITH_LEN("EXP") }, BUILDER(Create_func_exp)},
3149
  { { C_STRING_WITH_LEN("EXPORT_SET") }, BUILDER(Create_func_export_set)},
3150
  { { C_STRING_WITH_LEN("FIELD") }, BUILDER(Create_func_field)},
3151
  { { C_STRING_WITH_LEN("FIND_IN_SET") }, BUILDER(Create_func_find_in_set)},
3152
  { { C_STRING_WITH_LEN("FLOOR") }, BUILDER(Create_func_floor)},
3153
  { { C_STRING_WITH_LEN("FORMAT") }, BUILDER(Create_func_format)},
3154
  { { C_STRING_WITH_LEN("FOUND_ROWS") }, BUILDER(Create_func_found_rows)},
3155
  { { C_STRING_WITH_LEN("FROM_DAYS") }, BUILDER(Create_func_from_days)},
3156
  { { C_STRING_WITH_LEN("FROM_UNIXTIME") }, BUILDER(Create_func_from_unixtime)},
3157
  { { C_STRING_WITH_LEN("GREATEST") }, BUILDER(Create_func_greatest)},
3158
  { { C_STRING_WITH_LEN("HEX") }, BUILDER(Create_func_hex)},
3159
  { { C_STRING_WITH_LEN("IFNULL") }, BUILDER(Create_func_ifnull)},
3160
  { { C_STRING_WITH_LEN("INSTR") }, BUILDER(Create_func_instr)},
3161
  { { C_STRING_WITH_LEN("ISNULL") }, BUILDER(Create_func_isnull)},
3162
  { { C_STRING_WITH_LEN("LAST_DAY") }, BUILDER(Create_func_last_day)},
3163
  { { C_STRING_WITH_LEN("LAST_INSERT_ID") }, BUILDER(Create_func_last_insert_id)},
3164
  { { C_STRING_WITH_LEN("LCASE") }, BUILDER(Create_func_lcase)},
3165
  { { C_STRING_WITH_LEN("LEAST") }, BUILDER(Create_func_least)},
3166
  { { C_STRING_WITH_LEN("LENGTH") }, BUILDER(Create_func_length)},
3167
  { { C_STRING_WITH_LEN("LN") }, BUILDER(Create_func_ln)},
3168
  { { C_STRING_WITH_LEN("LOAD_FILE") }, BUILDER(Create_func_load_file)},
3169
  { { C_STRING_WITH_LEN("LOCATE") }, BUILDER(Create_func_locate)},
3170
  { { C_STRING_WITH_LEN("LOG") }, BUILDER(Create_func_log)},
3171
  { { C_STRING_WITH_LEN("LOG10") }, BUILDER(Create_func_log10)},
3172
  { { C_STRING_WITH_LEN("LOG2") }, BUILDER(Create_func_log2)},
3173
  { { C_STRING_WITH_LEN("LOWER") }, BUILDER(Create_func_lcase)},
3174
  { { C_STRING_WITH_LEN("LPAD") }, BUILDER(Create_func_lpad)},
3175
  { { C_STRING_WITH_LEN("LTRIM") }, BUILDER(Create_func_ltrim)},
3176
  { { C_STRING_WITH_LEN("MAKEDATE") }, BUILDER(Create_func_makedate)},
3177
  { { C_STRING_WITH_LEN("MAKETIME") }, BUILDER(Create_func_maketime)},
3178
  { { C_STRING_WITH_LEN("MAKE_SET") }, BUILDER(Create_func_make_set)},
3179
  { { C_STRING_WITH_LEN("MASTER_POS_WAIT") }, BUILDER(Create_func_master_pos_wait)},
3180
  { { C_STRING_WITH_LEN("MD5") }, BUILDER(Create_func_md5)},
3181
  { { C_STRING_WITH_LEN("MONTHNAME") }, BUILDER(Create_func_monthname)},
3182
  { { C_STRING_WITH_LEN("NULLIF") }, BUILDER(Create_func_nullif)},
3183
  { { C_STRING_WITH_LEN("OCT") }, BUILDER(Create_func_oct)},
3184
  { { C_STRING_WITH_LEN("OCTET_LENGTH") }, BUILDER(Create_func_length)},
3185
  { { C_STRING_WITH_LEN("ORD") }, BUILDER(Create_func_ord)},
3186
  { { C_STRING_WITH_LEN("PERIOD_ADD") }, BUILDER(Create_func_period_add)},
3187
  { { C_STRING_WITH_LEN("PERIOD_DIFF") }, BUILDER(Create_func_period_diff)},
3188
  { { C_STRING_WITH_LEN("PI") }, BUILDER(Create_func_pi)},
3189
  { { C_STRING_WITH_LEN("POW") }, BUILDER(Create_func_pow)},
3190
  { { C_STRING_WITH_LEN("POWER") }, BUILDER(Create_func_pow)},
3191
  { { C_STRING_WITH_LEN("QUOTE") }, BUILDER(Create_func_quote)},
3192
  { { C_STRING_WITH_LEN("RADIANS") }, BUILDER(Create_func_radians)},
3193
  { { C_STRING_WITH_LEN("RAND") }, BUILDER(Create_func_rand)},
3194
  { { C_STRING_WITH_LEN("ROUND") }, BUILDER(Create_func_round)},
3195
  { { C_STRING_WITH_LEN("ROW_COUNT") }, BUILDER(Create_func_row_count)},
3196
  { { C_STRING_WITH_LEN("RPAD") }, BUILDER(Create_func_rpad)},
3197
  { { C_STRING_WITH_LEN("RTRIM") }, BUILDER(Create_func_rtrim)},
3198
  { { C_STRING_WITH_LEN("SEC_TO_TIME") }, BUILDER(Create_func_sec_to_time)},
3199
  { { C_STRING_WITH_LEN("SIGN") }, BUILDER(Create_func_sign)},
3200
  { { C_STRING_WITH_LEN("SIN") }, BUILDER(Create_func_sin)},
3201
  { { C_STRING_WITH_LEN("SPACE") }, BUILDER(Create_func_space)},
3202
  { { C_STRING_WITH_LEN("SQRT") }, BUILDER(Create_func_sqrt)},
3203
  { { C_STRING_WITH_LEN("STRCMP") }, BUILDER(Create_func_strcmp)},
3204
  { { C_STRING_WITH_LEN("STR_TO_DATE") }, BUILDER(Create_func_str_to_date)},
3205
  { { C_STRING_WITH_LEN("SUBSTRING_INDEX") }, BUILDER(Create_func_substr_index)},
3206
  { { C_STRING_WITH_LEN("SUBTIME") }, BUILDER(Create_func_subtime)},
3207
  { { C_STRING_WITH_LEN("TAN") }, BUILDER(Create_func_tan)},
3208
  { { C_STRING_WITH_LEN("TIMEDIFF") }, BUILDER(Create_func_timediff)},
3209
  { { C_STRING_WITH_LEN("TIME_FORMAT") }, BUILDER(Create_func_time_format)},
3210
  { { C_STRING_WITH_LEN("TIME_TO_SEC") }, BUILDER(Create_func_time_to_sec)},
3211
  { { C_STRING_WITH_LEN("TO_DAYS") }, BUILDER(Create_func_to_days)},
3212
  { { C_STRING_WITH_LEN("UCASE") }, BUILDER(Create_func_ucase)},
3213
  { { C_STRING_WITH_LEN("UNHEX") }, BUILDER(Create_func_unhex)},
3214
  { { C_STRING_WITH_LEN("UNIX_TIMESTAMP") }, BUILDER(Create_func_unix_timestamp)},
3215
  { { C_STRING_WITH_LEN("UPPER") }, BUILDER(Create_func_ucase)},
3216
  { { C_STRING_WITH_LEN("UUID") }, BUILDER(Create_func_uuid)},
3217
  { { C_STRING_WITH_LEN("VERSION") }, BUILDER(Create_func_version)},
3218
  { { C_STRING_WITH_LEN("WEEKDAY") }, BUILDER(Create_func_weekday)},
3219
  { { C_STRING_WITH_LEN("WEEKOFYEAR") }, BUILDER(Create_func_weekofyear)},
3220
  { { C_STRING_WITH_LEN("YEARWEEK") }, BUILDER(Create_func_year_week)},
3221
3222
  { {0, 0}, NULL}
3223
};
3224
3225
static HASH native_functions_hash;
3226
3227
extern "C" uchar*
3228
get_native_fct_hash_key(const uchar *buff, size_t *length,
3229
                        my_bool /* unused */)
3230
{
3231
  Native_func_registry *func= (Native_func_registry*) buff;
3232
  *length= func->name.length;
3233
  return (uchar*) func->name.str;
3234
}
3235
3236
/*
3237
  Load the hash table for native functions.
3238
  Note: this code is not thread safe, and is intended to be used at server
3239
  startup only (before going multi-threaded)
3240
*/
3241
3242
int item_create_init()
3243
{
3244
  Native_func_registry *func;
3245
3246
  if (hash_init(& native_functions_hash,
3247
                system_charset_info,
3248
                array_elements(func_array),
3249
                0,
3250
                0,
3251
                (hash_get_key) get_native_fct_hash_key,
3252
                NULL,                          /* Nothing to free */
3253
                MYF(0)))
51.1.19 by Jay Pipes
Removed/replace DBUG symbols
3254
    return(1);
1 by brian
clean slate
3255
3256
  for (func= func_array; func->builder != NULL; func++)
3257
  {
3258
    if (my_hash_insert(& native_functions_hash, (uchar*) func))
51.1.19 by Jay Pipes
Removed/replace DBUG symbols
3259
      return(1);
3260
  }
3261
3262
  return(0);
1 by brian
clean slate
3263
}
3264
3265
/*
3266
  Empty the hash table for native functions.
3267
  Note: this code is not thread safe, and is intended to be used at server
3268
  shutdown only (after thread requests have been executed).
3269
*/
3270
3271
void item_create_cleanup()
3272
{
3273
  hash_free(& native_functions_hash);
51.1.19 by Jay Pipes
Removed/replace DBUG symbols
3274
  return;
1 by brian
clean slate
3275
}
3276
3277
Create_func *
77.1.15 by Monty Taylor
Bunch of warning cleanups.
3278
find_native_function_builder(THD *thd __attribute__((__unused__)),
3279
                             LEX_STRING name)
1 by brian
clean slate
3280
{
3281
  Native_func_registry *func;
3282
  Create_func *builder= NULL;
3283
3284
  /* Thread safe */
3285
  func= (Native_func_registry*) hash_search(& native_functions_hash,
3286
                                            (uchar*) name.str,
3287
                                             name.length);
3288
3289
  if (func)
3290
  {
3291
    builder= func->builder;
3292
  }
3293
3294
  return builder;
3295
}
3296
3297
3298
Item*
3299
create_func_char_cast(THD *thd, Item *a, int len, CHARSET_INFO *cs)
3300
{
3301
  CHARSET_INFO *real_cs= (cs ? cs : thd->variables.collation_connection);
3302
  return new (thd->mem_root) Item_char_typecast(a, len, real_cs);
3303
}
3304
3305
3306
Item *
3307
create_func_cast(THD *thd, Item *a, Cast_target cast_type,
3308
                 const char *c_len, const char *c_dec,
3309
                 CHARSET_INFO *cs)
3310
{
3311
  Item *res;
3312
  ulong len;
3313
  uint dec;
3314
3315
  switch (cast_type) {
3316
  case ITEM_CAST_BINARY:
3317
    res= new (thd->mem_root) Item_func_binary(a);
3318
    break;
3319
  case ITEM_CAST_SIGNED_INT:
3320
    res= new (thd->mem_root) Item_func_signed(a);
3321
    break;
3322
  case ITEM_CAST_UNSIGNED_INT:
3323
    res= new (thd->mem_root) Item_func_unsigned(a);
3324
    break;
3325
  case ITEM_CAST_DATE:
3326
    res= new (thd->mem_root) Item_date_typecast(a);
3327
    break;
3328
  case ITEM_CAST_TIME:
3329
    res= new (thd->mem_root) Item_time_typecast(a);
3330
    break;
3331
  case ITEM_CAST_DATETIME:
3332
    res= new (thd->mem_root) Item_datetime_typecast(a);
3333
    break;
3334
  case ITEM_CAST_DECIMAL:
3335
  {
3336
    len= c_len ? atoi(c_len) : 0;
3337
    dec= c_dec ? atoi(c_dec) : 0;
3338
    my_decimal_trim(&len, &dec);
3339
    if (len < dec)
3340
    {
3341
      my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
3342
      return 0;
3343
    }
3344
    if (len > DECIMAL_MAX_PRECISION)
3345
    {
3346
      my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name,
3347
               DECIMAL_MAX_PRECISION);
3348
      return 0;
3349
    }
3350
    if (dec > DECIMAL_MAX_SCALE)
3351
    {
3352
      my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name,
3353
               DECIMAL_MAX_SCALE);
3354
      return 0;
3355
    }
3356
    res= new (thd->mem_root) Item_decimal_typecast(a, len, dec);
3357
    break;
3358
  }
3359
  case ITEM_CAST_CHAR:
3360
  {
3361
    len= c_len ? atoi(c_len) : -1;
3362
    res= create_func_char_cast(thd, a, len, cs);
3363
    break;
3364
  }
3365
  default:
3366
  {
51.1.19 by Jay Pipes
Removed/replace DBUG symbols
3367
    assert(0);
1 by brian
clean slate
3368
    res= 0;
3369
    break;
3370
  }
3371
  }
3372
  return res;
3373
}