~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/create.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-03-07 20:12:20 UTC
  • mto: (934.3.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 938.
  • Revision ID: osullivan.padraig@gmail.com-20090307201220-u9r93y0knyyb8ggy
Cleaning up my function object a little bit.

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
 
 
28
 
#include "drizzled/function_container.h"
 
27
#include <drizzled/data_home.h>
29
28
 
30
29
#include <drizzled/function/str/binary.h>
31
30
#include <drizzled/function/str/concat.h>
32
31
#include <drizzled/function/str/conv.h>
 
32
#include <drizzled/function/str/elt.h>
33
33
#include <drizzled/function/str/export_set.h>
 
34
#include <drizzled/function/str/format.h>
 
35
#include <drizzled/function/str/hex.h>
34
36
#include <drizzled/function/str/load_file.h>
35
37
#include <drizzled/function/str/make_set.h>
36
38
#include <drizzled/function/str/pad.h>
37
39
#include <drizzled/function/str/repeat.h>
38
40
#include <drizzled/function/str/str_conv.h>
 
41
#include <drizzled/function/str/substr.h>
39
42
#include <drizzled/function/str/trim.h>
 
43
#include <drizzled/function/str/uuid.h>
40
44
 
41
45
#include <drizzled/function/time/date_format.h>
42
46
#include <drizzled/function/time/dayname.h>
55
59
#include <drizzled/function/time/weekday.h>
56
60
 
57
61
#include <drizzled/item/cmpfunc.h>
58
 
#include <drizzled/plugin/function.h>
 
62
#include <drizzled/sql_udf.h>
59
63
#include <drizzled/session.h>
60
64
 
61
65
/* Function declarations */
62
66
 
63
67
#include <drizzled/function/func.h>
 
68
#include <drizzled/function/math/abs.h>
 
69
#include <drizzled/function/math/acos.h>
64
70
#include <drizzled/function/additive_op.h>
 
71
#include <drizzled/function/math/asin.h>
 
72
#include <drizzled/function/math/atan.h>
 
73
#include <drizzled/function/benchmark.h>
 
74
#include <drizzled/function/bit.h>
 
75
#include <drizzled/function/bit_count.h>
 
76
#include <drizzled/function/bit_length.h>
 
77
#include <drizzled/function/math/ceiling.h>
 
78
#include <drizzled/function/char_length.h>
 
79
#include <drizzled/function/coercibility.h>
 
80
#include <drizzled/function/connection_id.h>
 
81
#include <drizzled/function/math/cos.h>
65
82
#include <drizzled/function/math/dec.h>
66
83
#include <drizzled/function/math/decimal_typecast.h>
 
84
#include <drizzled/function/math//exp.h>
67
85
#include <drizzled/function/field.h>
68
86
#include <drizzled/function/find_in_set.h>
 
87
#include <drizzled/function/math/floor.h>
69
88
#include <drizzled/function/found_rows.h>
70
89
#include <drizzled/function/get_system_var.h>
 
90
#include <drizzled/function/get_variable.h>
71
91
#include <drizzled/function/math/int_val.h>
72
92
#include <drizzled/function/math/integer.h>
73
93
#include <drizzled/function/last_insert.h>
 
94
#include <drizzled/function/length.h>
 
95
#include <drizzled/function/math/ln.h>
74
96
#include <drizzled/function/locate.h>
 
97
#include <drizzled/function/math/log.h>
75
98
#include <drizzled/function/min_max.h>
76
99
#include <drizzled/function/num1.h>
77
100
#include <drizzled/function/num_op.h>
78
101
#include <drizzled/function/numhybrid.h>
 
102
#include <drizzled/function/math/ord.h>
 
103
#include <drizzled/function/math/pow.h>
 
104
#include <drizzled/function/math/rand.h>
79
105
#include <drizzled/function/math/real.h>
80
106
#include <drizzled/function/row_count.h>
81
107
#include <drizzled/function/set_user_var.h>
82
108
#include <drizzled/function/sign.h>
 
109
#include <drizzled/function/signed.h>
 
110
#include <drizzled/function/math/sin.h>
 
111
#include <drizzled/function/math/sqrt.h>
 
112
#include <drizzled/function/str/quote.h>
83
113
#include <drizzled/function/math/tan.h>
84
114
#include <drizzled/function/units.h>
 
115
#include <drizzled/function/unsigned.h>
 
116
#include <drizzled/function/update_hash.h>
85
117
 
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"
 
118
#include <map>
90
119
 
91
120
using namespace std;
92
121
 
93
 
namespace drizzled
94
 
{
95
 
 
96
122
class Item;
97
123
 
98
124
 
245
271
  it helps to compare code between versions, and helps with merges conflicts.
246
272
*/
247
273
 
 
274
class Create_func_abs : public Create_func_arg1
 
275
{
 
276
public:
 
277
  using Create_func_arg1::create;
 
278
 
 
279
  virtual Item *create(Session *session, Item *arg1);
 
280
 
 
281
  static Create_func_abs s_singleton;
 
282
 
 
283
protected:
 
284
  Create_func_abs() {}
 
285
  virtual ~Create_func_abs() {}
 
286
};
 
287
 
 
288
 
 
289
class Create_func_acos : public Create_func_arg1
 
290
{
 
291
public:
 
292
  using Create_func_arg1::create;
 
293
 
 
294
  virtual Item *create(Session *session, Item *arg1);
 
295
 
 
296
  static Create_func_acos s_singleton;
 
297
 
 
298
protected:
 
299
  Create_func_acos() {}
 
300
  virtual ~Create_func_acos() {}
 
301
};
 
302
 
 
303
class Create_func_asin : public Create_func_arg1
 
304
{
 
305
public:
 
306
  using Create_func_arg1::create;
 
307
 
 
308
  virtual Item *create(Session *session, Item *arg1);
 
309
 
 
310
  static Create_func_asin s_singleton;
 
311
 
 
312
protected:
 
313
  Create_func_asin() {}
 
314
  virtual ~Create_func_asin() {}
 
315
};
 
316
 
 
317
 
 
318
class Create_func_atan : public Create_native_func
 
319
{
 
320
public:
 
321
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
 
322
 
 
323
  static Create_func_atan s_singleton;
 
324
 
 
325
protected:
 
326
  Create_func_atan() {}
 
327
  virtual ~Create_func_atan() {}
 
328
};
 
329
 
 
330
 
 
331
class Create_func_benchmark : public Create_func_arg2
 
332
{
 
333
public:
 
334
  using Create_func_arg2::create;
 
335
 
 
336
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
 
337
 
 
338
  static Create_func_benchmark s_singleton;
 
339
 
 
340
protected:
 
341
  Create_func_benchmark() {}
 
342
  virtual ~Create_func_benchmark() {}
 
343
};
 
344
 
248
345
 
249
346
class Create_func_bin : public Create_func_arg1
250
347
{
260
357
  virtual ~Create_func_bin() {}
261
358
};
262
359
 
 
360
 
 
361
class Create_func_bit_count : public Create_func_arg1
 
362
{
 
363
public:
 
364
  using Create_func_arg1::create;
 
365
 
 
366
  virtual Item *create(Session *session, Item *arg1);
 
367
 
 
368
  static Create_func_bit_count s_singleton;
 
369
 
 
370
protected:
 
371
  Create_func_bit_count() {}
 
372
  virtual ~Create_func_bit_count() {}
 
373
};
 
374
 
 
375
 
 
376
class Create_func_bit_length : public Create_func_arg1
 
377
{
 
378
public:
 
379
  using Create_func_arg1::create;
 
380
 
 
381
  virtual Item *create(Session *session, Item *arg1);
 
382
 
 
383
  static Create_func_bit_length s_singleton;
 
384
 
 
385
protected:
 
386
  Create_func_bit_length() {}
 
387
  virtual ~Create_func_bit_length() {}
 
388
};
 
389
 
 
390
 
 
391
class Create_func_ceiling : public Create_func_arg1
 
392
{
 
393
public:
 
394
  using Create_func_arg1::create;
 
395
 
 
396
  virtual Item *create(Session *session, Item *arg1);
 
397
 
 
398
  static Create_func_ceiling s_singleton;
 
399
 
 
400
protected:
 
401
  Create_func_ceiling() {}
 
402
  virtual ~Create_func_ceiling() {}
 
403
};
 
404
 
 
405
 
 
406
class Create_func_char_length : 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_char_length s_singleton;
 
414
 
 
415
protected:
 
416
  Create_func_char_length() {}
 
417
  virtual ~Create_func_char_length() {}
 
418
};
 
419
 
 
420
 
 
421
class Create_func_coercibility : public Create_func_arg1
 
422
{
 
423
public:
 
424
  using Create_func_arg1::create;
 
425
 
 
426
  virtual Item *create(Session *session, Item *arg1);
 
427
 
 
428
  static Create_func_coercibility s_singleton;
 
429
 
 
430
protected:
 
431
  Create_func_coercibility() {}
 
432
  virtual ~Create_func_coercibility() {}
 
433
};
 
434
 
 
435
 
263
436
class Create_func_concat : public Create_native_func
264
437
{
265
438
public:
286
459
};
287
460
 
288
461
 
 
462
class Create_func_connection_id : public Create_func_arg0
 
463
{
 
464
public:
 
465
  using Create_func_arg0::create;
 
466
 
 
467
  virtual Item *create(Session *session);
 
468
 
 
469
  static Create_func_connection_id s_singleton;
 
470
 
 
471
protected:
 
472
  Create_func_connection_id() {}
 
473
  virtual ~Create_func_connection_id() {}
 
474
};
 
475
 
 
476
 
289
477
class Create_func_conv : public Create_func_arg3
290
478
{
291
479
public:
300
488
  virtual ~Create_func_conv() {}
301
489
};
302
490
 
 
491
 
 
492
class Create_func_cos : public Create_func_arg1
 
493
{
 
494
public:
 
495
  using Create_func_arg1::create;
 
496
 
 
497
  virtual Item *create(Session *session, Item *arg1);
 
498
 
 
499
  static Create_func_cos s_singleton;
 
500
 
 
501
protected:
 
502
  Create_func_cos() {}
 
503
  virtual ~Create_func_cos() {}
 
504
};
 
505
 
 
506
 
303
507
class Create_func_cot : public Create_func_arg1
304
508
{
305
509
public:
433
637
  virtual ~Create_func_degrees() {}
434
638
};
435
639
 
 
640
 
 
641
class Create_func_elt : public Create_native_func
 
642
{
 
643
public:
 
644
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
 
645
 
 
646
  static Create_func_elt s_singleton;
 
647
 
 
648
protected:
 
649
  Create_func_elt() {}
 
650
  virtual ~Create_func_elt() {}
 
651
};
 
652
 
 
653
 
 
654
class Create_func_exp : public Create_func_arg1
 
655
{
 
656
public:
 
657
  using Create_func_arg1::create;
 
658
 
 
659
  virtual Item *create(Session *session, Item *arg1);
 
660
 
 
661
  static Create_func_exp s_singleton;
 
662
 
 
663
protected:
 
664
  Create_func_exp() {}
 
665
  virtual ~Create_func_exp() {}
 
666
};
 
667
 
 
668
 
436
669
class Create_func_export_set : public Create_native_func
437
670
{
438
 
 
439
671
public:
440
672
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
441
673
 
474
706
  virtual ~Create_func_find_in_set() {}
475
707
};
476
708
 
 
709
 
 
710
class Create_func_floor : 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_floor s_singleton;
 
718
 
 
719
protected:
 
720
  Create_func_floor() {}
 
721
  virtual ~Create_func_floor() {}
 
722
};
 
723
 
 
724
 
 
725
class Create_func_format : public Create_func_arg2
 
726
{
 
727
public:
 
728
  using Create_func_arg2::create;
 
729
 
 
730
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
 
731
 
 
732
  static Create_func_format s_singleton;
 
733
 
 
734
protected:
 
735
  Create_func_format() {}
 
736
  virtual ~Create_func_format() {}
 
737
};
 
738
 
 
739
 
477
740
class Create_func_found_rows : public Create_func_arg0
478
741
{
479
742
public:
530
793
};
531
794
 
532
795
 
 
796
class Create_func_hex : public Create_func_arg1
 
797
{
 
798
public:
 
799
  using Create_func_arg1::create;
 
800
 
 
801
  virtual Item *create(Session *session, Item *arg1);
 
802
 
 
803
  static Create_func_hex s_singleton;
 
804
 
 
805
protected:
 
806
  Create_func_hex() {}
 
807
  virtual ~Create_func_hex() {}
 
808
};
 
809
 
 
810
 
533
811
class Create_func_ifnull : public Create_func_arg2
534
812
{
535
813
public:
630
908
  virtual ~Create_func_least() {}
631
909
};
632
910
 
 
911
 
 
912
class Create_func_length : public Create_func_arg1
 
913
{
 
914
public:
 
915
  using Create_func_arg1::create;
 
916
 
 
917
  virtual Item *create(Session *session, Item *arg1);
 
918
 
 
919
  static Create_func_length s_singleton;
 
920
 
 
921
protected:
 
922
  Create_func_length() {}
 
923
  virtual ~Create_func_length() {}
 
924
};
 
925
 
 
926
 
 
927
class Create_func_ln : public Create_func_arg1
 
928
{
 
929
public:
 
930
  using Create_func_arg1::create;
 
931
 
 
932
  virtual Item *create(Session *session, Item *arg1);
 
933
 
 
934
  static Create_func_ln s_singleton;
 
935
 
 
936
protected:
 
937
  Create_func_ln() {}
 
938
  virtual ~Create_func_ln() {}
 
939
};
 
940
 
 
941
 
633
942
class Create_func_load_file : public Create_func_arg1
634
943
{
635
944
public:
658
967
};
659
968
 
660
969
 
 
970
class Create_func_log : public Create_native_func
 
971
{
 
972
public:
 
973
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
 
974
 
 
975
  static Create_func_log s_singleton;
 
976
 
 
977
protected:
 
978
  Create_func_log() {}
 
979
  virtual ~Create_func_log() {}
 
980
};
 
981
 
 
982
 
 
983
class Create_func_log10 : public Create_func_arg1
 
984
{
 
985
public:
 
986
  using Create_func_arg1::create;
 
987
 
 
988
  virtual Item *create(Session *session, Item *arg1);
 
989
 
 
990
  static Create_func_log10 s_singleton;
 
991
 
 
992
protected:
 
993
  Create_func_log10() {}
 
994
  virtual ~Create_func_log10() {}
 
995
};
 
996
 
 
997
 
 
998
class Create_func_log2 : public Create_func_arg1
 
999
{
 
1000
public:
 
1001
  using Create_func_arg1::create;
 
1002
 
 
1003
  virtual Item *create(Session *session, Item *arg1);
 
1004
 
 
1005
  static Create_func_log2 s_singleton;
 
1006
 
 
1007
protected:
 
1008
  Create_func_log2() {}
 
1009
  virtual ~Create_func_log2() {}
 
1010
};
 
1011
 
 
1012
 
661
1013
class Create_func_lpad : public Create_func_arg3
662
1014
{
663
1015
public:
774
1126
  virtual ~Create_func_oct() {}
775
1127
};
776
1128
 
 
1129
 
 
1130
class Create_func_ord : public Create_func_arg1
 
1131
{
 
1132
public:
 
1133
  using Create_func_arg1::create;
 
1134
 
 
1135
  virtual Item *create(Session *session, Item *arg1);
 
1136
 
 
1137
  static Create_func_ord s_singleton;
 
1138
 
 
1139
protected:
 
1140
  Create_func_ord() {}
 
1141
  virtual ~Create_func_ord() {}
 
1142
};
 
1143
 
 
1144
 
777
1145
class Create_func_period_add : public Create_func_arg2
778
1146
{
779
1147
public:
818
1186
  virtual ~Create_func_pi() {}
819
1187
};
820
1188
 
 
1189
 
 
1190
class Create_func_pow : public Create_func_arg2
 
1191
{
 
1192
public:
 
1193
  using Create_func_arg2::create;
 
1194
 
 
1195
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
 
1196
 
 
1197
  static Create_func_pow s_singleton;
 
1198
 
 
1199
protected:
 
1200
  Create_func_pow() {}
 
1201
  virtual ~Create_func_pow() {}
 
1202
};
 
1203
 
 
1204
 
 
1205
class Create_func_quote : public Create_func_arg1
 
1206
{
 
1207
public:
 
1208
  using Create_func_arg1::create;
 
1209
 
 
1210
  virtual Item *create(Session *session, Item *arg1);
 
1211
 
 
1212
  static Create_func_quote s_singleton;
 
1213
 
 
1214
protected:
 
1215
  Create_func_quote() {}
 
1216
  virtual ~Create_func_quote() {}
 
1217
};
 
1218
 
 
1219
 
821
1220
class Create_func_radians : public Create_func_arg1
822
1221
{
823
1222
public:
833
1232
};
834
1233
 
835
1234
 
 
1235
class Create_func_rand : public Create_native_func
 
1236
{
 
1237
public:
 
1238
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
 
1239
 
 
1240
  static Create_func_rand s_singleton;
 
1241
 
 
1242
protected:
 
1243
  Create_func_rand() {}
 
1244
  virtual ~Create_func_rand() {}
 
1245
};
 
1246
 
 
1247
 
836
1248
class Create_func_round : public Create_native_func
837
1249
{
838
1250
public:
904
1316
  virtual ~Create_func_sign() {}
905
1317
};
906
1318
 
 
1319
 
 
1320
class Create_func_sin : public Create_func_arg1
 
1321
{
 
1322
public:
 
1323
  using Create_func_arg1::create;
 
1324
 
 
1325
  virtual Item *create(Session *session, Item *arg1);
 
1326
 
 
1327
  static Create_func_sin s_singleton;
 
1328
 
 
1329
protected:
 
1330
  Create_func_sin() {}
 
1331
  virtual ~Create_func_sin() {}
 
1332
};
 
1333
 
 
1334
 
907
1335
class Create_func_space : public Create_func_arg1
908
1336
{
909
1337
public:
918
1346
  virtual ~Create_func_space() {}
919
1347
};
920
1348
 
 
1349
 
 
1350
class Create_func_sqrt : public Create_func_arg1
 
1351
{
 
1352
public:
 
1353
  using Create_func_arg1::create;
 
1354
 
 
1355
  virtual Item *create(Session *session, Item *arg1);
 
1356
 
 
1357
  static Create_func_sqrt s_singleton;
 
1358
 
 
1359
protected:
 
1360
  Create_func_sqrt() {}
 
1361
  virtual ~Create_func_sqrt() {}
 
1362
};
 
1363
 
 
1364
 
921
1365
class Create_func_strcmp : public Create_func_arg2
922
1366
{
923
1367
public:
933
1377
};
934
1378
 
935
1379
 
 
1380
class Create_func_substr_index : public Create_func_arg3
 
1381
{
 
1382
public:
 
1383
  using Create_func_arg3::create;
 
1384
 
 
1385
  virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3);
 
1386
 
 
1387
  static Create_func_substr_index s_singleton;
 
1388
 
 
1389
protected:
 
1390
  Create_func_substr_index() {}
 
1391
  virtual ~Create_func_substr_index() {}
 
1392
};
 
1393
 
 
1394
 
936
1395
class Create_func_tan : public Create_func_arg1
937
1396
{
938
1397
public:
1008
1467
};
1009
1468
 
1010
1469
 
 
1470
class Create_func_unhex : public Create_func_arg1
 
1471
{
 
1472
public:
 
1473
  using Create_func_arg1::create;
 
1474
 
 
1475
  virtual Item *create(Session *session, Item *arg1);
 
1476
 
 
1477
  static Create_func_unhex s_singleton;
 
1478
 
 
1479
protected:
 
1480
  Create_func_unhex() {}
 
1481
  virtual ~Create_func_unhex() {}
 
1482
};
 
1483
 
 
1484
 
1011
1485
class Create_func_unix_timestamp : public Create_native_func
1012
1486
{
1013
1487
public:
1021
1495
};
1022
1496
 
1023
1497
 
 
1498
class Create_func_uuid : public Create_func_arg0
 
1499
{
 
1500
public:
 
1501
  using Create_func_arg0::create;
 
1502
 
 
1503
  virtual Item *create(Session *session);
 
1504
 
 
1505
  static Create_func_uuid s_singleton;
 
1506
 
 
1507
protected:
 
1508
  Create_func_uuid() {}
 
1509
  virtual ~Create_func_uuid() {}
 
1510
};
 
1511
 
 
1512
 
 
1513
class Create_func_version : public Create_func_arg0
 
1514
{
 
1515
public:
 
1516
  using Create_func_arg0::create;
 
1517
 
 
1518
  virtual Item *create(Session *session);
 
1519
 
 
1520
  static Create_func_version s_singleton;
 
1521
 
 
1522
protected:
 
1523
  Create_func_version() {}
 
1524
  virtual ~Create_func_version() {}
 
1525
};
 
1526
 
 
1527
 
1024
1528
class Create_func_weekday : public Create_func_arg1
1025
1529
{
1026
1530
public:
1070
1574
Item*
1071
1575
Create_udf_func::create(Session *session, LEX_STRING name, List<Item> *item_list)
1072
1576
{
1073
 
  const plugin::Function *udf= plugin::Function::get(name.str, name.length);
 
1577
  udf_func *udf= find_udf(name.str, name.length);
1074
1578
  assert(udf);
1075
1579
  return create(session, udf, item_list);
1076
1580
}
1077
1581
 
1078
1582
 
1079
1583
Item*
1080
 
Create_udf_func::create(Session *session, const plugin::Function *udf,
1081
 
                        List<Item> *item_list)
 
1584
Create_udf_func::create(Session *session, udf_func *udf, List<Item> *item_list)
1082
1585
{
1083
1586
  Item_func *func= NULL;
1084
1587
  int arg_count= 0;
1086
1589
  if (item_list != NULL)
1087
1590
    arg_count= item_list->elements;
1088
1591
 
1089
 
  func= (*udf)(session->mem_root);
1090
 
 
1091
 
  if(!func->check_argument_count(arg_count))
1092
 
  {
1093
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), func->func_name());
1094
 
    return NULL;
1095
 
  }
1096
 
 
1097
 
  if(item_list)
1098
 
    func->set_arguments(*item_list);
 
1592
  func= udf->create_func(session->mem_root);
 
1593
 
 
1594
  func->set_arguments(*item_list);
1099
1595
 
1100
1596
  return func;
1101
1597
}
1124
1620
 
1125
1621
  if (arg_count != 0)
1126
1622
  {
1127
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1623
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1128
1624
    return NULL;
1129
1625
  }
1130
1626
 
1142
1638
 
1143
1639
  if (arg_count != 1)
1144
1640
  {
1145
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1641
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1146
1642
    return NULL;
1147
1643
  }
1148
1644
 
1168
1664
 
1169
1665
  if (arg_count != 2)
1170
1666
  {
1171
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1667
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1172
1668
    return NULL;
1173
1669
  }
1174
1670
 
1196
1692
 
1197
1693
  if (arg_count != 3)
1198
1694
  {
1199
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1695
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1200
1696
    return NULL;
1201
1697
  }
1202
1698
 
1215
1711
  return create(session, param_1, param_2, param_3);
1216
1712
}
1217
1713
 
 
1714
 
 
1715
Create_func_abs Create_func_abs::s_singleton;
 
1716
 
 
1717
Item*
 
1718
Create_func_abs::create(Session *session, Item *arg1)
 
1719
{
 
1720
  return new (session->mem_root) Item_func_abs(arg1);
 
1721
}
 
1722
 
 
1723
 
 
1724
Create_func_acos Create_func_acos::s_singleton;
 
1725
 
 
1726
Item*
 
1727
Create_func_acos::create(Session *session, Item *arg1)
 
1728
{
 
1729
  return new (session->mem_root) Item_func_acos(arg1);
 
1730
}
 
1731
 
 
1732
Create_func_asin Create_func_asin::s_singleton;
 
1733
 
 
1734
Item*
 
1735
Create_func_asin::create(Session *session, Item *arg1)
 
1736
{
 
1737
  return new (session->mem_root) Item_func_asin(arg1);
 
1738
}
 
1739
 
 
1740
 
 
1741
Create_func_atan Create_func_atan::s_singleton;
 
1742
 
 
1743
Item*
 
1744
Create_func_atan::create_native(Session *session, LEX_STRING name,
 
1745
                                List<Item> *item_list)
 
1746
{
 
1747
  Item* func= NULL;
 
1748
  int arg_count= 0;
 
1749
 
 
1750
  if (item_list != NULL)
 
1751
    arg_count= item_list->elements;
 
1752
 
 
1753
  switch (arg_count) {
 
1754
  case 1:
 
1755
  {
 
1756
    Item *param_1= item_list->pop();
 
1757
    func= new (session->mem_root) Item_func_atan(param_1);
 
1758
    break;
 
1759
  }
 
1760
  case 2:
 
1761
  {
 
1762
    Item *param_1= item_list->pop();
 
1763
    Item *param_2= item_list->pop();
 
1764
    func= new (session->mem_root) Item_func_atan(param_1, param_2);
 
1765
    break;
 
1766
  }
 
1767
  default:
 
1768
  {
 
1769
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
1770
    break;
 
1771
  }
 
1772
  }
 
1773
 
 
1774
  return func;
 
1775
}
 
1776
 
 
1777
 
 
1778
Create_func_benchmark Create_func_benchmark::s_singleton;
 
1779
 
 
1780
Item*
 
1781
Create_func_benchmark::create(Session *session, Item *arg1, Item *arg2)
 
1782
{
 
1783
  return new (session->mem_root) Item_func_benchmark(arg1, arg2);
 
1784
}
 
1785
 
 
1786
 
1218
1787
Create_func_bin Create_func_bin::s_singleton;
1219
1788
 
1220
1789
Item*
1225
1794
  return new (session->mem_root) Item_func_conv(arg1, i10, i2);
1226
1795
}
1227
1796
 
 
1797
 
 
1798
Create_func_bit_count Create_func_bit_count::s_singleton;
 
1799
 
 
1800
Item*
 
1801
Create_func_bit_count::create(Session *session, Item *arg1)
 
1802
{
 
1803
  return new (session->mem_root) Item_func_bit_count(arg1);
 
1804
}
 
1805
 
 
1806
 
 
1807
Create_func_bit_length Create_func_bit_length::s_singleton;
 
1808
 
 
1809
Item*
 
1810
Create_func_bit_length::create(Session *session, Item *arg1)
 
1811
{
 
1812
  return new (session->mem_root) Item_func_bit_length(arg1);
 
1813
}
 
1814
 
 
1815
 
 
1816
Create_func_ceiling Create_func_ceiling::s_singleton;
 
1817
 
 
1818
Item*
 
1819
Create_func_ceiling::create(Session *session, Item *arg1)
 
1820
{
 
1821
  return new (session->mem_root) Item_func_ceiling(arg1);
 
1822
}
 
1823
 
 
1824
 
 
1825
Create_func_char_length Create_func_char_length::s_singleton;
 
1826
 
 
1827
Item*
 
1828
Create_func_char_length::create(Session *session, Item *arg1)
 
1829
{
 
1830
  return new (session->mem_root) Item_func_char_length(arg1);
 
1831
}
 
1832
 
 
1833
 
 
1834
Create_func_coercibility Create_func_coercibility::s_singleton;
 
1835
 
 
1836
Item*
 
1837
Create_func_coercibility::create(Session *session, Item *arg1)
 
1838
{
 
1839
  return new (session->mem_root) Item_func_coercibility(arg1);
 
1840
}
 
1841
 
 
1842
 
1228
1843
Create_func_concat Create_func_concat::s_singleton;
1229
1844
 
1230
1845
Item*
1238
1853
 
1239
1854
  if (arg_count < 1)
1240
1855
  {
1241
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1856
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1242
1857
    return NULL;
1243
1858
  }
1244
1859
 
1245
 
  return new (session->mem_root) Item_func_concat(*session, *item_list);
 
1860
  return new (session->mem_root) Item_func_concat(*item_list);
1246
1861
}
1247
1862
 
1248
1863
 
1260
1875
  /* "WS" stands for "With Separator": this function takes 2+ arguments */
1261
1876
  if (arg_count < 2)
1262
1877
  {
1263
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1878
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1264
1879
    return NULL;
1265
1880
  }
1266
1881
 
1267
 
  return new (session->mem_root) Item_func_concat_ws(*session, *item_list);
 
1882
  return new (session->mem_root) Item_func_concat_ws(*item_list);
 
1883
}
 
1884
 
 
1885
 
 
1886
Create_func_connection_id Create_func_connection_id::s_singleton;
 
1887
 
 
1888
Item*
 
1889
Create_func_connection_id::create(Session *session)
 
1890
{
 
1891
  return new (session->mem_root) Item_func_connection_id();
1268
1892
}
1269
1893
 
1270
1894
 
1276
1900
  return new (session->mem_root) Item_func_conv(arg1, arg2, arg3);
1277
1901
}
1278
1902
 
 
1903
 
 
1904
Create_func_cos Create_func_cos::s_singleton;
 
1905
 
 
1906
Item*
 
1907
Create_func_cos::create(Session *session, Item *arg1)
 
1908
{
 
1909
  return new (session->mem_root) Item_func_cos(arg1);
 
1910
}
 
1911
 
 
1912
 
1279
1913
Create_func_cot Create_func_cot::s_singleton;
1280
1914
 
1281
1915
Item*
1283
1917
{
1284
1918
  Item *i1= new (session->mem_root) Item_int((char*) "1", 1, 1);
1285
1919
  Item *i2= new (session->mem_root) Item_func_tan(arg1);
1286
 
  return new (session->mem_root) Item_func_div(session, i1, i2);
 
1920
  return new (session->mem_root) Item_func_div(i1, i2);
1287
1921
}
1288
1922
 
1289
1923
Create_func_date_format Create_func_date_format::s_singleton;
1352
1986
                                             180/M_PI, 0.0);
1353
1987
}
1354
1988
 
 
1989
 
 
1990
Create_func_elt Create_func_elt::s_singleton;
 
1991
 
 
1992
Item*
 
1993
Create_func_elt::create_native(Session *session, LEX_STRING name,
 
1994
                               List<Item> *item_list)
 
1995
{
 
1996
  int arg_count= 0;
 
1997
 
 
1998
  if (item_list != NULL)
 
1999
    arg_count= item_list->elements;
 
2000
 
 
2001
  if (arg_count < 2)
 
2002
  {
 
2003
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2004
    return NULL;
 
2005
  }
 
2006
 
 
2007
  return new (session->mem_root) Item_func_elt(*item_list);
 
2008
}
 
2009
 
 
2010
 
 
2011
Create_func_exp Create_func_exp::s_singleton;
 
2012
 
 
2013
Item*
 
2014
Create_func_exp::create(Session *session, Item *arg1)
 
2015
{
 
2016
  return new (session->mem_root) Item_func_exp(arg1);
 
2017
}
 
2018
 
 
2019
 
1355
2020
Create_func_export_set Create_func_export_set::s_singleton;
1356
2021
 
1357
2022
Item*
1396
2061
  }
1397
2062
  default:
1398
2063
  {
1399
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2064
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1400
2065
    break;
1401
2066
  }
1402
2067
  }
1418
2083
 
1419
2084
  if (arg_count < 2)
1420
2085
  {
1421
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2086
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1422
2087
    return NULL;
1423
2088
  }
1424
2089
 
1434
2099
  return new (session->mem_root) Item_func_find_in_set(arg1, arg2);
1435
2100
}
1436
2101
 
 
2102
 
 
2103
Create_func_floor Create_func_floor::s_singleton;
 
2104
 
 
2105
Item*
 
2106
Create_func_floor::create(Session *session, Item *arg1)
 
2107
{
 
2108
  return new (session->mem_root) Item_func_floor(arg1);
 
2109
}
 
2110
 
 
2111
 
 
2112
Create_func_format Create_func_format::s_singleton;
 
2113
 
 
2114
Item*
 
2115
Create_func_format::create(Session *session, Item *arg1, Item *arg2)
 
2116
{
 
2117
  return new (session->mem_root) Item_func_format(arg1, arg2);
 
2118
}
 
2119
 
 
2120
 
1437
2121
Create_func_found_rows Create_func_found_rows::s_singleton;
1438
2122
 
1439
2123
Item*
1481
2165
  }
1482
2166
  default:
1483
2167
  {
1484
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2168
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1485
2169
    break;
1486
2170
  }
1487
2171
  }
1503
2187
 
1504
2188
  if (arg_count < 2)
1505
2189
  {
1506
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2190
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1507
2191
    return NULL;
1508
2192
  }
1509
2193
 
1510
2194
  return new (session->mem_root) Item_func_max(*item_list);
1511
2195
}
1512
2196
 
 
2197
 
 
2198
Create_func_hex Create_func_hex::s_singleton;
 
2199
 
 
2200
Item*
 
2201
Create_func_hex::create(Session *session, Item *arg1)
 
2202
{
 
2203
  return new (session->mem_root) Item_func_hex(arg1);
 
2204
}
 
2205
 
 
2206
 
1513
2207
Create_func_ifnull Create_func_ifnull::s_singleton;
1514
2208
 
1515
2209
Item*
1572
2266
  }
1573
2267
  default:
1574
2268
  {
1575
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2269
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1576
2270
    break;
1577
2271
  }
1578
2272
  }
1603
2297
 
1604
2298
  if (arg_count < 2)
1605
2299
  {
1606
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2300
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1607
2301
    return NULL;
1608
2302
  }
1609
2303
 
1610
2304
  return new (session->mem_root) Item_func_min(*item_list);
1611
2305
}
1612
2306
 
 
2307
 
 
2308
Create_func_length Create_func_length::s_singleton;
 
2309
 
 
2310
Item*
 
2311
Create_func_length::create(Session *session, Item *arg1)
 
2312
{
 
2313
  return new (session->mem_root) Item_func_length(arg1);
 
2314
}
 
2315
 
 
2316
 
 
2317
Create_func_ln Create_func_ln::s_singleton;
 
2318
 
 
2319
Item*
 
2320
Create_func_ln::create(Session *session, Item *arg1)
 
2321
{
 
2322
  return new (session->mem_root) Item_func_ln(arg1);
 
2323
}
 
2324
 
 
2325
 
1613
2326
Create_func_load_file Create_func_load_file::s_singleton;
1614
2327
 
1615
2328
Item*
1616
2329
Create_func_load_file::create(Session *session, Item *arg1)
1617
2330
{
1618
 
  return new (session->mem_root) Item_load_file(*session, arg1);
 
2331
  return new (session->mem_root) Item_load_file(arg1);
1619
2332
}
1620
2333
 
1621
2334
 
1651
2364
  }
1652
2365
  default:
1653
2366
  {
1654
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1655
 
    break;
1656
 
  }
1657
 
  }
1658
 
 
1659
 
  return func;
1660
 
}
 
2367
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2368
    break;
 
2369
  }
 
2370
  }
 
2371
 
 
2372
  return func;
 
2373
}
 
2374
 
 
2375
 
 
2376
Create_func_log Create_func_log::s_singleton;
 
2377
 
 
2378
Item*
 
2379
Create_func_log::create_native(Session *session, LEX_STRING name,
 
2380
                               List<Item> *item_list)
 
2381
{
 
2382
  Item *func= NULL;
 
2383
  int arg_count= 0;
 
2384
 
 
2385
  if (item_list != NULL)
 
2386
    arg_count= item_list->elements;
 
2387
 
 
2388
  switch (arg_count) {
 
2389
  case 1:
 
2390
  {
 
2391
    Item *param_1= item_list->pop();
 
2392
    func= new (session->mem_root) Item_func_log(param_1);
 
2393
    break;
 
2394
  }
 
2395
  case 2:
 
2396
  {
 
2397
    Item *param_1= item_list->pop();
 
2398
    Item *param_2= item_list->pop();
 
2399
    func= new (session->mem_root) Item_func_log(param_1, param_2);
 
2400
    break;
 
2401
  }
 
2402
  default:
 
2403
  {
 
2404
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2405
    break;
 
2406
  }
 
2407
  }
 
2408
 
 
2409
  return func;
 
2410
}
 
2411
 
 
2412
 
 
2413
Create_func_log10 Create_func_log10::s_singleton;
 
2414
 
 
2415
Item*
 
2416
Create_func_log10::create(Session *session, Item *arg1)
 
2417
{
 
2418
  return new (session->mem_root) Item_func_log10(arg1);
 
2419
}
 
2420
 
 
2421
 
 
2422
Create_func_log2 Create_func_log2::s_singleton;
 
2423
 
 
2424
Item*
 
2425
Create_func_log2::create(Session *session, Item *arg1)
 
2426
{
 
2427
  return new (session->mem_root) Item_func_log2(arg1);
 
2428
}
 
2429
 
1661
2430
 
1662
2431
Create_func_lpad Create_func_lpad::s_singleton;
1663
2432
 
1664
2433
Item*
1665
2434
Create_func_lpad::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
1666
2435
{
1667
 
  return new (session->mem_root) Item_func_lpad(*session, arg1, arg2, arg3);
 
2436
  return new (session->mem_root) Item_func_lpad(arg1, arg2, arg3);
1668
2437
}
1669
2438
 
1670
2439
 
1689
2458
Create_func_make_set Create_func_make_set::s_singleton;
1690
2459
 
1691
2460
Item*
1692
 
Create_func_make_set::create_native(Session *session_arg, LEX_STRING name,
 
2461
Create_func_make_set::create_native(Session *session, LEX_STRING name,
1693
2462
                                    List<Item> *item_list)
1694
2463
{
1695
2464
  int arg_count= 0;
1699
2468
 
1700
2469
  if (arg_count < 2)
1701
2470
  {
1702
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2471
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1703
2472
    return NULL;
1704
2473
  }
1705
2474
 
1706
2475
  Item *param_1= item_list->pop();
1707
 
  return new (session_arg->mem_root) Item_func_make_set(*session_arg, param_1, *item_list);
 
2476
  return new (session->mem_root) Item_func_make_set(param_1, *item_list);
1708
2477
}
1709
2478
 
1710
2479
 
1736
2505
  return new (session->mem_root) Item_func_conv(arg1, i10, i8);
1737
2506
}
1738
2507
 
 
2508
 
 
2509
Create_func_ord Create_func_ord::s_singleton;
 
2510
 
 
2511
Item*
 
2512
Create_func_ord::create(Session *session, Item *arg1)
 
2513
{
 
2514
  return new (session->mem_root) Item_func_ord(arg1);
 
2515
}
 
2516
 
 
2517
 
1739
2518
Create_func_period_add Create_func_period_add::s_singleton;
1740
2519
 
1741
2520
Item*
1762
2541
  return new (session->mem_root) Item_static_float_func("pi()", M_PI, 6, 8);
1763
2542
}
1764
2543
 
 
2544
 
 
2545
Create_func_pow Create_func_pow::s_singleton;
 
2546
 
 
2547
Item*
 
2548
Create_func_pow::create(Session *session, Item *arg1, Item *arg2)
 
2549
{
 
2550
  return new (session->mem_root) Item_func_pow(arg1, arg2);
 
2551
}
 
2552
 
 
2553
 
 
2554
Create_func_quote Create_func_quote::s_singleton;
 
2555
 
 
2556
Item*
 
2557
Create_func_quote::create(Session *session, Item *arg1)
 
2558
{
 
2559
  return new (session->mem_root) Item_func_quote(arg1);
 
2560
}
 
2561
 
 
2562
 
1765
2563
Create_func_radians Create_func_radians::s_singleton;
1766
2564
 
1767
2565
Item*
1771
2569
                                             M_PI/180, 0.0);
1772
2570
}
1773
2571
 
 
2572
 
 
2573
Create_func_rand Create_func_rand::s_singleton;
 
2574
 
 
2575
Item*
 
2576
Create_func_rand::create_native(Session *session, LEX_STRING name,
 
2577
                                List<Item> *item_list)
 
2578
{
 
2579
  Item *func= NULL;
 
2580
  int arg_count= 0;
 
2581
 
 
2582
  if (item_list != NULL)
 
2583
    arg_count= item_list->elements;
 
2584
 
 
2585
  switch (arg_count) {
 
2586
  case 0:
 
2587
  {
 
2588
    func= new (session->mem_root) Item_func_rand();
 
2589
    break;
 
2590
  }
 
2591
  case 1:
 
2592
  {
 
2593
    Item *param_1= item_list->pop();
 
2594
    func= new (session->mem_root) Item_func_rand(param_1);
 
2595
    break;
 
2596
  }
 
2597
  default:
 
2598
  {
 
2599
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2600
    break;
 
2601
  }
 
2602
  }
 
2603
 
 
2604
  return func;
 
2605
}
 
2606
 
 
2607
 
1774
2608
Create_func_round Create_func_round::s_singleton;
1775
2609
 
1776
2610
Item*
1800
2634
  }
1801
2635
  default:
1802
2636
  {
1803
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2637
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1804
2638
    break;
1805
2639
  }
1806
2640
  }
1823
2657
Item*
1824
2658
Create_func_rpad::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
1825
2659
{
1826
 
  return new (session->mem_root) Item_func_rpad(*session, arg1, arg2, arg3);
 
2660
  return new (session->mem_root) Item_func_rpad(arg1, arg2, arg3);
1827
2661
}
1828
2662
 
1829
2663
 
1844
2678
  return new (session->mem_root) Item_func_sign(arg1);
1845
2679
}
1846
2680
 
 
2681
 
 
2682
Create_func_sin Create_func_sin::s_singleton;
 
2683
 
 
2684
Item*
 
2685
Create_func_sin::create(Session *session, Item *arg1)
 
2686
{
 
2687
  return new (session->mem_root) Item_func_sin(arg1);
 
2688
}
 
2689
 
 
2690
 
1847
2691
Create_func_space Create_func_space::s_singleton;
1848
2692
 
1849
2693
Item*
1859
2703
 
1860
2704
  if (cs->mbminlen > 1)
1861
2705
  {
1862
 
    size_t dummy_errors;
1863
 
    sp= new (session->mem_root) Item_string("", 0, cs, DERIVATION_COERCIBLE);
 
2706
    uint32_t dummy_errors;
 
2707
    sp= new (session->mem_root) Item_string("", 0, cs, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
1864
2708
    sp->str_value.copy(" ", 1, &my_charset_utf8_general_ci, cs, &dummy_errors);
1865
2709
  }
1866
2710
  else
1867
2711
  {
1868
 
    sp= new (session->mem_root) Item_string(" ", 1, cs, DERIVATION_COERCIBLE);
 
2712
    sp= new (session->mem_root) Item_string(" ", 1, cs, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
1869
2713
  }
1870
2714
 
1871
 
  return new (session->mem_root) Item_func_repeat(*session, sp, arg1);
1872
 
}
 
2715
  return new (session->mem_root) Item_func_repeat(sp, arg1);
 
2716
}
 
2717
 
 
2718
 
 
2719
Create_func_sqrt Create_func_sqrt::s_singleton;
 
2720
 
 
2721
Item*
 
2722
Create_func_sqrt::create(Session *session, Item *arg1)
 
2723
{
 
2724
  return new (session->mem_root) Item_func_sqrt(arg1);
 
2725
}
 
2726
 
1873
2727
 
1874
2728
Create_func_strcmp Create_func_strcmp::s_singleton;
1875
2729
 
1880
2734
}
1881
2735
 
1882
2736
 
 
2737
Create_func_substr_index Create_func_substr_index::s_singleton;
 
2738
 
 
2739
Item*
 
2740
Create_func_substr_index::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
 
2741
{
 
2742
  return new (session->mem_root) Item_func_substr_index(arg1, arg2, arg3);
 
2743
}
 
2744
 
1883
2745
Create_func_tan Create_func_tan::s_singleton;
1884
2746
 
1885
2747
Item*
1914
2776
  return new (session->mem_root) Item_func_ucase(arg1);
1915
2777
}
1916
2778
 
 
2779
 
 
2780
Create_func_unhex Create_func_unhex::s_singleton;
 
2781
 
 
2782
Item*
 
2783
Create_func_unhex::create(Session *session, Item *arg1)
 
2784
{
 
2785
  return new (session->mem_root) Item_func_unhex(arg1);
 
2786
}
 
2787
 
 
2788
 
1917
2789
Create_func_unix_timestamp Create_func_unix_timestamp::s_singleton;
1918
2790
 
1919
2791
Item*
1940
2812
  }
1941
2813
  default:
1942
2814
  {
1943
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2815
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1944
2816
    break;
1945
2817
  }
1946
2818
  }
1949
2821
}
1950
2822
 
1951
2823
 
 
2824
Create_func_uuid Create_func_uuid::s_singleton;
 
2825
 
 
2826
Item*
 
2827
Create_func_uuid::create(Session *session)
 
2828
{
 
2829
  return new (session->mem_root) Item_func_uuid();
 
2830
}
 
2831
 
 
2832
 
 
2833
Create_func_version Create_func_version::s_singleton;
 
2834
 
 
2835
Item*
 
2836
Create_func_version::create(Session *session)
 
2837
{
 
2838
  return new (session->mem_root) Item_static_string_func("version()",
 
2839
                                                         server_version,
 
2840
                                                         (uint32_t) strlen(server_version),
 
2841
                                                         system_charset_info,
 
2842
                                                         DERIVATION_SYSCONST);
 
2843
}
 
2844
 
 
2845
 
1952
2846
Create_func_weekday Create_func_weekday::s_singleton;
1953
2847
 
1954
2848
Item*
1974
2868
 
1975
2869
static Native_func_registry func_array[] =
1976
2870
{
 
2871
  { { C_STRING_WITH_LEN("ABS") }, BUILDER(Create_func_abs)},
 
2872
  { { C_STRING_WITH_LEN("ACOS") }, BUILDER(Create_func_acos)},
 
2873
  { { C_STRING_WITH_LEN("ASIN") }, BUILDER(Create_func_asin)},
 
2874
  { { C_STRING_WITH_LEN("ATAN") }, BUILDER(Create_func_atan)},
 
2875
  { { C_STRING_WITH_LEN("ATAN2") }, BUILDER(Create_func_atan)},
 
2876
  { { C_STRING_WITH_LEN("BENCHMARK") }, BUILDER(Create_func_benchmark)},
1977
2877
  { { C_STRING_WITH_LEN("BIN") }, BUILDER(Create_func_bin)},
 
2878
  { { C_STRING_WITH_LEN("BIT_COUNT") }, BUILDER(Create_func_bit_count)},
 
2879
  { { C_STRING_WITH_LEN("BIT_LENGTH") }, BUILDER(Create_func_bit_length)},
 
2880
  { { C_STRING_WITH_LEN("CEIL") }, BUILDER(Create_func_ceiling)},
 
2881
  { { C_STRING_WITH_LEN("CEILING") }, BUILDER(Create_func_ceiling)},
 
2882
  { { C_STRING_WITH_LEN("CHARACTER_LENGTH") }, BUILDER(Create_func_char_length)},
 
2883
  { { C_STRING_WITH_LEN("CHAR_LENGTH") }, BUILDER(Create_func_char_length)},
 
2884
  { { C_STRING_WITH_LEN("COERCIBILITY") }, BUILDER(Create_func_coercibility)},
1978
2885
  { { C_STRING_WITH_LEN("CONCAT") }, BUILDER(Create_func_concat)},
1979
2886
  { { C_STRING_WITH_LEN("CONCAT_WS") }, BUILDER(Create_func_concat_ws)},
 
2887
  { { C_STRING_WITH_LEN("CONNECTION_ID") }, BUILDER(Create_func_connection_id)},
1980
2888
  { { C_STRING_WITH_LEN("CONV") }, BUILDER(Create_func_conv)},
 
2889
  { { C_STRING_WITH_LEN("COS") }, BUILDER(Create_func_cos)},
1981
2890
  { { C_STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)},
1982
2891
  { { C_STRING_WITH_LEN("DATEDIFF") }, BUILDER(Create_func_datediff)},
1983
2892
  { { C_STRING_WITH_LEN("DATE_FORMAT") }, BUILDER(Create_func_date_format)},
1986
2895
  { { C_STRING_WITH_LEN("DAYOFWEEK") }, BUILDER(Create_func_dayofweek)},
1987
2896
  { { C_STRING_WITH_LEN("DAYOFYEAR") }, BUILDER(Create_func_dayofyear)},
1988
2897
  { { C_STRING_WITH_LEN("DEGREES") }, BUILDER(Create_func_degrees)},
 
2898
  { { C_STRING_WITH_LEN("ELT") }, BUILDER(Create_func_elt)},
 
2899
  { { C_STRING_WITH_LEN("EXP") }, BUILDER(Create_func_exp)},
1989
2900
  { { C_STRING_WITH_LEN("EXPORT_SET") }, BUILDER(Create_func_export_set)},
1990
2901
  { { C_STRING_WITH_LEN("FIELD") }, BUILDER(Create_func_field)},
1991
2902
  { { C_STRING_WITH_LEN("FIND_IN_SET") }, BUILDER(Create_func_find_in_set)},
 
2903
  { { C_STRING_WITH_LEN("FLOOR") }, BUILDER(Create_func_floor)},
 
2904
  { { C_STRING_WITH_LEN("FORMAT") }, BUILDER(Create_func_format)},
1992
2905
  { { C_STRING_WITH_LEN("FOUND_ROWS") }, BUILDER(Create_func_found_rows)},
1993
2906
  { { C_STRING_WITH_LEN("FROM_DAYS") }, BUILDER(Create_func_from_days)},
1994
2907
  { { C_STRING_WITH_LEN("FROM_UNIXTIME") }, BUILDER(Create_func_from_unixtime)},
1995
2908
  { { C_STRING_WITH_LEN("GREATEST") }, BUILDER(Create_func_greatest)},
 
2909
  { { C_STRING_WITH_LEN("HEX") }, BUILDER(Create_func_hex)},
1996
2910
  { { C_STRING_WITH_LEN("IFNULL") }, BUILDER(Create_func_ifnull)},
1997
2911
  { { C_STRING_WITH_LEN("INSTR") }, BUILDER(Create_func_instr)},
1998
2912
  { { C_STRING_WITH_LEN("ISNULL") }, BUILDER(Create_func_isnull)},
2000
2914
  { { C_STRING_WITH_LEN("LAST_INSERT_ID") }, BUILDER(Create_func_last_insert_id)},
2001
2915
  { { C_STRING_WITH_LEN("LCASE") }, BUILDER(Create_func_lcase)},
2002
2916
  { { C_STRING_WITH_LEN("LEAST") }, BUILDER(Create_func_least)},
 
2917
  { { C_STRING_WITH_LEN("LENGTH") }, BUILDER(Create_func_length)},
 
2918
  { { C_STRING_WITH_LEN("LN") }, BUILDER(Create_func_ln)},
2003
2919
  { { C_STRING_WITH_LEN("LOAD_FILE") }, BUILDER(Create_func_load_file)},
2004
2920
  { { C_STRING_WITH_LEN("LOCATE") }, BUILDER(Create_func_locate)},
 
2921
  { { C_STRING_WITH_LEN("LOG") }, BUILDER(Create_func_log)},
 
2922
  { { C_STRING_WITH_LEN("LOG10") }, BUILDER(Create_func_log10)},
 
2923
  { { C_STRING_WITH_LEN("LOG2") }, BUILDER(Create_func_log2)},
2005
2924
  { { C_STRING_WITH_LEN("LOWER") }, BUILDER(Create_func_lcase)},
2006
2925
  { { C_STRING_WITH_LEN("LPAD") }, BUILDER(Create_func_lpad)},
2007
2926
  { { C_STRING_WITH_LEN("LTRIM") }, BUILDER(Create_func_ltrim)},
2010
2929
  { { C_STRING_WITH_LEN("MONTHNAME") }, BUILDER(Create_func_monthname)},
2011
2930
  { { C_STRING_WITH_LEN("NULLIF") }, BUILDER(Create_func_nullif)},
2012
2931
  { { C_STRING_WITH_LEN("OCT") }, BUILDER(Create_func_oct)},
 
2932
  { { C_STRING_WITH_LEN("OCTET_LENGTH") }, BUILDER(Create_func_length)},
 
2933
  { { C_STRING_WITH_LEN("ORD") }, BUILDER(Create_func_ord)},
2013
2934
  { { C_STRING_WITH_LEN("PERIOD_ADD") }, BUILDER(Create_func_period_add)},
2014
2935
  { { C_STRING_WITH_LEN("PERIOD_DIFF") }, BUILDER(Create_func_period_diff)},
2015
2936
  { { C_STRING_WITH_LEN("PI") }, BUILDER(Create_func_pi)},
 
2937
  { { C_STRING_WITH_LEN("POW") }, BUILDER(Create_func_pow)},
 
2938
  { { C_STRING_WITH_LEN("POWER") }, BUILDER(Create_func_pow)},
 
2939
  { { C_STRING_WITH_LEN("QUOTE") }, BUILDER(Create_func_quote)},
2016
2940
  { { C_STRING_WITH_LEN("RADIANS") }, BUILDER(Create_func_radians)},
 
2941
  { { C_STRING_WITH_LEN("RAND") }, BUILDER(Create_func_rand)},
2017
2942
  { { C_STRING_WITH_LEN("ROUND") }, BUILDER(Create_func_round)},
2018
2943
  { { C_STRING_WITH_LEN("ROW_COUNT") }, BUILDER(Create_func_row_count)},
2019
2944
  { { C_STRING_WITH_LEN("RPAD") }, BUILDER(Create_func_rpad)},
2020
2945
  { { C_STRING_WITH_LEN("RTRIM") }, BUILDER(Create_func_rtrim)},
2021
2946
  { { C_STRING_WITH_LEN("SIGN") }, BUILDER(Create_func_sign)},
 
2947
  { { C_STRING_WITH_LEN("SIN") }, BUILDER(Create_func_sin)},
2022
2948
  { { C_STRING_WITH_LEN("SPACE") }, BUILDER(Create_func_space)},
 
2949
  { { C_STRING_WITH_LEN("SQRT") }, BUILDER(Create_func_sqrt)},
2023
2950
  { { C_STRING_WITH_LEN("STRCMP") }, BUILDER(Create_func_strcmp)},
 
2951
  { { C_STRING_WITH_LEN("SUBSTRING_INDEX") }, BUILDER(Create_func_substr_index)},
2024
2952
  { { C_STRING_WITH_LEN("TAN") }, BUILDER(Create_func_tan)},
2025
2953
  { { C_STRING_WITH_LEN("TIME_FORMAT") }, BUILDER(Create_func_time_format)},
2026
2954
  { { C_STRING_WITH_LEN("TO_DAYS") }, BUILDER(Create_func_to_days)},
2027
2955
  { { C_STRING_WITH_LEN("UCASE") }, BUILDER(Create_func_ucase)},
 
2956
  { { C_STRING_WITH_LEN("UNHEX") }, BUILDER(Create_func_unhex)},
2028
2957
  { { C_STRING_WITH_LEN("UNIX_TIMESTAMP") }, BUILDER(Create_func_unix_timestamp)},
2029
2958
  { { C_STRING_WITH_LEN("UPPER") }, BUILDER(Create_func_ucase)},
 
2959
  { { C_STRING_WITH_LEN("UUID") }, BUILDER(Create_func_uuid)},
 
2960
  { { C_STRING_WITH_LEN("VERSION") }, BUILDER(Create_func_version)},
2030
2961
  { { C_STRING_WITH_LEN("WEEKDAY") }, BUILDER(Create_func_weekday)},
2031
2962
 
2032
2963
  { {0, 0}, NULL}
2033
2964
};
2034
2965
 
 
2966
static map<string, Native_func_registry *> native_functions_map;
 
2967
 
2035
2968
/*
2036
2969
  Load the hash table for native functions.
2037
2970
  Note: this code is not thread safe, and is intended to be used at server
2046
2979
  for (func= func_array; func->builder != NULL; func++)
2047
2980
  {
2048
2981
    func_name.assign(func->name.str, func->name.length);
 
2982
    transform(func_name.begin(), func_name.end(), func_name.begin(), ::tolower);
2049
2983
 
2050
 
    FunctionContainer::getMap()[func_name]= func->builder;
 
2984
    native_functions_map[func_name]= func;
2051
2985
  }
2052
2986
 
2053
2987
  return 0;
2057
2991
Create_func *
2058
2992
find_native_function_builder(LEX_STRING name)
2059
2993
{
 
2994
  Native_func_registry *func;
2060
2995
  Create_func *builder= NULL;
2061
2996
 
2062
2997
  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())
 
2998
  transform(func_name.begin(), func_name.end(), func_name.begin(), ::tolower);
 
2999
 
 
3000
  map<string, Native_func_registry *>::iterator func_iter=
 
3001
    native_functions_map.find(func_name);
 
3002
 
 
3003
  if (func_iter != native_functions_map.end())
2068
3004
  {
2069
 
    builder= (*func_iter).second;
 
3005
    func= (*func_iter).second;
 
3006
    builder= func->builder;
2070
3007
  }
2071
3008
 
2072
3009
  return builder;
2086
3023
                 const char *c_len, const char *c_dec,
2087
3024
                 const CHARSET_INFO * const cs)
2088
3025
{
2089
 
  Item *res= NULL;
 
3026
  Item *res;
2090
3027
  uint32_t len;
2091
3028
  uint32_t dec;
2092
3029
 
2093
3030
  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
3031
  case ITEM_CAST_BINARY:
2103
3032
    res= new (session->mem_root) Item_func_binary(a);
2104
3033
    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
 
 
 
3034
  case ITEM_CAST_SIGNED_INT:
 
3035
    res= new (session->mem_root) Item_func_signed(a);
 
3036
    break;
 
3037
  case ITEM_CAST_UNSIGNED_INT:
 
3038
    res= new (session->mem_root) Item_func_unsigned(a);
 
3039
    break;
2114
3040
  case ITEM_CAST_DATE:
2115
3041
    res= new (session->mem_root) Item_date_typecast(a);
2116
3042
    break;
2117
 
 
2118
3043
  case ITEM_CAST_DATETIME:
2119
3044
    res= new (session->mem_root) Item_datetime_typecast(a);
2120
3045
    break;
2121
 
 
2122
3046
  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
 
    }
 
3047
  {
 
3048
    len= c_len ? atoi(c_len) : 0;
 
3049
    dec= c_dec ? atoi(c_dec) : 0;
 
3050
    my_decimal_trim(&len, &dec);
 
3051
    if (len < dec)
 
3052
    {
 
3053
      my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
 
3054
      return 0;
 
3055
    }
 
3056
    if (len > DECIMAL_MAX_PRECISION)
 
3057
    {
 
3058
      my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name,
 
3059
               DECIMAL_MAX_PRECISION);
 
3060
      return 0;
 
3061
    }
 
3062
    if (dec > DECIMAL_MAX_SCALE)
 
3063
    {
 
3064
      my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name,
 
3065
               DECIMAL_MAX_SCALE);
 
3066
      return 0;
 
3067
    }
 
3068
    res= new (session->mem_root) Item_decimal_typecast(a, len, dec);
 
3069
    break;
 
3070
  }
2147
3071
  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
 
 
 
3072
  {
 
3073
    len= c_len ? atoi(c_len) : -1;
 
3074
    res= create_func_char_cast(session, a, len, cs);
 
3075
    break;
 
3076
  }
 
3077
  default:
 
3078
  {
 
3079
    assert(0);
 
3080
    res= 0;
 
3081
    break;
 
3082
  }
 
3083
  }
2155
3084
  return res;
2156
3085
}
2157
 
 
2158
 
} /* namespace drizzled */