~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/create.cc

  • Committer: Brian Aker
  • Date: 2009-08-18 07:20:29 UTC
  • mfrom: (1117.1.9 merge)
  • Revision ID: brian@gaz-20090818072029-s9ch5lcmltxwidn7
Merge of Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/**
17
17
  @file
20
20
  Functions to create an item. Used by sql_yac.yy
21
21
*/
22
22
 
23
 
#include <config.h>
 
23
#include <drizzled/server_includes.h>
24
24
#include <drizzled/item/create.h>
25
25
#include <drizzled/item/func.h>
26
26
#include <drizzled/error.h>
27
27
 
28
 
#include <drizzled/function_container.h>
29
 
 
30
28
#include <drizzled/function/str/binary.h>
31
29
#include <drizzled/function/str/concat.h>
32
30
#include <drizzled/function/str/conv.h>
 
31
#include <drizzled/function/str/elt.h>
33
32
#include <drizzled/function/str/export_set.h>
 
33
#include <drizzled/function/str/format.h>
 
34
#include <drizzled/function/str/hex.h>
34
35
#include <drizzled/function/str/load_file.h>
35
36
#include <drizzled/function/str/make_set.h>
36
37
#include <drizzled/function/str/pad.h>
37
38
#include <drizzled/function/str/repeat.h>
38
39
#include <drizzled/function/str/str_conv.h>
 
40
#include <drizzled/function/str/substr.h>
39
41
#include <drizzled/function/str/trim.h>
 
42
#include <drizzled/function/str/uuid.h>
40
43
 
41
44
#include <drizzled/function/time/date_format.h>
42
45
#include <drizzled/function/time/dayname.h>
55
58
#include <drizzled/function/time/weekday.h>
56
59
 
57
60
#include <drizzled/item/cmpfunc.h>
58
 
#include <drizzled/plugin/function.h>
 
61
#include <drizzled/sql_udf.h>
59
62
#include <drizzled/session.h>
60
63
 
61
64
/* Function declarations */
62
65
 
63
66
#include <drizzled/function/func.h>
 
67
#include <drizzled/function/math/abs.h>
 
68
#include <drizzled/function/math/acos.h>
64
69
#include <drizzled/function/additive_op.h>
 
70
#include <drizzled/function/math/asin.h>
 
71
#include <drizzled/function/math/atan.h>
 
72
#include <drizzled/function/math/ceiling.h>
 
73
#include <drizzled/function/coercibility.h>
 
74
#include <drizzled/function/math/cos.h>
65
75
#include <drizzled/function/math/dec.h>
66
76
#include <drizzled/function/math/decimal_typecast.h>
 
77
#include <drizzled/function/math//exp.h>
67
78
#include <drizzled/function/field.h>
68
79
#include <drizzled/function/find_in_set.h>
 
80
#include <drizzled/function/math/floor.h>
69
81
#include <drizzled/function/found_rows.h>
70
82
#include <drizzled/function/get_system_var.h>
71
83
#include <drizzled/function/math/int_val.h>
72
84
#include <drizzled/function/math/integer.h>
73
85
#include <drizzled/function/last_insert.h>
 
86
#include <drizzled/function/math/ln.h>
74
87
#include <drizzled/function/locate.h>
 
88
#include <drizzled/function/math/log.h>
75
89
#include <drizzled/function/min_max.h>
76
90
#include <drizzled/function/num1.h>
77
91
#include <drizzled/function/num_op.h>
78
92
#include <drizzled/function/numhybrid.h>
 
93
#include <drizzled/function/math/ord.h>
 
94
#include <drizzled/function/math/pow.h>
 
95
#include <drizzled/function/math/rand.h>
79
96
#include <drizzled/function/math/real.h>
80
97
#include <drizzled/function/row_count.h>
81
98
#include <drizzled/function/set_user_var.h>
82
99
#include <drizzled/function/sign.h>
 
100
#include <drizzled/function/signed.h>
 
101
#include <drizzled/function/math/sin.h>
 
102
#include <drizzled/function/math/sqrt.h>
 
103
#include <drizzled/function/str/quote.h>
83
104
#include <drizzled/function/math/tan.h>
84
105
#include <drizzled/function/units.h>
 
106
#include <drizzled/function/unsigned.h>
85
107
 
86
 
#include <drizzled/function/cast/boolean.h>
87
 
#include <drizzled/function/cast/signed.h>
88
 
#include <drizzled/function/cast/time.h>
89
 
#include <drizzled/function/cast/unsigned.h>
 
108
#include <map>
90
109
 
91
110
using namespace std;
92
111
 
93
 
namespace drizzled
94
 
{
95
 
 
96
112
class Item;
97
113
 
98
114
 
245
261
  it helps to compare code between versions, and helps with merges conflicts.
246
262
*/
247
263
 
 
264
class Create_func_abs : public Create_func_arg1
 
265
{
 
266
public:
 
267
  using Create_func_arg1::create;
 
268
 
 
269
  virtual Item *create(Session *session, Item *arg1);
 
270
 
 
271
  static Create_func_abs s_singleton;
 
272
 
 
273
protected:
 
274
  Create_func_abs() {}
 
275
  virtual ~Create_func_abs() {}
 
276
};
 
277
 
 
278
 
 
279
class Create_func_acos : public Create_func_arg1
 
280
{
 
281
public:
 
282
  using Create_func_arg1::create;
 
283
 
 
284
  virtual Item *create(Session *session, Item *arg1);
 
285
 
 
286
  static Create_func_acos s_singleton;
 
287
 
 
288
protected:
 
289
  Create_func_acos() {}
 
290
  virtual ~Create_func_acos() {}
 
291
};
 
292
 
 
293
class Create_func_asin : public Create_func_arg1
 
294
{
 
295
public:
 
296
  using Create_func_arg1::create;
 
297
 
 
298
  virtual Item *create(Session *session, Item *arg1);
 
299
 
 
300
  static Create_func_asin s_singleton;
 
301
 
 
302
protected:
 
303
  Create_func_asin() {}
 
304
  virtual ~Create_func_asin() {}
 
305
};
 
306
 
 
307
 
 
308
class Create_func_atan : public Create_native_func
 
309
{
 
310
public:
 
311
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
 
312
 
 
313
  static Create_func_atan s_singleton;
 
314
 
 
315
protected:
 
316
  Create_func_atan() {}
 
317
  virtual ~Create_func_atan() {}
 
318
};
248
319
 
249
320
class Create_func_bin : public Create_func_arg1
250
321
{
260
331
  virtual ~Create_func_bin() {}
261
332
};
262
333
 
 
334
 
 
335
class Create_func_ceiling : public Create_func_arg1
 
336
{
 
337
public:
 
338
  using Create_func_arg1::create;
 
339
 
 
340
  virtual Item *create(Session *session, Item *arg1);
 
341
 
 
342
  static Create_func_ceiling s_singleton;
 
343
 
 
344
protected:
 
345
  Create_func_ceiling() {}
 
346
  virtual ~Create_func_ceiling() {}
 
347
};
 
348
 
 
349
 
 
350
class Create_func_coercibility : public Create_func_arg1
 
351
{
 
352
public:
 
353
  using Create_func_arg1::create;
 
354
 
 
355
  virtual Item *create(Session *session, Item *arg1);
 
356
 
 
357
  static Create_func_coercibility s_singleton;
 
358
 
 
359
protected:
 
360
  Create_func_coercibility() {}
 
361
  virtual ~Create_func_coercibility() {}
 
362
};
 
363
 
 
364
 
263
365
class Create_func_concat : public Create_native_func
264
366
{
265
367
public:
300
402
  virtual ~Create_func_conv() {}
301
403
};
302
404
 
 
405
 
 
406
class Create_func_cos : public Create_func_arg1
 
407
{
 
408
public:
 
409
  using Create_func_arg1::create;
 
410
 
 
411
  virtual Item *create(Session *session, Item *arg1);
 
412
 
 
413
  static Create_func_cos s_singleton;
 
414
 
 
415
protected:
 
416
  Create_func_cos() {}
 
417
  virtual ~Create_func_cos() {}
 
418
};
 
419
 
 
420
 
303
421
class Create_func_cot : public Create_func_arg1
304
422
{
305
423
public:
433
551
  virtual ~Create_func_degrees() {}
434
552
};
435
553
 
 
554
 
 
555
class Create_func_elt : public Create_native_func
 
556
{
 
557
public:
 
558
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
 
559
 
 
560
  static Create_func_elt s_singleton;
 
561
 
 
562
protected:
 
563
  Create_func_elt() {}
 
564
  virtual ~Create_func_elt() {}
 
565
};
 
566
 
 
567
 
 
568
class Create_func_exp : public Create_func_arg1
 
569
{
 
570
public:
 
571
  using Create_func_arg1::create;
 
572
 
 
573
  virtual Item *create(Session *session, Item *arg1);
 
574
 
 
575
  static Create_func_exp s_singleton;
 
576
 
 
577
protected:
 
578
  Create_func_exp() {}
 
579
  virtual ~Create_func_exp() {}
 
580
};
 
581
 
 
582
 
436
583
class Create_func_export_set : public Create_native_func
437
584
{
438
 
 
439
585
public:
440
586
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
441
587
 
474
620
  virtual ~Create_func_find_in_set() {}
475
621
};
476
622
 
 
623
 
 
624
class Create_func_floor : public Create_func_arg1
 
625
{
 
626
public:
 
627
  using Create_func_arg1::create;
 
628
 
 
629
  virtual Item *create(Session *session, Item *arg1);
 
630
 
 
631
  static Create_func_floor s_singleton;
 
632
 
 
633
protected:
 
634
  Create_func_floor() {}
 
635
  virtual ~Create_func_floor() {}
 
636
};
 
637
 
 
638
 
 
639
class Create_func_format : public Create_func_arg2
 
640
{
 
641
public:
 
642
  using Create_func_arg2::create;
 
643
 
 
644
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
 
645
 
 
646
  static Create_func_format s_singleton;
 
647
 
 
648
protected:
 
649
  Create_func_format() {}
 
650
  virtual ~Create_func_format() {}
 
651
};
 
652
 
 
653
 
477
654
class Create_func_found_rows : public Create_func_arg0
478
655
{
479
656
public:
530
707
};
531
708
 
532
709
 
 
710
class Create_func_hex : public Create_func_arg1
 
711
{
 
712
public:
 
713
  using Create_func_arg1::create;
 
714
 
 
715
  virtual Item *create(Session *session, Item *arg1);
 
716
 
 
717
  static Create_func_hex s_singleton;
 
718
 
 
719
protected:
 
720
  Create_func_hex() {}
 
721
  virtual ~Create_func_hex() {}
 
722
};
 
723
 
 
724
 
533
725
class Create_func_ifnull : public Create_func_arg2
534
726
{
535
727
public:
630
822
  virtual ~Create_func_least() {}
631
823
};
632
824
 
 
825
 
 
826
class Create_func_ln : public Create_func_arg1
 
827
{
 
828
public:
 
829
  using Create_func_arg1::create;
 
830
 
 
831
  virtual Item *create(Session *session, Item *arg1);
 
832
 
 
833
  static Create_func_ln s_singleton;
 
834
 
 
835
protected:
 
836
  Create_func_ln() {}
 
837
  virtual ~Create_func_ln() {}
 
838
};
 
839
 
 
840
 
633
841
class Create_func_load_file : public Create_func_arg1
634
842
{
635
843
public:
658
866
};
659
867
 
660
868
 
 
869
class Create_func_log : public Create_native_func
 
870
{
 
871
public:
 
872
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
 
873
 
 
874
  static Create_func_log s_singleton;
 
875
 
 
876
protected:
 
877
  Create_func_log() {}
 
878
  virtual ~Create_func_log() {}
 
879
};
 
880
 
 
881
 
 
882
class Create_func_log10 : public Create_func_arg1
 
883
{
 
884
public:
 
885
  using Create_func_arg1::create;
 
886
 
 
887
  virtual Item *create(Session *session, Item *arg1);
 
888
 
 
889
  static Create_func_log10 s_singleton;
 
890
 
 
891
protected:
 
892
  Create_func_log10() {}
 
893
  virtual ~Create_func_log10() {}
 
894
};
 
895
 
 
896
 
 
897
class Create_func_log2 : public Create_func_arg1
 
898
{
 
899
public:
 
900
  using Create_func_arg1::create;
 
901
 
 
902
  virtual Item *create(Session *session, Item *arg1);
 
903
 
 
904
  static Create_func_log2 s_singleton;
 
905
 
 
906
protected:
 
907
  Create_func_log2() {}
 
908
  virtual ~Create_func_log2() {}
 
909
};
 
910
 
 
911
 
661
912
class Create_func_lpad : public Create_func_arg3
662
913
{
663
914
public:
774
1025
  virtual ~Create_func_oct() {}
775
1026
};
776
1027
 
 
1028
 
 
1029
class Create_func_ord : public Create_func_arg1
 
1030
{
 
1031
public:
 
1032
  using Create_func_arg1::create;
 
1033
 
 
1034
  virtual Item *create(Session *session, Item *arg1);
 
1035
 
 
1036
  static Create_func_ord s_singleton;
 
1037
 
 
1038
protected:
 
1039
  Create_func_ord() {}
 
1040
  virtual ~Create_func_ord() {}
 
1041
};
 
1042
 
 
1043
 
777
1044
class Create_func_period_add : public Create_func_arg2
778
1045
{
779
1046
public:
818
1085
  virtual ~Create_func_pi() {}
819
1086
};
820
1087
 
 
1088
 
 
1089
class Create_func_pow : public Create_func_arg2
 
1090
{
 
1091
public:
 
1092
  using Create_func_arg2::create;
 
1093
 
 
1094
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
 
1095
 
 
1096
  static Create_func_pow s_singleton;
 
1097
 
 
1098
protected:
 
1099
  Create_func_pow() {}
 
1100
  virtual ~Create_func_pow() {}
 
1101
};
 
1102
 
 
1103
 
 
1104
class Create_func_quote : public Create_func_arg1
 
1105
{
 
1106
public:
 
1107
  using Create_func_arg1::create;
 
1108
 
 
1109
  virtual Item *create(Session *session, Item *arg1);
 
1110
 
 
1111
  static Create_func_quote s_singleton;
 
1112
 
 
1113
protected:
 
1114
  Create_func_quote() {}
 
1115
  virtual ~Create_func_quote() {}
 
1116
};
 
1117
 
 
1118
 
821
1119
class Create_func_radians : public Create_func_arg1
822
1120
{
823
1121
public:
833
1131
};
834
1132
 
835
1133
 
 
1134
class Create_func_rand : public Create_native_func
 
1135
{
 
1136
public:
 
1137
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
 
1138
 
 
1139
  static Create_func_rand s_singleton;
 
1140
 
 
1141
protected:
 
1142
  Create_func_rand() {}
 
1143
  virtual ~Create_func_rand() {}
 
1144
};
 
1145
 
 
1146
 
836
1147
class Create_func_round : public Create_native_func
837
1148
{
838
1149
public:
904
1215
  virtual ~Create_func_sign() {}
905
1216
};
906
1217
 
 
1218
 
 
1219
class Create_func_sin : public Create_func_arg1
 
1220
{
 
1221
public:
 
1222
  using Create_func_arg1::create;
 
1223
 
 
1224
  virtual Item *create(Session *session, Item *arg1);
 
1225
 
 
1226
  static Create_func_sin s_singleton;
 
1227
 
 
1228
protected:
 
1229
  Create_func_sin() {}
 
1230
  virtual ~Create_func_sin() {}
 
1231
};
 
1232
 
 
1233
 
907
1234
class Create_func_space : public Create_func_arg1
908
1235
{
909
1236
public:
918
1245
  virtual ~Create_func_space() {}
919
1246
};
920
1247
 
 
1248
 
 
1249
class Create_func_sqrt : public Create_func_arg1
 
1250
{
 
1251
public:
 
1252
  using Create_func_arg1::create;
 
1253
 
 
1254
  virtual Item *create(Session *session, Item *arg1);
 
1255
 
 
1256
  static Create_func_sqrt s_singleton;
 
1257
 
 
1258
protected:
 
1259
  Create_func_sqrt() {}
 
1260
  virtual ~Create_func_sqrt() {}
 
1261
};
 
1262
 
 
1263
 
921
1264
class Create_func_strcmp : public Create_func_arg2
922
1265
{
923
1266
public:
933
1276
};
934
1277
 
935
1278
 
 
1279
class Create_func_substr_index : public Create_func_arg3
 
1280
{
 
1281
public:
 
1282
  using Create_func_arg3::create;
 
1283
 
 
1284
  virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3);
 
1285
 
 
1286
  static Create_func_substr_index s_singleton;
 
1287
 
 
1288
protected:
 
1289
  Create_func_substr_index() {}
 
1290
  virtual ~Create_func_substr_index() {}
 
1291
};
 
1292
 
 
1293
 
936
1294
class Create_func_tan : public Create_func_arg1
937
1295
{
938
1296
public:
1008
1366
};
1009
1367
 
1010
1368
 
 
1369
class Create_func_unhex : public Create_func_arg1
 
1370
{
 
1371
public:
 
1372
  using Create_func_arg1::create;
 
1373
 
 
1374
  virtual Item *create(Session *session, Item *arg1);
 
1375
 
 
1376
  static Create_func_unhex s_singleton;
 
1377
 
 
1378
protected:
 
1379
  Create_func_unhex() {}
 
1380
  virtual ~Create_func_unhex() {}
 
1381
};
 
1382
 
 
1383
 
1011
1384
class Create_func_unix_timestamp : public Create_native_func
1012
1385
{
1013
1386
public:
1021
1394
};
1022
1395
 
1023
1396
 
 
1397
class Create_func_uuid : public Create_func_arg0
 
1398
{
 
1399
public:
 
1400
  using Create_func_arg0::create;
 
1401
 
 
1402
  virtual Item *create(Session *session);
 
1403
 
 
1404
  static Create_func_uuid s_singleton;
 
1405
 
 
1406
protected:
 
1407
  Create_func_uuid() {}
 
1408
  virtual ~Create_func_uuid() {}
 
1409
};
 
1410
 
 
1411
 
1024
1412
class Create_func_weekday : public Create_func_arg1
1025
1413
{
1026
1414
public:
1053
1441
  if (params)
1054
1442
  {
1055
1443
    Item *param;
1056
 
    List<Item>::iterator it(params->begin());
 
1444
    List_iterator<Item> it(*params);
1057
1445
    while ((param= it++))
1058
1446
    {
1059
1447
      if (! param->is_autogenerated_name)
1070
1458
Item*
1071
1459
Create_udf_func::create(Session *session, LEX_STRING name, List<Item> *item_list)
1072
1460
{
1073
 
  const plugin::Function *udf= plugin::Function::get(name.str, name.length);
 
1461
  Function_builder *udf= find_udf(name.str, name.length);
1074
1462
  assert(udf);
1075
1463
  return create(session, udf, item_list);
1076
1464
}
1077
1465
 
1078
1466
 
1079
1467
Item*
1080
 
Create_udf_func::create(Session *session, const plugin::Function *udf,
 
1468
Create_udf_func::create(Session *session, Function_builder *udf,
1081
1469
                        List<Item> *item_list)
1082
1470
{
1083
1471
  Item_func *func= NULL;
1090
1478
 
1091
1479
  if(!func->check_argument_count(arg_count))
1092
1480
  {
1093
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), func->func_name());
 
1481
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), func->func_name());
1094
1482
    return NULL;
1095
1483
  }
1096
1484
 
1124
1512
 
1125
1513
  if (arg_count != 0)
1126
1514
  {
1127
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1515
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1128
1516
    return NULL;
1129
1517
  }
1130
1518
 
1142
1530
 
1143
1531
  if (arg_count != 1)
1144
1532
  {
1145
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1533
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1146
1534
    return NULL;
1147
1535
  }
1148
1536
 
1168
1556
 
1169
1557
  if (arg_count != 2)
1170
1558
  {
1171
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1559
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1172
1560
    return NULL;
1173
1561
  }
1174
1562
 
1196
1584
 
1197
1585
  if (arg_count != 3)
1198
1586
  {
1199
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1587
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1200
1588
    return NULL;
1201
1589
  }
1202
1590
 
1215
1603
  return create(session, param_1, param_2, param_3);
1216
1604
}
1217
1605
 
 
1606
 
 
1607
Create_func_abs Create_func_abs::s_singleton;
 
1608
 
 
1609
Item*
 
1610
Create_func_abs::create(Session *session, Item *arg1)
 
1611
{
 
1612
  return new (session->mem_root) Item_func_abs(arg1);
 
1613
}
 
1614
 
 
1615
 
 
1616
Create_func_acos Create_func_acos::s_singleton;
 
1617
 
 
1618
Item*
 
1619
Create_func_acos::create(Session *session, Item *arg1)
 
1620
{
 
1621
  return new (session->mem_root) Item_func_acos(arg1);
 
1622
}
 
1623
 
 
1624
Create_func_asin Create_func_asin::s_singleton;
 
1625
 
 
1626
Item*
 
1627
Create_func_asin::create(Session *session, Item *arg1)
 
1628
{
 
1629
  return new (session->mem_root) Item_func_asin(arg1);
 
1630
}
 
1631
 
 
1632
 
 
1633
Create_func_atan Create_func_atan::s_singleton;
 
1634
 
 
1635
Item*
 
1636
Create_func_atan::create_native(Session *session, LEX_STRING name,
 
1637
                                List<Item> *item_list)
 
1638
{
 
1639
  Item* func= NULL;
 
1640
  int arg_count= 0;
 
1641
 
 
1642
  if (item_list != NULL)
 
1643
    arg_count= item_list->elements;
 
1644
 
 
1645
  switch (arg_count) {
 
1646
  case 1:
 
1647
  {
 
1648
    Item *param_1= item_list->pop();
 
1649
    func= new (session->mem_root) Item_func_atan(param_1);
 
1650
    break;
 
1651
  }
 
1652
  case 2:
 
1653
  {
 
1654
    Item *param_1= item_list->pop();
 
1655
    Item *param_2= item_list->pop();
 
1656
    func= new (session->mem_root) Item_func_atan(param_1, param_2);
 
1657
    break;
 
1658
  }
 
1659
  default:
 
1660
  {
 
1661
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
1662
    break;
 
1663
  }
 
1664
  }
 
1665
 
 
1666
  return func;
 
1667
}
 
1668
 
1218
1669
Create_func_bin Create_func_bin::s_singleton;
1219
1670
 
1220
1671
Item*
1225
1676
  return new (session->mem_root) Item_func_conv(arg1, i10, i2);
1226
1677
}
1227
1678
 
 
1679
 
 
1680
Create_func_ceiling Create_func_ceiling::s_singleton;
 
1681
 
 
1682
Item*
 
1683
Create_func_ceiling::create(Session *session, Item *arg1)
 
1684
{
 
1685
  return new (session->mem_root) Item_func_ceiling(arg1);
 
1686
}
 
1687
 
 
1688
 
 
1689
Create_func_coercibility Create_func_coercibility::s_singleton;
 
1690
 
 
1691
Item*
 
1692
Create_func_coercibility::create(Session *session, Item *arg1)
 
1693
{
 
1694
  return new (session->mem_root) Item_func_coercibility(arg1);
 
1695
}
 
1696
 
 
1697
 
1228
1698
Create_func_concat Create_func_concat::s_singleton;
1229
1699
 
1230
1700
Item*
1238
1708
 
1239
1709
  if (arg_count < 1)
1240
1710
  {
1241
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1711
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1242
1712
    return NULL;
1243
1713
  }
1244
1714
 
1245
 
  return new (session->mem_root) Item_func_concat(*session, *item_list);
 
1715
  return new (session->mem_root) Item_func_concat(*item_list);
1246
1716
}
1247
1717
 
1248
1718
 
1260
1730
  /* "WS" stands for "With Separator": this function takes 2+ arguments */
1261
1731
  if (arg_count < 2)
1262
1732
  {
1263
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1733
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1264
1734
    return NULL;
1265
1735
  }
1266
1736
 
1267
 
  return new (session->mem_root) Item_func_concat_ws(*session, *item_list);
 
1737
  return new (session->mem_root) Item_func_concat_ws(*item_list);
1268
1738
}
1269
1739
 
1270
1740
 
1276
1746
  return new (session->mem_root) Item_func_conv(arg1, arg2, arg3);
1277
1747
}
1278
1748
 
 
1749
 
 
1750
Create_func_cos Create_func_cos::s_singleton;
 
1751
 
 
1752
Item*
 
1753
Create_func_cos::create(Session *session, Item *arg1)
 
1754
{
 
1755
  return new (session->mem_root) Item_func_cos(arg1);
 
1756
}
 
1757
 
 
1758
 
1279
1759
Create_func_cot Create_func_cot::s_singleton;
1280
1760
 
1281
1761
Item*
1283
1763
{
1284
1764
  Item *i1= new (session->mem_root) Item_int((char*) "1", 1, 1);
1285
1765
  Item *i2= new (session->mem_root) Item_func_tan(arg1);
1286
 
  return new (session->mem_root) Item_func_div(session, i1, i2);
 
1766
  return new (session->mem_root) Item_func_div(i1, i2);
1287
1767
}
1288
1768
 
1289
1769
Create_func_date_format Create_func_date_format::s_singleton;
1352
1832
                                             180/M_PI, 0.0);
1353
1833
}
1354
1834
 
 
1835
 
 
1836
Create_func_elt Create_func_elt::s_singleton;
 
1837
 
 
1838
Item*
 
1839
Create_func_elt::create_native(Session *session, LEX_STRING name,
 
1840
                               List<Item> *item_list)
 
1841
{
 
1842
  int arg_count= 0;
 
1843
 
 
1844
  if (item_list != NULL)
 
1845
    arg_count= item_list->elements;
 
1846
 
 
1847
  if (arg_count < 2)
 
1848
  {
 
1849
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
1850
    return NULL;
 
1851
  }
 
1852
 
 
1853
  return new (session->mem_root) Item_func_elt(*item_list);
 
1854
}
 
1855
 
 
1856
 
 
1857
Create_func_exp Create_func_exp::s_singleton;
 
1858
 
 
1859
Item*
 
1860
Create_func_exp::create(Session *session, Item *arg1)
 
1861
{
 
1862
  return new (session->mem_root) Item_func_exp(arg1);
 
1863
}
 
1864
 
 
1865
 
1355
1866
Create_func_export_set Create_func_export_set::s_singleton;
1356
1867
 
1357
1868
Item*
1396
1907
  }
1397
1908
  default:
1398
1909
  {
1399
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1910
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1400
1911
    break;
1401
1912
  }
1402
1913
  }
1418
1929
 
1419
1930
  if (arg_count < 2)
1420
1931
  {
1421
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1932
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1422
1933
    return NULL;
1423
1934
  }
1424
1935
 
1434
1945
  return new (session->mem_root) Item_func_find_in_set(arg1, arg2);
1435
1946
}
1436
1947
 
 
1948
 
 
1949
Create_func_floor Create_func_floor::s_singleton;
 
1950
 
 
1951
Item*
 
1952
Create_func_floor::create(Session *session, Item *arg1)
 
1953
{
 
1954
  return new (session->mem_root) Item_func_floor(arg1);
 
1955
}
 
1956
 
 
1957
 
 
1958
Create_func_format Create_func_format::s_singleton;
 
1959
 
 
1960
Item*
 
1961
Create_func_format::create(Session *session, Item *arg1, Item *arg2)
 
1962
{
 
1963
  return new (session->mem_root) Item_func_format(arg1, arg2);
 
1964
}
 
1965
 
 
1966
 
1437
1967
Create_func_found_rows Create_func_found_rows::s_singleton;
1438
1968
 
1439
1969
Item*
1481
2011
  }
1482
2012
  default:
1483
2013
  {
1484
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2014
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1485
2015
    break;
1486
2016
  }
1487
2017
  }
1503
2033
 
1504
2034
  if (arg_count < 2)
1505
2035
  {
1506
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2036
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1507
2037
    return NULL;
1508
2038
  }
1509
2039
 
1510
2040
  return new (session->mem_root) Item_func_max(*item_list);
1511
2041
}
1512
2042
 
 
2043
 
 
2044
Create_func_hex Create_func_hex::s_singleton;
 
2045
 
 
2046
Item*
 
2047
Create_func_hex::create(Session *session, Item *arg1)
 
2048
{
 
2049
  return new (session->mem_root) Item_func_hex(arg1);
 
2050
}
 
2051
 
 
2052
 
1513
2053
Create_func_ifnull Create_func_ifnull::s_singleton;
1514
2054
 
1515
2055
Item*
1572
2112
  }
1573
2113
  default:
1574
2114
  {
1575
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2115
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1576
2116
    break;
1577
2117
  }
1578
2118
  }
1603
2143
 
1604
2144
  if (arg_count < 2)
1605
2145
  {
1606
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2146
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1607
2147
    return NULL;
1608
2148
  }
1609
2149
 
1610
2150
  return new (session->mem_root) Item_func_min(*item_list);
1611
2151
}
1612
2152
 
 
2153
 
 
2154
Create_func_ln Create_func_ln::s_singleton;
 
2155
 
 
2156
Item*
 
2157
Create_func_ln::create(Session *session, Item *arg1)
 
2158
{
 
2159
  return new (session->mem_root) Item_func_ln(arg1);
 
2160
}
 
2161
 
 
2162
 
1613
2163
Create_func_load_file Create_func_load_file::s_singleton;
1614
2164
 
1615
2165
Item*
1616
2166
Create_func_load_file::create(Session *session, Item *arg1)
1617
2167
{
1618
 
  return new (session->mem_root) Item_load_file(*session, arg1);
 
2168
  return new (session->mem_root) Item_load_file(arg1);
1619
2169
}
1620
2170
 
1621
2171
 
1651
2201
  }
1652
2202
  default:
1653
2203
  {
1654
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1655
 
    break;
1656
 
  }
1657
 
  }
1658
 
 
1659
 
  return func;
1660
 
}
 
2204
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2205
    break;
 
2206
  }
 
2207
  }
 
2208
 
 
2209
  return func;
 
2210
}
 
2211
 
 
2212
 
 
2213
Create_func_log Create_func_log::s_singleton;
 
2214
 
 
2215
Item*
 
2216
Create_func_log::create_native(Session *session, LEX_STRING name,
 
2217
                               List<Item> *item_list)
 
2218
{
 
2219
  Item *func= NULL;
 
2220
  int arg_count= 0;
 
2221
 
 
2222
  if (item_list != NULL)
 
2223
    arg_count= item_list->elements;
 
2224
 
 
2225
  switch (arg_count) {
 
2226
  case 1:
 
2227
  {
 
2228
    Item *param_1= item_list->pop();
 
2229
    func= new (session->mem_root) Item_func_log(param_1);
 
2230
    break;
 
2231
  }
 
2232
  case 2:
 
2233
  {
 
2234
    Item *param_1= item_list->pop();
 
2235
    Item *param_2= item_list->pop();
 
2236
    func= new (session->mem_root) Item_func_log(param_1, param_2);
 
2237
    break;
 
2238
  }
 
2239
  default:
 
2240
  {
 
2241
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2242
    break;
 
2243
  }
 
2244
  }
 
2245
 
 
2246
  return func;
 
2247
}
 
2248
 
 
2249
 
 
2250
Create_func_log10 Create_func_log10::s_singleton;
 
2251
 
 
2252
Item*
 
2253
Create_func_log10::create(Session *session, Item *arg1)
 
2254
{
 
2255
  return new (session->mem_root) Item_func_log10(arg1);
 
2256
}
 
2257
 
 
2258
 
 
2259
Create_func_log2 Create_func_log2::s_singleton;
 
2260
 
 
2261
Item*
 
2262
Create_func_log2::create(Session *session, Item *arg1)
 
2263
{
 
2264
  return new (session->mem_root) Item_func_log2(arg1);
 
2265
}
 
2266
 
1661
2267
 
1662
2268
Create_func_lpad Create_func_lpad::s_singleton;
1663
2269
 
1664
2270
Item*
1665
2271
Create_func_lpad::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
1666
2272
{
1667
 
  return new (session->mem_root) Item_func_lpad(*session, arg1, arg2, arg3);
 
2273
  return new (session->mem_root) Item_func_lpad(arg1, arg2, arg3);
1668
2274
}
1669
2275
 
1670
2276
 
1689
2295
Create_func_make_set Create_func_make_set::s_singleton;
1690
2296
 
1691
2297
Item*
1692
 
Create_func_make_set::create_native(Session *session_arg, LEX_STRING name,
 
2298
Create_func_make_set::create_native(Session *session, LEX_STRING name,
1693
2299
                                    List<Item> *item_list)
1694
2300
{
1695
2301
  int arg_count= 0;
1699
2305
 
1700
2306
  if (arg_count < 2)
1701
2307
  {
1702
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2308
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1703
2309
    return NULL;
1704
2310
  }
1705
2311
 
1706
2312
  Item *param_1= item_list->pop();
1707
 
  return new (session_arg->mem_root) Item_func_make_set(*session_arg, param_1, *item_list);
 
2313
  return new (session->mem_root) Item_func_make_set(param_1, *item_list);
1708
2314
}
1709
2315
 
1710
2316
 
1736
2342
  return new (session->mem_root) Item_func_conv(arg1, i10, i8);
1737
2343
}
1738
2344
 
 
2345
 
 
2346
Create_func_ord Create_func_ord::s_singleton;
 
2347
 
 
2348
Item*
 
2349
Create_func_ord::create(Session *session, Item *arg1)
 
2350
{
 
2351
  return new (session->mem_root) Item_func_ord(arg1);
 
2352
}
 
2353
 
 
2354
 
1739
2355
Create_func_period_add Create_func_period_add::s_singleton;
1740
2356
 
1741
2357
Item*
1762
2378
  return new (session->mem_root) Item_static_float_func("pi()", M_PI, 6, 8);
1763
2379
}
1764
2380
 
 
2381
 
 
2382
Create_func_pow Create_func_pow::s_singleton;
 
2383
 
 
2384
Item*
 
2385
Create_func_pow::create(Session *session, Item *arg1, Item *arg2)
 
2386
{
 
2387
  return new (session->mem_root) Item_func_pow(arg1, arg2);
 
2388
}
 
2389
 
 
2390
 
 
2391
Create_func_quote Create_func_quote::s_singleton;
 
2392
 
 
2393
Item*
 
2394
Create_func_quote::create(Session *session, Item *arg1)
 
2395
{
 
2396
  return new (session->mem_root) Item_func_quote(arg1);
 
2397
}
 
2398
 
 
2399
 
1765
2400
Create_func_radians Create_func_radians::s_singleton;
1766
2401
 
1767
2402
Item*
1771
2406
                                             M_PI/180, 0.0);
1772
2407
}
1773
2408
 
 
2409
 
 
2410
Create_func_rand Create_func_rand::s_singleton;
 
2411
 
 
2412
Item*
 
2413
Create_func_rand::create_native(Session *session, LEX_STRING name,
 
2414
                                List<Item> *item_list)
 
2415
{
 
2416
  Item *func= NULL;
 
2417
  int arg_count= 0;
 
2418
 
 
2419
  if (item_list != NULL)
 
2420
    arg_count= item_list->elements;
 
2421
 
 
2422
  switch (arg_count) {
 
2423
  case 0:
 
2424
  {
 
2425
    func= new (session->mem_root) Item_func_rand();
 
2426
    break;
 
2427
  }
 
2428
  case 1:
 
2429
  {
 
2430
    Item *param_1= item_list->pop();
 
2431
    func= new (session->mem_root) Item_func_rand(param_1);
 
2432
    break;
 
2433
  }
 
2434
  default:
 
2435
  {
 
2436
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2437
    break;
 
2438
  }
 
2439
  }
 
2440
 
 
2441
  return func;
 
2442
}
 
2443
 
 
2444
 
1774
2445
Create_func_round Create_func_round::s_singleton;
1775
2446
 
1776
2447
Item*
1800
2471
  }
1801
2472
  default:
1802
2473
  {
1803
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2474
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1804
2475
    break;
1805
2476
  }
1806
2477
  }
1823
2494
Item*
1824
2495
Create_func_rpad::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
1825
2496
{
1826
 
  return new (session->mem_root) Item_func_rpad(*session, arg1, arg2, arg3);
 
2497
  return new (session->mem_root) Item_func_rpad(arg1, arg2, arg3);
1827
2498
}
1828
2499
 
1829
2500
 
1844
2515
  return new (session->mem_root) Item_func_sign(arg1);
1845
2516
}
1846
2517
 
 
2518
 
 
2519
Create_func_sin Create_func_sin::s_singleton;
 
2520
 
 
2521
Item*
 
2522
Create_func_sin::create(Session *session, Item *arg1)
 
2523
{
 
2524
  return new (session->mem_root) Item_func_sin(arg1);
 
2525
}
 
2526
 
 
2527
 
1847
2528
Create_func_space Create_func_space::s_singleton;
1848
2529
 
1849
2530
Item*
1859
2540
 
1860
2541
  if (cs->mbminlen > 1)
1861
2542
  {
1862
 
    size_t dummy_errors;
 
2543
    uint32_t dummy_errors;
1863
2544
    sp= new (session->mem_root) Item_string("", 0, cs, DERIVATION_COERCIBLE);
1864
2545
    sp->str_value.copy(" ", 1, &my_charset_utf8_general_ci, cs, &dummy_errors);
1865
2546
  }
1868
2549
    sp= new (session->mem_root) Item_string(" ", 1, cs, DERIVATION_COERCIBLE);
1869
2550
  }
1870
2551
 
1871
 
  return new (session->mem_root) Item_func_repeat(*session, sp, arg1);
1872
 
}
 
2552
  return new (session->mem_root) Item_func_repeat(sp, arg1);
 
2553
}
 
2554
 
 
2555
 
 
2556
Create_func_sqrt Create_func_sqrt::s_singleton;
 
2557
 
 
2558
Item*
 
2559
Create_func_sqrt::create(Session *session, Item *arg1)
 
2560
{
 
2561
  return new (session->mem_root) Item_func_sqrt(arg1);
 
2562
}
 
2563
 
1873
2564
 
1874
2565
Create_func_strcmp Create_func_strcmp::s_singleton;
1875
2566
 
1880
2571
}
1881
2572
 
1882
2573
 
 
2574
Create_func_substr_index Create_func_substr_index::s_singleton;
 
2575
 
 
2576
Item*
 
2577
Create_func_substr_index::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
 
2578
{
 
2579
  return new (session->mem_root) Item_func_substr_index(arg1, arg2, arg3);
 
2580
}
 
2581
 
1883
2582
Create_func_tan Create_func_tan::s_singleton;
1884
2583
 
1885
2584
Item*
1914
2613
  return new (session->mem_root) Item_func_ucase(arg1);
1915
2614
}
1916
2615
 
 
2616
 
 
2617
Create_func_unhex Create_func_unhex::s_singleton;
 
2618
 
 
2619
Item*
 
2620
Create_func_unhex::create(Session *session, Item *arg1)
 
2621
{
 
2622
  return new (session->mem_root) Item_func_unhex(arg1);
 
2623
}
 
2624
 
 
2625
 
1917
2626
Create_func_unix_timestamp Create_func_unix_timestamp::s_singleton;
1918
2627
 
1919
2628
Item*
1940
2649
  }
1941
2650
  default:
1942
2651
  {
1943
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2652
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1944
2653
    break;
1945
2654
  }
1946
2655
  }
1949
2658
}
1950
2659
 
1951
2660
 
 
2661
Create_func_uuid Create_func_uuid::s_singleton;
 
2662
 
 
2663
Item*
 
2664
Create_func_uuid::create(Session *session)
 
2665
{
 
2666
  return new (session->mem_root) Item_func_uuid();
 
2667
}
 
2668
 
 
2669
 
1952
2670
Create_func_weekday Create_func_weekday::s_singleton;
1953
2671
 
1954
2672
Item*
1974
2692
 
1975
2693
static Native_func_registry func_array[] =
1976
2694
{
 
2695
  { { C_STRING_WITH_LEN("ABS") }, BUILDER(Create_func_abs)},
 
2696
  { { C_STRING_WITH_LEN("ACOS") }, BUILDER(Create_func_acos)},
 
2697
  { { C_STRING_WITH_LEN("ASIN") }, BUILDER(Create_func_asin)},
 
2698
  { { C_STRING_WITH_LEN("ATAN") }, BUILDER(Create_func_atan)},
 
2699
  { { C_STRING_WITH_LEN("ATAN2") }, BUILDER(Create_func_atan)},
1977
2700
  { { C_STRING_WITH_LEN("BIN") }, BUILDER(Create_func_bin)},
 
2701
  { { C_STRING_WITH_LEN("CEIL") }, BUILDER(Create_func_ceiling)},
 
2702
  { { C_STRING_WITH_LEN("CEILING") }, BUILDER(Create_func_ceiling)},
 
2703
  { { C_STRING_WITH_LEN("COERCIBILITY") }, BUILDER(Create_func_coercibility)},
1978
2704
  { { C_STRING_WITH_LEN("CONCAT") }, BUILDER(Create_func_concat)},
1979
2705
  { { C_STRING_WITH_LEN("CONCAT_WS") }, BUILDER(Create_func_concat_ws)},
1980
2706
  { { C_STRING_WITH_LEN("CONV") }, BUILDER(Create_func_conv)},
 
2707
  { { C_STRING_WITH_LEN("COS") }, BUILDER(Create_func_cos)},
1981
2708
  { { C_STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)},
1982
2709
  { { C_STRING_WITH_LEN("DATEDIFF") }, BUILDER(Create_func_datediff)},
1983
2710
  { { C_STRING_WITH_LEN("DATE_FORMAT") }, BUILDER(Create_func_date_format)},
1986
2713
  { { C_STRING_WITH_LEN("DAYOFWEEK") }, BUILDER(Create_func_dayofweek)},
1987
2714
  { { C_STRING_WITH_LEN("DAYOFYEAR") }, BUILDER(Create_func_dayofyear)},
1988
2715
  { { C_STRING_WITH_LEN("DEGREES") }, BUILDER(Create_func_degrees)},
 
2716
  { { C_STRING_WITH_LEN("ELT") }, BUILDER(Create_func_elt)},
 
2717
  { { C_STRING_WITH_LEN("EXP") }, BUILDER(Create_func_exp)},
1989
2718
  { { C_STRING_WITH_LEN("EXPORT_SET") }, BUILDER(Create_func_export_set)},
1990
2719
  { { C_STRING_WITH_LEN("FIELD") }, BUILDER(Create_func_field)},
1991
2720
  { { C_STRING_WITH_LEN("FIND_IN_SET") }, BUILDER(Create_func_find_in_set)},
 
2721
  { { C_STRING_WITH_LEN("FLOOR") }, BUILDER(Create_func_floor)},
 
2722
  { { C_STRING_WITH_LEN("FORMAT") }, BUILDER(Create_func_format)},
1992
2723
  { { C_STRING_WITH_LEN("FOUND_ROWS") }, BUILDER(Create_func_found_rows)},
1993
2724
  { { C_STRING_WITH_LEN("FROM_DAYS") }, BUILDER(Create_func_from_days)},
1994
2725
  { { C_STRING_WITH_LEN("FROM_UNIXTIME") }, BUILDER(Create_func_from_unixtime)},
1995
2726
  { { C_STRING_WITH_LEN("GREATEST") }, BUILDER(Create_func_greatest)},
 
2727
  { { C_STRING_WITH_LEN("HEX") }, BUILDER(Create_func_hex)},
1996
2728
  { { C_STRING_WITH_LEN("IFNULL") }, BUILDER(Create_func_ifnull)},
1997
2729
  { { C_STRING_WITH_LEN("INSTR") }, BUILDER(Create_func_instr)},
1998
2730
  { { C_STRING_WITH_LEN("ISNULL") }, BUILDER(Create_func_isnull)},
2000
2732
  { { C_STRING_WITH_LEN("LAST_INSERT_ID") }, BUILDER(Create_func_last_insert_id)},
2001
2733
  { { C_STRING_WITH_LEN("LCASE") }, BUILDER(Create_func_lcase)},
2002
2734
  { { C_STRING_WITH_LEN("LEAST") }, BUILDER(Create_func_least)},
 
2735
  { { C_STRING_WITH_LEN("LN") }, BUILDER(Create_func_ln)},
2003
2736
  { { C_STRING_WITH_LEN("LOAD_FILE") }, BUILDER(Create_func_load_file)},
2004
2737
  { { C_STRING_WITH_LEN("LOCATE") }, BUILDER(Create_func_locate)},
 
2738
  { { C_STRING_WITH_LEN("LOG") }, BUILDER(Create_func_log)},
 
2739
  { { C_STRING_WITH_LEN("LOG10") }, BUILDER(Create_func_log10)},
 
2740
  { { C_STRING_WITH_LEN("LOG2") }, BUILDER(Create_func_log2)},
2005
2741
  { { C_STRING_WITH_LEN("LOWER") }, BUILDER(Create_func_lcase)},
2006
2742
  { { C_STRING_WITH_LEN("LPAD") }, BUILDER(Create_func_lpad)},
2007
2743
  { { C_STRING_WITH_LEN("LTRIM") }, BUILDER(Create_func_ltrim)},
2010
2746
  { { C_STRING_WITH_LEN("MONTHNAME") }, BUILDER(Create_func_monthname)},
2011
2747
  { { C_STRING_WITH_LEN("NULLIF") }, BUILDER(Create_func_nullif)},
2012
2748
  { { C_STRING_WITH_LEN("OCT") }, BUILDER(Create_func_oct)},
 
2749
  { { C_STRING_WITH_LEN("ORD") }, BUILDER(Create_func_ord)},
2013
2750
  { { C_STRING_WITH_LEN("PERIOD_ADD") }, BUILDER(Create_func_period_add)},
2014
2751
  { { C_STRING_WITH_LEN("PERIOD_DIFF") }, BUILDER(Create_func_period_diff)},
2015
2752
  { { C_STRING_WITH_LEN("PI") }, BUILDER(Create_func_pi)},
 
2753
  { { C_STRING_WITH_LEN("POW") }, BUILDER(Create_func_pow)},
 
2754
  { { C_STRING_WITH_LEN("POWER") }, BUILDER(Create_func_pow)},
 
2755
  { { C_STRING_WITH_LEN("QUOTE") }, BUILDER(Create_func_quote)},
2016
2756
  { { C_STRING_WITH_LEN("RADIANS") }, BUILDER(Create_func_radians)},
 
2757
  { { C_STRING_WITH_LEN("RAND") }, BUILDER(Create_func_rand)},
2017
2758
  { { C_STRING_WITH_LEN("ROUND") }, BUILDER(Create_func_round)},
2018
2759
  { { C_STRING_WITH_LEN("ROW_COUNT") }, BUILDER(Create_func_row_count)},
2019
2760
  { { C_STRING_WITH_LEN("RPAD") }, BUILDER(Create_func_rpad)},
2020
2761
  { { C_STRING_WITH_LEN("RTRIM") }, BUILDER(Create_func_rtrim)},
2021
2762
  { { C_STRING_WITH_LEN("SIGN") }, BUILDER(Create_func_sign)},
 
2763
  { { C_STRING_WITH_LEN("SIN") }, BUILDER(Create_func_sin)},
2022
2764
  { { C_STRING_WITH_LEN("SPACE") }, BUILDER(Create_func_space)},
 
2765
  { { C_STRING_WITH_LEN("SQRT") }, BUILDER(Create_func_sqrt)},
2023
2766
  { { C_STRING_WITH_LEN("STRCMP") }, BUILDER(Create_func_strcmp)},
 
2767
  { { C_STRING_WITH_LEN("SUBSTRING_INDEX") }, BUILDER(Create_func_substr_index)},
2024
2768
  { { C_STRING_WITH_LEN("TAN") }, BUILDER(Create_func_tan)},
2025
2769
  { { C_STRING_WITH_LEN("TIME_FORMAT") }, BUILDER(Create_func_time_format)},
2026
2770
  { { C_STRING_WITH_LEN("TO_DAYS") }, BUILDER(Create_func_to_days)},
2027
2771
  { { C_STRING_WITH_LEN("UCASE") }, BUILDER(Create_func_ucase)},
 
2772
  { { C_STRING_WITH_LEN("UNHEX") }, BUILDER(Create_func_unhex)},
2028
2773
  { { C_STRING_WITH_LEN("UNIX_TIMESTAMP") }, BUILDER(Create_func_unix_timestamp)},
2029
2774
  { { C_STRING_WITH_LEN("UPPER") }, BUILDER(Create_func_ucase)},
 
2775
  { { C_STRING_WITH_LEN("UUID") }, BUILDER(Create_func_uuid)},
2030
2776
  { { C_STRING_WITH_LEN("WEEKDAY") }, BUILDER(Create_func_weekday)},
2031
2777
 
2032
2778
  { {0, 0}, NULL}
2033
2779
};
2034
2780
 
 
2781
static map<string, Native_func_registry *> native_functions_map;
 
2782
 
2035
2783
/*
2036
2784
  Load the hash table for native functions.
2037
2785
  Note: this code is not thread safe, and is intended to be used at server
2046
2794
  for (func= func_array; func->builder != NULL; func++)
2047
2795
  {
2048
2796
    func_name.assign(func->name.str, func->name.length);
 
2797
    transform(func_name.begin(), func_name.end(), func_name.begin(), ::tolower);
2049
2798
 
2050
 
    FunctionContainer::getMap()[func_name]= func->builder;
 
2799
    native_functions_map[func_name]= func;
2051
2800
  }
2052
2801
 
2053
2802
  return 0;
2057
2806
Create_func *
2058
2807
find_native_function_builder(LEX_STRING name)
2059
2808
{
 
2809
  Native_func_registry *func;
2060
2810
  Create_func *builder= NULL;
2061
2811
 
2062
2812
  string func_name(name.str, name.length);
2063
 
 
2064
 
  FunctionContainer::Map::iterator func_iter=
2065
 
    FunctionContainer::getMap().find(func_name);
2066
 
 
2067
 
  if (func_iter != FunctionContainer::getMap().end())
 
2813
  transform(func_name.begin(), func_name.end(), func_name.begin(), ::tolower);
 
2814
 
 
2815
  map<string, Native_func_registry *>::iterator func_iter=
 
2816
    native_functions_map.find(func_name);
 
2817
 
 
2818
  if (func_iter != native_functions_map.end())
2068
2819
  {
2069
 
    builder= (*func_iter).second;
 
2820
    func= (*func_iter).second;
 
2821
    builder= func->builder;
2070
2822
  }
2071
2823
 
2072
2824
  return builder;
2086
2838
                 const char *c_len, const char *c_dec,
2087
2839
                 const CHARSET_INFO * const cs)
2088
2840
{
2089
 
  Item *res= NULL;
 
2841
  Item *res;
2090
2842
  uint32_t len;
2091
2843
  uint32_t dec;
2092
2844
 
2093
2845
  switch (cast_type) {
2094
 
  case ITEM_CAST_SIGNED:
2095
 
    res= new (session->mem_root) function::cast::Signed(a);
2096
 
    break;
2097
 
 
2098
 
  case ITEM_CAST_UNSIGNED:
2099
 
    res= new (session->mem_root) function::cast::Unsigned(a);
2100
 
    break;
2101
 
 
2102
2846
  case ITEM_CAST_BINARY:
2103
2847
    res= new (session->mem_root) Item_func_binary(a);
2104
2848
    break;
2105
 
 
2106
 
  case ITEM_CAST_BOOLEAN:
2107
 
    res= new (session->mem_root) function::cast::Boolean(a);
2108
 
    break;
2109
 
 
2110
 
  case ITEM_CAST_TIME:
2111
 
    res= new (session->mem_root) function::cast::Time(a);
2112
 
    break;
2113
 
 
 
2849
  case ITEM_CAST_SIGNED_INT:
 
2850
    res= new (session->mem_root) Item_func_signed(a);
 
2851
    break;
 
2852
  case ITEM_CAST_UNSIGNED_INT:
 
2853
    res= new (session->mem_root) Item_func_unsigned(a);
 
2854
    break;
2114
2855
  case ITEM_CAST_DATE:
2115
2856
    res= new (session->mem_root) Item_date_typecast(a);
2116
2857
    break;
2117
 
 
2118
2858
  case ITEM_CAST_DATETIME:
2119
2859
    res= new (session->mem_root) Item_datetime_typecast(a);
2120
2860
    break;
2121
 
 
2122
2861
  case ITEM_CAST_DECIMAL:
2123
 
    {
2124
 
      len= c_len ? atoi(c_len) : 0;
2125
 
      dec= c_dec ? atoi(c_dec) : 0;
2126
 
      class_decimal_trim(&len, &dec);
2127
 
      if (len < dec)
2128
 
      {
2129
 
        my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
2130
 
        return 0;
2131
 
      }
2132
 
      if (len > DECIMAL_MAX_PRECISION)
2133
 
      {
2134
 
        my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name,
2135
 
                 DECIMAL_MAX_PRECISION);
2136
 
        return 0;
2137
 
      }
2138
 
      if (dec > DECIMAL_MAX_SCALE)
2139
 
      {
2140
 
        my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name,
2141
 
                 DECIMAL_MAX_SCALE);
2142
 
        return 0;
2143
 
      }
2144
 
      res= new (session->mem_root) Item_decimal_typecast(a, len, dec);
2145
 
      break;
2146
 
    }
 
2862
  {
 
2863
    len= c_len ? atoi(c_len) : 0;
 
2864
    dec= c_dec ? atoi(c_dec) : 0;
 
2865
    my_decimal_trim(&len, &dec);
 
2866
    if (len < dec)
 
2867
    {
 
2868
      my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
 
2869
      return 0;
 
2870
    }
 
2871
    if (len > DECIMAL_MAX_PRECISION)
 
2872
    {
 
2873
      my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name,
 
2874
               DECIMAL_MAX_PRECISION);
 
2875
      return 0;
 
2876
    }
 
2877
    if (dec > DECIMAL_MAX_SCALE)
 
2878
    {
 
2879
      my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name,
 
2880
               DECIMAL_MAX_SCALE);
 
2881
      return 0;
 
2882
    }
 
2883
    res= new (session->mem_root) Item_decimal_typecast(a, len, dec);
 
2884
    break;
 
2885
  }
2147
2886
  case ITEM_CAST_CHAR:
2148
 
    {
2149
 
      len= c_len ? atoi(c_len) : -1;
2150
 
      res= create_func_char_cast(session, a, len, cs);
2151
 
      break;
2152
 
    }
2153
 
  }
2154
 
 
 
2887
  {
 
2888
    len= c_len ? atoi(c_len) : -1;
 
2889
    res= create_func_char_cast(session, a, len, cs);
 
2890
    break;
 
2891
  }
 
2892
  default:
 
2893
  {
 
2894
    assert(0);
 
2895
    res= 0;
 
2896
    break;
 
2897
  }
 
2898
  }
2155
2899
  return res;
2156
2900
}
2157
 
 
2158
 
} /* namespace drizzled */