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