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