~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/create.cc

  • Committer: Olaf van der Spek
  • Date: 2011-08-11 12:10:21 UTC
  • mto: This revision was merged to the branch mainline in revision 2397.
  • Revision ID: olafvdspek@gmail.com-20110811121021-cuio8i0qi202l6iu
Delete commented functions

Show diffs side-by-side

added added

removed removed

Lines of Context:
128
128
class Create_native_func : public Create_func
129
129
{
130
130
public:
131
 
  virtual Item* create(Session* session, str_ref name, List<Item>* item_list)
 
131
  virtual Item* create(Session* session, lex_string_t name, List<Item>* item_list)
132
132
  {
133
133
    if (item_list && has_named_parameters(*item_list))
134
134
    {
135
 
      my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.data());
 
135
      my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
136
136
      return NULL;
137
137
    }
138
138
    return create_native(session, name, item_list);
145
145
    @param item_list The function parameters, none of which are named
146
146
    @return An item representing the function call
147
147
  */
148
 
  virtual Item* create_native(Session*, str_ref name, List<Item>*) = 0;
 
148
  virtual Item* create_native(Session*, lex_string_t name, List<Item>*) = 0;
149
149
};
150
150
 
151
151
 
156
156
class Create_func_arg0 : public Create_func
157
157
{
158
158
public:
159
 
  virtual Item* create(Session *session, str_ref name, List<Item> *item_list);
 
159
  virtual Item* create(Session *session, lex_string_t name, List<Item> *item_list);
160
160
 
161
161
  /**
162
162
    Builder method, with no arguments.
174
174
class Create_func_arg1 : public Create_func
175
175
{
176
176
public:
177
 
  virtual Item* create(Session *session, str_ref name, List<Item> *item_list);
 
177
  virtual Item* create(Session *session, lex_string_t name, List<Item> *item_list);
178
178
 
179
179
  /**
180
180
    Builder method, with one argument.
193
193
class Create_func_arg2 : public Create_func
194
194
{
195
195
public:
196
 
  virtual Item* create(Session *session, str_ref name, List<Item> *item_list);
 
196
  virtual Item* create(Session *session, lex_string_t name, List<Item> *item_list);
197
197
 
198
198
  /**
199
199
    Builder method, with two arguments.
213
213
class Create_func_arg3 : public Create_func
214
214
{
215
215
public:
216
 
  virtual Item* create(Session *session, str_ref name, List<Item> *item_list);
 
216
  virtual Item* create(Session *session, lex_string_t name, List<Item> *item_list);
217
217
 
218
218
  /**
219
219
    Builder method, with three arguments.
246
246
  virtual Item* create(Session *session, Item *arg1);
247
247
 
248
248
  static Create_func_bin s_singleton;
 
249
 
 
250
protected:
 
251
  Create_func_bin() {}
249
252
};
250
253
 
251
254
class Create_func_concat : public Create_native_func
252
255
{
253
256
public:
254
 
  virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
 
257
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
255
258
 
256
259
  static Create_func_concat s_singleton;
 
260
 
 
261
protected:
 
262
  Create_func_concat() {}
257
263
};
258
264
 
259
265
 
260
266
class Create_func_concat_ws : public Create_native_func
261
267
{
262
268
public:
263
 
  virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
 
269
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
264
270
 
265
271
  static Create_func_concat_ws s_singleton;
 
272
 
 
273
protected:
 
274
  Create_func_concat_ws() {}
266
275
};
267
276
 
268
277
 
277
286
  }
278
287
 
279
288
  static Create_func_conv s_singleton;
 
289
protected:
 
290
  Create_func_conv() {}
280
291
};
281
292
 
282
293
Create_func_conv Create_func_conv::s_singleton;
289
300
  virtual Item* create(Session *session, Item *arg1);
290
301
 
291
302
  static Create_func_cot s_singleton;
 
303
 
 
304
protected:
 
305
  Create_func_cot() {}
292
306
};
293
307
 
294
308
class Create_func_date_format : public Create_func_arg2
302
316
  }
303
317
 
304
318
  static Create_func_date_format s_singleton;
 
319
protected:
 
320
  Create_func_date_format() {}
305
321
};
306
322
 
307
323
Create_func_date_format Create_func_date_format::s_singleton;
314
330
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
315
331
 
316
332
  static Create_func_datediff s_singleton;
 
333
 
 
334
protected:
 
335
  Create_func_datediff() {}
317
336
};
318
337
 
319
338
 
328
347
  }
329
348
 
330
349
  static Create_func_dayname s_singleton;
 
350
 
 
351
protected:
 
352
  Create_func_dayname() {}
331
353
};
332
354
 
333
355
Create_func_dayname Create_func_dayname::s_singleton;
343
365
  }
344
366
 
345
367
  static Create_func_dayofmonth s_singleton;
 
368
protected:
 
369
  Create_func_dayofmonth() {}
346
370
};
347
371
 
348
372
Create_func_dayofmonth Create_func_dayofmonth::s_singleton;
358
382
  }
359
383
 
360
384
  static Create_func_dayofweek s_singleton;
 
385
protected:
 
386
  Create_func_dayofweek() {}
361
387
};
362
388
 
363
389
Create_func_dayofweek Create_func_dayofweek::s_singleton;
373
399
  }
374
400
 
375
401
  static Create_func_dayofyear s_singleton;
 
402
protected:
 
403
  Create_func_dayofyear() {}
376
404
};
377
405
 
378
406
Create_func_dayofyear Create_func_dayofyear::s_singleton;
385
413
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
386
414
 
387
415
  static Create_func_decode s_singleton;
 
416
 
 
417
protected:
 
418
  Create_func_decode() {}
388
419
};
389
420
 
390
421
 
399
430
  }
400
431
 
401
432
  static Create_func_degrees s_singleton;
 
433
protected:
 
434
  Create_func_degrees() {}
402
435
};
403
436
 
404
437
Create_func_degrees Create_func_degrees::s_singleton;
407
440
{
408
441
 
409
442
public:
410
 
  virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
 
443
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
411
444
 
412
445
  static Create_func_export_set s_singleton;
 
446
 
 
447
protected:
 
448
  Create_func_export_set() {}
413
449
};
414
450
 
415
451
 
416
452
class Create_func_field : public Create_native_func
417
453
{
418
454
public:
419
 
  virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
 
455
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
420
456
 
421
457
  static Create_func_field s_singleton;
 
458
 
 
459
protected:
 
460
  Create_func_field() {}
422
461
};
423
462
 
424
463
 
427
466
public:
428
467
  using Create_func_arg2::create;
429
468
 
430
 
  virtual Item* create(Session *session, Item *arg1, Item *arg2)
431
 
  {
432
 
    return new (session->mem) Item_func_find_in_set(arg1, arg2);
433
 
  }
 
469
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
434
470
 
435
471
  static Create_func_find_in_set s_singleton;
 
472
 
 
473
protected:
 
474
  Create_func_find_in_set() {}
436
475
};
437
476
 
438
477
class Create_func_found_rows : public Create_func_arg0
440
479
public:
441
480
  using Create_func_arg0::create;
442
481
 
443
 
  virtual Item* create(Session *session)
444
 
  {
445
 
    return new (session->mem) Item_func_found_rows();
446
 
  }
 
482
  virtual Item* create(Session *session);
447
483
 
448
484
  static Create_func_found_rows s_singleton;
 
485
 
 
486
protected:
 
487
  Create_func_found_rows() {}
449
488
};
450
489
 
451
490
 
454
493
public:
455
494
  using Create_func_arg1::create;
456
495
 
457
 
  virtual Item* create(Session *session, Item *arg1)
458
 
  {
459
 
    return new (session->mem) Item_func_from_days(arg1);
460
 
  }
 
496
  virtual Item* create(Session *session, Item *arg1);
461
497
 
462
498
  static Create_func_from_days s_singleton;
 
499
 
 
500
protected:
 
501
  Create_func_from_days() {}
463
502
};
464
503
 
465
504
 
466
505
class Create_func_from_unixtime : public Create_native_func
467
506
{
468
507
public:
469
 
  virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
 
508
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
470
509
 
471
510
  static Create_func_from_unixtime s_singleton;
 
511
 
 
512
protected:
 
513
  Create_func_from_unixtime() {}
472
514
};
473
515
 
474
516
 
475
517
class Create_func_greatest : public Create_native_func
476
518
{
477
519
public:
478
 
  virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
 
520
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
479
521
 
480
522
  static Create_func_greatest s_singleton;
 
523
 
 
524
protected:
 
525
  Create_func_greatest() {}
481
526
};
482
527
 
483
528
 
486
531
public:
487
532
  using Create_func_arg2::create;
488
533
 
489
 
  virtual Item* create(Session *session, Item *arg1, Item *arg2)
490
 
  {
491
 
    return new (session->mem) Item_func_ifnull(arg1, arg2);
492
 
  }
 
534
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
493
535
 
494
536
  static Create_func_ifnull s_singleton;
 
537
 
 
538
protected:
 
539
  Create_func_ifnull() {}
495
540
};
496
541
 
497
542
 
500
545
public:
501
546
  using Create_func_arg2::create;
502
547
 
503
 
  virtual Item* create(Session *session, Item *arg1, Item *arg2)
504
 
  {
505
 
    return new (session->mem) Item_func_locate(arg1, arg2);
506
 
  }
 
548
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
507
549
 
508
550
  static Create_func_instr s_singleton;
 
551
 
 
552
protected:
 
553
  Create_func_instr() {}
509
554
};
510
555
 
511
556
 
514
559
public:
515
560
  using Create_func_arg1::create;
516
561
 
517
 
  virtual Item* create(Session *session, Item *arg1)
518
 
  {
519
 
    return new (session->mem) Item_func_isnull(arg1);
520
 
  }
 
562
  virtual Item* create(Session *session, Item *arg1);
521
563
 
522
564
  static Create_func_isnull s_singleton;
 
565
 
 
566
protected:
 
567
  Create_func_isnull() {}
523
568
};
524
569
 
525
570
 
528
573
public:
529
574
  using Create_func_arg1::create;
530
575
 
531
 
  virtual Item* create(Session *session, Item *arg1)
532
 
  {
533
 
    return new (session->mem) Item_func_last_day(arg1);
534
 
  }
 
576
  virtual Item* create(Session *session, Item *arg1);
535
577
 
536
578
  static Create_func_last_day s_singleton;
 
579
 
 
580
protected:
 
581
  Create_func_last_day() {}
537
582
};
538
583
 
539
584
 
540
585
class Create_func_last_insert_id : public Create_native_func
541
586
{
542
587
public:
543
 
  virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
 
588
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
544
589
 
545
590
  static Create_func_last_insert_id s_singleton;
 
591
 
 
592
protected:
 
593
  Create_func_last_insert_id() {}
546
594
};
547
595
 
548
596
 
551
599
public:
552
600
  using Create_func_arg1::create;
553
601
 
554
 
  virtual Item* create(Session *session, Item *arg1)
555
 
  {
556
 
    return new (session->mem) Item_func_lcase(arg1);
557
 
  }
 
602
  virtual Item* create(Session *session, Item *arg1);
558
603
 
559
604
  static Create_func_lcase s_singleton;
 
605
 
 
606
protected:
 
607
  Create_func_lcase() {}
560
608
};
561
609
 
562
610
 
563
611
class Create_func_least : public Create_native_func
564
612
{
565
613
public:
566
 
  virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
 
614
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
567
615
 
568
616
  static Create_func_least s_singleton;
 
617
 
 
618
protected:
 
619
  Create_func_least() {}
569
620
};
570
621
 
571
622
class Create_func_load_file : public Create_func_arg1
573
624
public:
574
625
  using Create_func_arg1::create;
575
626
 
576
 
  virtual Item* create(Session *session, Item *arg1)
577
 
  {
578
 
    return new (session->mem) Item_load_file(*session, arg1);
579
 
  }
 
627
  virtual Item* create(Session *session, Item *arg1);
580
628
 
581
629
  static Create_func_load_file s_singleton;
 
630
 
 
631
protected:
 
632
  Create_func_load_file() {}
582
633
};
583
634
 
 
635
 
584
636
class Create_func_locate : public Create_native_func
585
637
{
586
638
public:
587
 
  virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
 
639
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
588
640
 
589
641
  static Create_func_locate s_singleton;
 
642
 
 
643
protected:
 
644
  Create_func_locate() {}
590
645
};
591
646
 
 
647
 
592
648
class Create_func_lpad : public Create_func_arg3
593
649
{
594
650
public:
600
656
  }
601
657
 
602
658
  static Create_func_lpad s_singleton;
 
659
protected:
 
660
  Create_func_lpad() {}
603
661
};
604
662
 
605
663
Create_func_lpad Create_func_lpad::s_singleton;
615
673
  }
616
674
 
617
675
  static Create_func_ltrim s_singleton;
 
676
protected:
 
677
  Create_func_ltrim() {}
618
678
};
619
679
 
620
680
Create_func_ltrim Create_func_ltrim::s_singleton;
630
690
  }
631
691
 
632
692
  static Create_func_makedate s_singleton;
 
693
protected:
 
694
  Create_func_makedate() {}
633
695
};
634
696
 
635
697
Create_func_makedate Create_func_makedate::s_singleton;
637
699
class Create_func_make_set : public Create_native_func
638
700
{
639
701
public:
640
 
  virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
 
702
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
641
703
 
642
704
  static Create_func_make_set s_singleton;
 
705
 
 
706
protected:
 
707
  Create_func_make_set() {}
643
708
};
644
709
 
645
710
 
654
719
  }
655
720
 
656
721
  static Create_func_monthname s_singleton;
 
722
protected:
 
723
  Create_func_monthname() {}
657
724
};
658
725
 
659
726
Create_func_monthname Create_func_monthname::s_singleton;
666
733
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
667
734
 
668
735
  static Create_func_name_const s_singleton;
 
736
 
 
737
protected:
 
738
  Create_func_name_const() {}
669
739
};
670
740
 
671
741
 
680
750
  }
681
751
 
682
752
  static Create_func_nullif s_singleton;
 
753
protected:
 
754
  Create_func_nullif() {}
683
755
};
684
756
 
685
757
Create_func_nullif Create_func_nullif::s_singleton;
692
764
  virtual Item* create(Session *session, Item *arg1);
693
765
 
694
766
  static Create_func_oct s_singleton;
 
767
 
 
768
protected:
 
769
  Create_func_oct() {}
695
770
};
696
771
 
697
772
class Create_func_period_add : public Create_func_arg2
699
774
public:
700
775
  using Create_func_arg2::create;
701
776
 
702
 
  virtual Item* create(Session *session, Item *arg1, Item *arg2)
703
 
  {
704
 
    return new (session->mem) Item_func_period_add(arg1, arg2);
705
 
  }
 
777
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
706
778
 
707
779
  static Create_func_period_add s_singleton;
 
780
 
 
781
protected:
 
782
  Create_func_period_add() {}
708
783
};
709
784
 
710
785
 
713
788
public:
714
789
  using Create_func_arg2::create;
715
790
 
716
 
  virtual Item* create(Session *session, Item *arg1, Item *arg2)
717
 
  {
718
 
    return new (session->mem) Item_func_period_diff(arg1, arg2);
719
 
  }
 
791
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
720
792
 
721
793
  static Create_func_period_diff s_singleton;
 
794
 
 
795
protected:
 
796
  Create_func_period_diff() {}
722
797
};
723
798
 
724
799
 
727
802
public:
728
803
  using Create_func_arg0::create;
729
804
 
730
 
  virtual Item* create(Session *session)
731
 
  {
732
 
    return new (session->mem) Item_static_float_func("pi()", M_PI, 6, 8);
733
 
  }
 
805
  virtual Item* create(Session *session);
734
806
 
735
807
  static Create_func_pi s_singleton;
 
808
 
 
809
protected:
 
810
  Create_func_pi() {}
736
811
};
737
812
 
738
813
class Create_func_radians : public Create_func_arg1
740
815
public:
741
816
  using Create_func_arg1::create;
742
817
 
743
 
  virtual Item* create(Session *session, Item *arg1)
744
 
  {
745
 
    return new (session->mem) Item_func_units("radians", arg1, M_PI/180, 0.0);
746
 
  }
 
818
  virtual Item* create(Session *session, Item *arg1);
747
819
 
748
820
  static Create_func_radians s_singleton;
 
821
protected:
 
822
  Create_func_radians() {}
749
823
};
750
824
 
751
825
 
752
826
class Create_func_round : public Create_native_func
753
827
{
754
828
public:
755
 
  virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
 
829
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
756
830
 
757
831
  static Create_func_round s_singleton;
 
832
protected:
 
833
  Create_func_round() {}
758
834
};
759
835
 
760
836
 
769
845
  }
770
846
 
771
847
  static Create_func_row_count s_singleton;
 
848
protected:
 
849
  Create_func_row_count() {}
772
850
};
773
851
 
774
852
Create_func_row_count Create_func_row_count::s_singleton;
784
862
  }
785
863
 
786
864
  static Create_func_rpad s_singleton;
 
865
protected:
 
866
  Create_func_rpad() {}
787
867
};
788
868
 
789
869
Create_func_rpad Create_func_rpad::s_singleton;
799
879
  }
800
880
 
801
881
  static Create_func_rtrim s_singleton;
 
882
 
 
883
protected:
 
884
  Create_func_rtrim() {}
802
885
};
803
886
 
804
887
Create_func_rtrim Create_func_rtrim::s_singleton;
814
897
  }
815
898
 
816
899
  static Create_func_sign s_singleton;
 
900
protected:
 
901
  Create_func_sign() {}
817
902
};
818
903
 
819
904
Create_func_sign Create_func_sign::s_singleton;
826
911
  virtual Item* create(Session *session, Item *arg1);
827
912
 
828
913
  static Create_func_space s_singleton;
 
914
protected:
 
915
  Create_func_space() {}
829
916
};
830
917
 
831
918
class Create_func_strcmp : public Create_func_arg2
839
926
  }
840
927
  
841
928
  static Create_func_strcmp s_singleton;
 
929
protected:
 
930
  Create_func_strcmp() {}
842
931
};
843
932
 
844
933
Create_func_strcmp Create_func_strcmp::s_singleton;
854
943
  }
855
944
 
856
945
  static Create_func_tan s_singleton;
 
946
protected:
 
947
  Create_func_tan() {}
857
948
};
858
949
 
859
950
Create_func_tan Create_func_tan::s_singleton;
869
960
  }
870
961
 
871
962
  static Create_func_time_format s_singleton;
 
963
protected:
 
964
  Create_func_time_format() {}
872
965
};
873
966
 
874
967
Create_func_time_format Create_func_time_format::s_singleton;
884
977
  }
885
978
 
886
979
  static Create_func_to_days s_singleton;
 
980
protected:
 
981
  Create_func_to_days() {}
887
982
};
888
983
 
889
984
Create_func_to_days Create_func_to_days::s_singleton;
899
994
  }
900
995
 
901
996
  static Create_func_ucase s_singleton;
 
997
protected:
 
998
  Create_func_ucase() {}
902
999
};
903
1000
 
904
1001
Create_func_ucase Create_func_ucase::s_singleton;
906
1003
class Create_func_unix_timestamp : public Create_native_func
907
1004
{
908
1005
public:
909
 
  virtual Item* create_native(Session *session, str_ref name, List<Item> *item_list);
 
1006
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
910
1007
 
911
1008
  static Create_func_unix_timestamp s_singleton;
 
1009
protected:
 
1010
  Create_func_unix_timestamp() {}
912
1011
};
913
1012
 
914
1013
 
923
1022
  }
924
1023
 
925
1024
  static Create_func_weekday s_singleton;
 
1025
protected:
 
1026
  Create_func_weekday() {}
926
1027
};
927
1028
 
928
1029
Create_func_weekday Create_func_weekday::s_singleton;
935
1036
 
936
1037
Create_udf_func Create_udf_func::s_singleton;
937
1038
 
938
 
Item* Create_udf_func::create(Session *session, str_ref name, List<Item> *item_list)
 
1039
Item* Create_udf_func::create(Session *session, lex_string_t name, List<Item> *item_list)
939
1040
{
940
 
  return create(session, plugin::Function::get(to_string(name)), item_list);
 
1041
  return create(session, plugin::Function::get(std::string(name.str, name.length)), item_list);
941
1042
}
942
1043
 
943
1044
Item* Create_udf_func::create(Session *session, const plugin::Function *udf, List<Item> *item_list)
944
1045
{
945
1046
  assert(udf);
 
1047
  int arg_count= item_list ? item_list->size() : 0;
946
1048
  Item_func* func= (*udf)(&session->mem);
947
 
  if (!func->check_argument_count(item_list ? item_list->size() : 0))
 
1049
  if (!func->check_argument_count(arg_count))
948
1050
  {
949
1051
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), func->func_name());
950
1052
    return NULL;
954
1056
  return func;
955
1057
}
956
1058
 
957
 
Item* Create_func_arg0::create(Session *session, str_ref name, List<Item> *item_list)
 
1059
Item* Create_func_arg0::create(Session *session, lex_string_t name, List<Item> *item_list)
958
1060
{
959
 
  if (not item_list || not item_list->size())
960
 
    return create(session);
961
 
  my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
962
 
  return NULL;
 
1061
  if (item_list && item_list->size())
 
1062
  {
 
1063
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1064
    return NULL;
 
1065
  }
 
1066
  return create(session);
963
1067
}
964
1068
 
965
 
Item* Create_func_arg1::create(Session *session, str_ref name, List<Item> *item_list)
 
1069
Item* Create_func_arg1::create(Session *session, lex_string_t name, List<Item> *item_list)
966
1070
{
967
 
  if (not item_list || item_list->size() != 1)
 
1071
  int arg_count= item_list ? item_list->size() : 0;
 
1072
  if (arg_count != 1)
968
1073
  {
969
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
 
1074
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
970
1075
    return NULL;
971
1076
  }
972
1077
 
973
1078
  Item *param_1= item_list->pop();
974
 
  if (param_1->is_autogenerated_name)
975
 
    return create(session, param_1);
976
 
  my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.data());
977
 
  return NULL;
 
1079
 
 
1080
  if (! param_1->is_autogenerated_name)
 
1081
  {
 
1082
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
 
1083
    return NULL;
 
1084
  }
 
1085
 
 
1086
  return create(session, param_1);
978
1087
}
979
1088
 
980
 
Item* Create_func_arg2::create(Session *session, str_ref name, List<Item> *item_list)
 
1089
 
 
1090
Item*
 
1091
Create_func_arg2::create(Session *session, lex_string_t name, List<Item> *item_list)
981
1092
{
982
 
  if (not item_list || item_list->size() != 2)
 
1093
  int arg_count= item_list ? item_list->size() : 0;
 
1094
  if (arg_count != 2)
983
1095
  {
984
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
 
1096
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
985
1097
    return NULL;
986
1098
  }
987
1099
 
988
1100
  Item *param_1= item_list->pop();
989
1101
  Item *param_2= item_list->pop();
990
1102
 
991
 
  if (param_1->is_autogenerated_name
992
 
    && param_2->is_autogenerated_name)
 
1103
  if (   (! param_1->is_autogenerated_name)
 
1104
      || (! param_2->is_autogenerated_name))
 
1105
  {
 
1106
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
 
1107
    return NULL;
 
1108
  }
 
1109
 
993
1110
  return create(session, param_1, param_2);
994
 
  my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.data());
995
 
  return NULL;
996
1111
}
997
1112
 
998
 
Item* Create_func_arg3::create(Session *session, str_ref name, List<Item> *item_list)
 
1113
 
 
1114
Item*
 
1115
Create_func_arg3::create(Session *session, lex_string_t name, List<Item> *item_list)
999
1116
{
1000
 
  if (not item_list || item_list->size() != 3)
 
1117
  int arg_count= item_list ? item_list->size() : 0;
 
1118
  if (arg_count != 3)
1001
1119
  {
1002
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
 
1120
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1003
1121
    return NULL;
1004
1122
  }
1005
1123
 
1007
1125
  Item *param_2= item_list->pop();
1008
1126
  Item *param_3= item_list->pop();
1009
1127
 
1010
 
  if (param_1->is_autogenerated_name
1011
 
    && param_2->is_autogenerated_name
1012
 
    && param_3->is_autogenerated_name)
1013
 
    return create(session, param_1, param_2, param_3);
1014
 
  my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.data());
1015
 
  return NULL;
 
1128
  if (   (! param_1->is_autogenerated_name)
 
1129
      || (! param_2->is_autogenerated_name)
 
1130
      || (! param_3->is_autogenerated_name))
 
1131
  {
 
1132
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
 
1133
    return NULL;
 
1134
  }
 
1135
 
 
1136
  return create(session, param_1, param_2, param_3);
1016
1137
}
1017
1138
 
1018
1139
Create_func_bin Create_func_bin::s_singleton;
1019
1140
 
1020
 
Item* Create_func_bin::create(Session *session, Item *arg1)
 
1141
Item*
 
1142
Create_func_bin::create(Session *session, Item *arg1)
1021
1143
{
1022
1144
  Item *i10= new (session->mem) Item_int(10, 2);
1023
1145
  Item *i2= new (session->mem) Item_int(2, 1);
1026
1148
 
1027
1149
Create_func_concat Create_func_concat::s_singleton;
1028
1150
 
1029
 
Item* Create_func_concat::create_native(Session *session, str_ref name, List<Item> *item_list)
 
1151
Item*
 
1152
Create_func_concat::create_native(Session *session, lex_string_t name, List<Item> *item_list)
1030
1153
{
1031
 
  if (item_list && item_list->size() >= 1)
1032
 
    return new (session->mem) Item_func_concat(*session, *item_list);
1033
 
  my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1034
 
  return NULL;
 
1154
  int arg_count= item_list ? item_list->size() : 0;
 
1155
  if (arg_count < 1)
 
1156
  {
 
1157
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1158
    return NULL;
 
1159
  }
 
1160
 
 
1161
  return new (session->mem) Item_func_concat(*session, *item_list);
1035
1162
}
1036
1163
 
 
1164
 
1037
1165
Create_func_concat_ws Create_func_concat_ws::s_singleton;
1038
1166
 
1039
 
Item* Create_func_concat_ws::create_native(Session *session, str_ref name, List<Item> *item_list)
 
1167
Item*
 
1168
Create_func_concat_ws::create_native(Session *session, lex_string_t name,
 
1169
                                     List<Item> *item_list)
1040
1170
{
 
1171
  int arg_count= item_list ? item_list->size() : 0;
1041
1172
  /* "WS" stands for "With Separator": this function takes 2+ arguments */
1042
 
  if (item_list && item_list->size() >= 2)
1043
 
    return new (session->mem) Item_func_concat_ws(*session, *item_list);
1044
 
  my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1045
 
  return NULL;
 
1173
  if (arg_count < 2)
 
1174
  {
 
1175
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1176
    return NULL;
 
1177
  }
 
1178
 
 
1179
  return new (session->mem) Item_func_concat_ws(*session, *item_list);
1046
1180
}
1047
1181
 
1048
1182
Create_func_cot Create_func_cot::s_singleton;
1068
1202
Create_func_export_set Create_func_export_set::s_singleton;
1069
1203
 
1070
1204
Item*
1071
 
Create_func_export_set::create_native(Session *session, str_ref name, List<Item> *item_list)
 
1205
Create_func_export_set::create_native(Session *session, lex_string_t name, List<Item> *item_list)
1072
1206
{
1073
1207
  switch (item_list ? item_list->size() : 0) 
1074
1208
  {
1096
1230
      Item *param_5= item_list->pop();
1097
1231
      return new (session->mem) Item_func_export_set(param_1, param_2, param_3, param_4, param_5);
1098
1232
    }
 
1233
  default:
 
1234
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1099
1235
  }
1100
 
  my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1101
1236
  return NULL;
1102
1237
}
1103
1238
 
1104
1239
 
1105
1240
Create_func_field Create_func_field::s_singleton;
1106
1241
 
1107
 
Item* Create_func_field::create_native(Session *session, str_ref name, List<Item> *item_list)
 
1242
Item*
 
1243
Create_func_field::create_native(Session *session, lex_string_t name,
 
1244
                                 List<Item> *item_list)
1108
1245
{
1109
 
  if (item_list && item_list->size() >= 2)
1110
 
    return new (session->mem) Item_func_field(*item_list);
1111
 
  my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1112
 
  return NULL;
 
1246
  int arg_count= item_list ? item_list->size() : 0;
 
1247
  if (arg_count < 2)
 
1248
  {
 
1249
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1250
    return NULL;
 
1251
  }
 
1252
 
 
1253
  return new (session->mem) Item_func_field(*item_list);
1113
1254
}
1114
1255
 
 
1256
 
1115
1257
Create_func_find_in_set Create_func_find_in_set::s_singleton;
 
1258
 
 
1259
Item*
 
1260
Create_func_find_in_set::create(Session *session, Item *arg1, Item *arg2)
 
1261
{
 
1262
  return new (session->mem) Item_func_find_in_set(arg1, arg2);
 
1263
}
 
1264
 
1116
1265
Create_func_found_rows Create_func_found_rows::s_singleton;
 
1266
 
 
1267
Item*
 
1268
Create_func_found_rows::create(Session *session)
 
1269
{
 
1270
  return new (session->mem) Item_func_found_rows();
 
1271
}
 
1272
 
 
1273
 
1117
1274
Create_func_from_days Create_func_from_days::s_singleton;
 
1275
 
 
1276
Item*
 
1277
Create_func_from_days::create(Session *session, Item *arg1)
 
1278
{
 
1279
  return new (session->mem) Item_func_from_days(arg1);
 
1280
}
 
1281
 
 
1282
 
1118
1283
Create_func_from_unixtime Create_func_from_unixtime::s_singleton;
1119
1284
 
1120
 
Item* Create_func_from_unixtime::create_native(Session *session, str_ref name, List<Item> *item_list)
 
1285
Item*
 
1286
Create_func_from_unixtime::create_native(Session *session, lex_string_t name,
 
1287
                                         List<Item> *item_list)
1121
1288
{
1122
1289
  switch (item_list ? item_list->size() : 0) 
1123
1290
  {
1133
1300
      Item *ut= new (session->mem) Item_func_from_unixtime(param_1);
1134
1301
      return new (session->mem) Item_func_date_format(ut, param_2, 0);
1135
1302
    }
 
1303
  default:
 
1304
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1136
1305
  }
1137
 
  my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1138
1306
  return NULL;
1139
1307
}
1140
1308
 
 
1309
 
1141
1310
Create_func_greatest Create_func_greatest::s_singleton;
1142
1311
 
1143
 
Item* Create_func_greatest::create_native(Session *session, str_ref name, List<Item> *item_list)
 
1312
Item*
 
1313
Create_func_greatest::create_native(Session *session, lex_string_t name,
 
1314
                                    List<Item> *item_list)
1144
1315
{
1145
 
  if (item_list && item_list->size() >= 2)
 
1316
  int arg_count= item_list ? item_list->size() : 0;
 
1317
  if (arg_count < 2)
 
1318
  {
 
1319
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1320
    return NULL;
 
1321
  }
 
1322
 
1146
1323
  return new (session->mem) Item_func_max(*item_list);
1147
 
  my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1148
 
  return NULL;
1149
1324
}
1150
1325
 
1151
1326
Create_func_ifnull Create_func_ifnull::s_singleton;
 
1327
 
 
1328
Item*
 
1329
Create_func_ifnull::create(Session *session, Item *arg1, Item *arg2)
 
1330
{
 
1331
  return new (session->mem) Item_func_ifnull(arg1, arg2);
 
1332
}
 
1333
 
 
1334
 
1152
1335
Create_func_instr Create_func_instr::s_singleton;
 
1336
 
 
1337
Item*
 
1338
Create_func_instr::create(Session *session, Item *arg1, Item *arg2)
 
1339
{
 
1340
  return new (session->mem) Item_func_locate(arg1, arg2);
 
1341
}
 
1342
 
 
1343
 
1153
1344
Create_func_isnull Create_func_isnull::s_singleton;
 
1345
 
 
1346
Item*
 
1347
Create_func_isnull::create(Session *session, Item *arg1)
 
1348
{
 
1349
  return new (session->mem) Item_func_isnull(arg1);
 
1350
}
 
1351
 
 
1352
 
1154
1353
Create_func_last_day Create_func_last_day::s_singleton;
 
1354
 
 
1355
Item*
 
1356
Create_func_last_day::create(Session *session, Item *arg1)
 
1357
{
 
1358
  return new (session->mem) Item_func_last_day(arg1);
 
1359
}
 
1360
 
 
1361
 
1155
1362
Create_func_last_insert_id Create_func_last_insert_id::s_singleton;
1156
1363
 
1157
 
Item* Create_func_last_insert_id::create_native(Session *session, str_ref name, List<Item> *item_list)
 
1364
Item*
 
1365
Create_func_last_insert_id::create_native(Session *session, lex_string_t name,
 
1366
                                          List<Item> *item_list)
1158
1367
{
1159
1368
  int arg_count= item_list ? item_list->size() : 0;
1160
 
  switch (arg_count) 
1161
 
  {
 
1369
  switch (arg_count) {
1162
1370
  case 0:
1163
1371
    {
1164
1372
      return new (session->mem) Item_func_last_insert_id();
1168
1376
      Item *param_1= item_list->pop();
1169
1377
      return new (session->mem) Item_func_last_insert_id(param_1);
1170
1378
    }
 
1379
  default:
 
1380
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1171
1381
  }
1172
 
  my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1173
1382
  return NULL;
1174
1383
}
1175
1384
 
 
1385
 
1176
1386
Create_func_lcase Create_func_lcase::s_singleton;
 
1387
 
 
1388
Item*
 
1389
Create_func_lcase::create(Session *session, Item *arg1)
 
1390
{
 
1391
  return new (session->mem) Item_func_lcase(arg1);
 
1392
}
 
1393
 
 
1394
 
1177
1395
Create_func_least Create_func_least::s_singleton;
1178
1396
 
1179
 
Item* Create_func_least::create_native(Session *session, str_ref name, List<Item> *item_list)
 
1397
Item*
 
1398
Create_func_least::create_native(Session *session, lex_string_t name,
 
1399
                                 List<Item> *item_list)
1180
1400
{
1181
 
  if (item_list && item_list->size() >= 2)
1182
 
    return new (session->mem) Item_func_min(*item_list);
1183
 
  my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1184
 
  return NULL;
 
1401
  int arg_count= item_list ? item_list->size() : 0;
 
1402
  if (arg_count < 2)
 
1403
  {
 
1404
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1405
    return NULL;
 
1406
  }
 
1407
 
 
1408
  return new (session->mem) Item_func_min(*item_list);
1185
1409
}
1186
1410
 
1187
1411
Create_func_load_file Create_func_load_file::s_singleton;
 
1412
 
 
1413
Item*
 
1414
Create_func_load_file::create(Session *session, Item *arg1)
 
1415
{
 
1416
  return new (session->mem) Item_load_file(*session, arg1);
 
1417
}
 
1418
 
 
1419
 
1188
1420
Create_func_locate Create_func_locate::s_singleton;
1189
1421
 
1190
 
Item* Create_func_locate::create_native(Session *session, str_ref name, List<Item> *item_list)
 
1422
Item*
 
1423
Create_func_locate::create_native(Session *session, lex_string_t name,
 
1424
                                  List<Item> *item_list)
1191
1425
{
1192
 
  switch (item_list ? item_list->size() : 0) 
 
1426
  int arg_count= item_list ? item_list->size() : 0;
 
1427
  switch (arg_count) 
1193
1428
  {
1194
1429
  case 2:
1195
1430
    {
1206
1441
      /* Yes, parameters in that order : 2, 1, 3 */
1207
1442
      return new (session->mem) Item_func_locate(param_2, param_1, param_3);
1208
1443
    }
 
1444
  default:
 
1445
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1209
1446
  }
1210
 
  my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1211
1447
  return NULL;
1212
1448
}
1213
1449
 
1214
1450
Create_func_make_set Create_func_make_set::s_singleton;
1215
1451
 
1216
 
Item* Create_func_make_set::create_native(Session *session_arg, str_ref name, List<Item> *item_list)
 
1452
Item*
 
1453
Create_func_make_set::create_native(Session *session_arg, lex_string_t name,
 
1454
                                    List<Item> *item_list)
1217
1455
{
1218
 
  if (not item_list || item_list->size() < 2)
 
1456
  int arg_count= item_list ? item_list->size() : 0;
 
1457
  if (arg_count < 2)
1219
1458
  {
1220
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
 
1459
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1221
1460
    return NULL;
1222
1461
  }
1223
1462
 
1227
1466
 
1228
1467
Create_func_oct Create_func_oct::s_singleton;
1229
1468
 
1230
 
Item* Create_func_oct::create(Session *session, Item *arg1)
 
1469
Item*
 
1470
Create_func_oct::create(Session *session, Item *arg1)
1231
1471
{
1232
1472
  Item *i10= new (session->mem) Item_int((int32_t) 10,2);
1233
1473
  Item *i8= new (session->mem) Item_int((int32_t) 8,1);
1235
1475
}
1236
1476
 
1237
1477
Create_func_period_add Create_func_period_add::s_singleton;
 
1478
 
 
1479
Item*
 
1480
Create_func_period_add::create(Session *session, Item *arg1, Item *arg2)
 
1481
{
 
1482
  return new (session->mem) Item_func_period_add(arg1, arg2);
 
1483
}
 
1484
 
 
1485
 
1238
1486
Create_func_period_diff Create_func_period_diff::s_singleton;
 
1487
 
 
1488
Item*
 
1489
Create_func_period_diff::create(Session *session, Item *arg1, Item *arg2)
 
1490
{
 
1491
  return new (session->mem) Item_func_period_diff(arg1, arg2);
 
1492
}
 
1493
 
 
1494
 
1239
1495
Create_func_pi Create_func_pi::s_singleton;
 
1496
 
 
1497
Item*
 
1498
Create_func_pi::create(Session *session)
 
1499
{
 
1500
  return new (session->mem) Item_static_float_func("pi()", M_PI, 6, 8);
 
1501
}
 
1502
 
1240
1503
Create_func_radians Create_func_radians::s_singleton;
 
1504
 
 
1505
Item*
 
1506
Create_func_radians::create(Session *session, Item *arg1)
 
1507
{
 
1508
  return new (session->mem) Item_func_units("radians", arg1,
 
1509
                                             M_PI/180, 0.0);
 
1510
}
 
1511
 
1241
1512
Create_func_round Create_func_round::s_singleton;
1242
1513
 
1243
 
Item* Create_func_round::create_native(Session *session, str_ref name, List<Item> *item_list)
 
1514
Item* Create_func_round::create_native(Session *session, lex_string_t name, List<Item> *item_list)
1244
1515
{
1245
1516
  switch (item_list ? item_list->size() : 0) 
1246
1517
  {
1247
1518
  case 1:
1248
 
    {
1249
 
      Item *param_1= item_list->pop();
1250
 
      Item *i0 = new (session->mem) Item_int("0", 0, 1);
1251
 
      return new (session->mem) Item_func_round(param_1, i0, 0);
1252
 
    }
 
1519
  {
 
1520
    Item *param_1= item_list->pop();
 
1521
    Item *i0 = new (session->mem) Item_int("0", 0, 1);
 
1522
    return new (session->mem) Item_func_round(param_1, i0, 0);
 
1523
  }
1253
1524
  case 2:
1254
 
    {
1255
 
      Item *param_1= item_list->pop();
1256
 
      Item *param_2= item_list->pop();
1257
 
      return new (session->mem) Item_func_round(param_1, param_2, 0);
1258
 
    }
1259
 
  }
1260
 
  my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
 
1525
  {
 
1526
    Item *param_1= item_list->pop();
 
1527
    Item *param_2= item_list->pop();
 
1528
    return new (session->mem) Item_func_round(param_1, param_2, 0);
 
1529
  }
 
1530
  default:
 
1531
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1532
  }
1261
1533
  return NULL;
1262
1534
}
1263
1535
 
1264
1536
Create_func_space Create_func_space::s_singleton;
1265
1537
 
1266
 
Item* Create_func_space::create(Session *session, Item *arg1)
 
1538
Item*
 
1539
Create_func_space::create(Session *session, Item *arg1)
1267
1540
{
1268
1541
  /**
1269
1542
    TODO: Fix Bug#23637
1275
1548
 
1276
1549
  if (cs->mbminlen > 1)
1277
1550
  {
1278
 
    sp= new (session->mem) Item_string(str_ref(""), cs, DERIVATION_COERCIBLE);
 
1551
    sp= new (session->mem) Item_string("", 0, cs, DERIVATION_COERCIBLE);
1279
1552
    sp->str_value.copy(" ", 1, cs);
1280
1553
  }
1281
1554
  else
1282
1555
  {
1283
 
    sp= new (session->mem) Item_string(str_ref(" "), cs, DERIVATION_COERCIBLE);
 
1556
    sp= new (session->mem) Item_string(" ", 1, cs, DERIVATION_COERCIBLE);
1284
1557
  }
1285
1558
 
1286
1559
  return new (session->mem) Item_func_repeat(*session, sp, arg1);
1288
1561
 
1289
1562
Create_func_unix_timestamp Create_func_unix_timestamp::s_singleton;
1290
1563
 
1291
 
Item* Create_func_unix_timestamp::create_native(Session *session, str_ref name, List<Item> *item_list)
 
1564
Item*
 
1565
Create_func_unix_timestamp::create_native(Session *session, lex_string_t name,
 
1566
                                          List<Item> *item_list)
1292
1567
{
1293
1568
  switch (item_list ? item_list->size() : 0) 
1294
1569
  {
1296
1571
    return new (session->mem) Item_func_unix_timestamp();
1297
1572
  case 1:
1298
1573
    return new (session->mem) Item_func_unix_timestamp(item_list->pop());
 
1574
  default:
 
1575
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1299
1576
  }
1300
 
  my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.data());
1301
1577
  return NULL;
1302
1578
}
1303
1579
 
1388
1664
    FunctionContainer::getMutableMap()[func->name]= func->builder;
1389
1665
}
1390
1666
 
1391
 
Create_func* find_native_function_builder(str_ref name)
 
1667
Create_func* find_native_function_builder(lex_string_t name)
1392
1668
{
1393
 
  return find_ptr2(FunctionContainer::getMap(), name.data());
 
1669
  return find_ptr2(FunctionContainer::getMap(), name.str);
1394
1670
}
1395
1671
 
1396
1672
Item* create_func_char_cast(Session *session, Item *a, int len, const charset_info_st* cs)