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