~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/create.cc

  • Committer: Monty Taylor
  • Date: 2009-03-04 02:48:12 UTC
  • mto: (917.1.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 918.
  • Revision ID: mordred@inaugust.com-20090304024812-5wb6wpye5c1iitbq
Applied atomic patch to current tree.

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>
 
117
 
 
118
#include <map>
85
119
 
86
120
using namespace std;
87
121
 
88
 
namespace drizzled
89
 
{
90
 
 
91
122
class Item;
92
123
 
93
124
 
240
271
  it helps to compare code between versions, and helps with merges conflicts.
241
272
*/
242
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
 
243
345
 
244
346
class Create_func_bin : public Create_func_arg1
245
347
{
255
357
  virtual ~Create_func_bin() {}
256
358
};
257
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
 
258
436
class Create_func_concat : public Create_native_func
259
437
{
260
438
public:
281
459
};
282
460
 
283
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
 
284
477
class Create_func_conv : public Create_func_arg3
285
478
{
286
479
public:
295
488
  virtual ~Create_func_conv() {}
296
489
};
297
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
 
298
507
class Create_func_cot : public Create_func_arg1
299
508
{
300
509
public:
428
637
  virtual ~Create_func_degrees() {}
429
638
};
430
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
 
431
669
class Create_func_export_set : public Create_native_func
432
670
{
433
 
 
434
671
public:
435
672
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
436
673
 
469
706
  virtual ~Create_func_find_in_set() {}
470
707
};
471
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
 
472
740
class Create_func_found_rows : public Create_func_arg0
473
741
{
474
742
public:
525
793
};
526
794
 
527
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
 
528
811
class Create_func_ifnull : public Create_func_arg2
529
812
{
530
813
public:
625
908
  virtual ~Create_func_least() {}
626
909
};
627
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
 
628
942
class Create_func_load_file : public Create_func_arg1
629
943
{
630
944
public:
653
967
};
654
968
 
655
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
 
656
1013
class Create_func_lpad : public Create_func_arg3
657
1014
{
658
1015
public:
769
1126
  virtual ~Create_func_oct() {}
770
1127
};
771
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
 
772
1145
class Create_func_period_add : public Create_func_arg2
773
1146
{
774
1147
public:
813
1186
  virtual ~Create_func_pi() {}
814
1187
};
815
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
 
816
1220
class Create_func_radians : public Create_func_arg1
817
1221
{
818
1222
public:
828
1232
};
829
1233
 
830
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
 
831
1248
class Create_func_round : public Create_native_func
832
1249
{
833
1250
public:
899
1316
  virtual ~Create_func_sign() {}
900
1317
};
901
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
 
902
1335
class Create_func_space : public Create_func_arg1
903
1336
{
904
1337
public:
913
1346
  virtual ~Create_func_space() {}
914
1347
};
915
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
 
916
1365
class Create_func_strcmp : public Create_func_arg2
917
1366
{
918
1367
public:
928
1377
};
929
1378
 
930
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
 
931
1395
class Create_func_tan : public Create_func_arg1
932
1396
{
933
1397
public:
1003
1467
};
1004
1468
 
1005
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
 
1006
1485
class Create_func_unix_timestamp : public Create_native_func
1007
1486
{
1008
1487
public:
1016
1495
};
1017
1496
 
1018
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
 
1019
1528
class Create_func_weekday : public Create_func_arg1
1020
1529
{
1021
1530
public:
1065
1574
Item*
1066
1575
Create_udf_func::create(Session *session, LEX_STRING name, List<Item> *item_list)
1067
1576
{
1068
 
  const plugin::Function *udf= plugin::Function::get(name.str, name.length);
 
1577
  udf_func *udf= find_udf(name.str, name.length);
1069
1578
  assert(udf);
1070
1579
  return create(session, udf, item_list);
1071
1580
}
1072
1581
 
1073
1582
 
1074
1583
Item*
1075
 
Create_udf_func::create(Session *session, const plugin::Function *udf,
1076
 
                        List<Item> *item_list)
 
1584
Create_udf_func::create(Session *session, udf_func *udf, List<Item> *item_list)
1077
1585
{
1078
1586
  Item_func *func= NULL;
1079
1587
  int arg_count= 0;
1081
1589
  if (item_list != NULL)
1082
1590
    arg_count= item_list->elements;
1083
1591
 
1084
 
  func= (*udf)(session->mem_root);
1085
 
 
1086
 
  if(!func->check_argument_count(arg_count))
1087
 
  {
1088
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), func->func_name());
1089
 
    return NULL;
1090
 
  }
1091
 
 
1092
 
  if(item_list)
1093
 
    func->set_arguments(*item_list);
 
1592
  func= udf->create_func(session->mem_root);
 
1593
 
 
1594
  func->set_arguments(*item_list);
1094
1595
 
1095
1596
  return func;
1096
1597
}
1119
1620
 
1120
1621
  if (arg_count != 0)
1121
1622
  {
1122
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1623
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1123
1624
    return NULL;
1124
1625
  }
1125
1626
 
1137
1638
 
1138
1639
  if (arg_count != 1)
1139
1640
  {
1140
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1641
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1141
1642
    return NULL;
1142
1643
  }
1143
1644
 
1163
1664
 
1164
1665
  if (arg_count != 2)
1165
1666
  {
1166
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1667
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1167
1668
    return NULL;
1168
1669
  }
1169
1670
 
1191
1692
 
1192
1693
  if (arg_count != 3)
1193
1694
  {
1194
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1695
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1195
1696
    return NULL;
1196
1697
  }
1197
1698
 
1210
1711
  return create(session, param_1, param_2, param_3);
1211
1712
}
1212
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
 
1213
1787
Create_func_bin Create_func_bin::s_singleton;
1214
1788
 
1215
1789
Item*
1220
1794
  return new (session->mem_root) Item_func_conv(arg1, i10, i2);
1221
1795
}
1222
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
 
1223
1843
Create_func_concat Create_func_concat::s_singleton;
1224
1844
 
1225
1845
Item*
1233
1853
 
1234
1854
  if (arg_count < 1)
1235
1855
  {
1236
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1856
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1237
1857
    return NULL;
1238
1858
  }
1239
1859
 
1240
 
  return new (session->mem_root) Item_func_concat(*session, *item_list);
 
1860
  return new (session->mem_root) Item_func_concat(*item_list);
1241
1861
}
1242
1862
 
1243
1863
 
1255
1875
  /* "WS" stands for "With Separator": this function takes 2+ arguments */
1256
1876
  if (arg_count < 2)
1257
1877
  {
1258
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
1878
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1259
1879
    return NULL;
1260
1880
  }
1261
1881
 
1262
 
  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();
1263
1892
}
1264
1893
 
1265
1894
 
1271
1900
  return new (session->mem_root) Item_func_conv(arg1, arg2, arg3);
1272
1901
}
1273
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
 
1274
1913
Create_func_cot Create_func_cot::s_singleton;
1275
1914
 
1276
1915
Item*
1278
1917
{
1279
1918
  Item *i1= new (session->mem_root) Item_int((char*) "1", 1, 1);
1280
1919
  Item *i2= new (session->mem_root) Item_func_tan(arg1);
1281
 
  return new (session->mem_root) Item_func_div(session, i1, i2);
 
1920
  return new (session->mem_root) Item_func_div(i1, i2);
1282
1921
}
1283
1922
 
1284
1923
Create_func_date_format Create_func_date_format::s_singleton;
1347
1986
                                             180/M_PI, 0.0);
1348
1987
}
1349
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
 
1350
2020
Create_func_export_set Create_func_export_set::s_singleton;
1351
2021
 
1352
2022
Item*
1391
2061
  }
1392
2062
  default:
1393
2063
  {
1394
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2064
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1395
2065
    break;
1396
2066
  }
1397
2067
  }
1413
2083
 
1414
2084
  if (arg_count < 2)
1415
2085
  {
1416
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2086
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1417
2087
    return NULL;
1418
2088
  }
1419
2089
 
1429
2099
  return new (session->mem_root) Item_func_find_in_set(arg1, arg2);
1430
2100
}
1431
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
 
1432
2121
Create_func_found_rows Create_func_found_rows::s_singleton;
1433
2122
 
1434
2123
Item*
1476
2165
  }
1477
2166
  default:
1478
2167
  {
1479
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2168
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1480
2169
    break;
1481
2170
  }
1482
2171
  }
1498
2187
 
1499
2188
  if (arg_count < 2)
1500
2189
  {
1501
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2190
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1502
2191
    return NULL;
1503
2192
  }
1504
2193
 
1505
2194
  return new (session->mem_root) Item_func_max(*item_list);
1506
2195
}
1507
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
 
1508
2207
Create_func_ifnull Create_func_ifnull::s_singleton;
1509
2208
 
1510
2209
Item*
1567
2266
  }
1568
2267
  default:
1569
2268
  {
1570
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2269
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1571
2270
    break;
1572
2271
  }
1573
2272
  }
1598
2297
 
1599
2298
  if (arg_count < 2)
1600
2299
  {
1601
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2300
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1602
2301
    return NULL;
1603
2302
  }
1604
2303
 
1605
2304
  return new (session->mem_root) Item_func_min(*item_list);
1606
2305
}
1607
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
 
1608
2326
Create_func_load_file Create_func_load_file::s_singleton;
1609
2327
 
1610
2328
Item*
1611
2329
Create_func_load_file::create(Session *session, Item *arg1)
1612
2330
{
1613
 
  return new (session->mem_root) Item_load_file(*session, arg1);
 
2331
  return new (session->mem_root) Item_load_file(arg1);
1614
2332
}
1615
2333
 
1616
2334
 
1646
2364
  }
1647
2365
  default:
1648
2366
  {
1649
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1650
 
    break;
1651
 
  }
1652
 
  }
1653
 
 
1654
 
  return func;
1655
 
}
 
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
 
1656
2430
 
1657
2431
Create_func_lpad Create_func_lpad::s_singleton;
1658
2432
 
1659
2433
Item*
1660
2434
Create_func_lpad::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
1661
2435
{
1662
 
  return new (session->mem_root) Item_func_lpad(*session, arg1, arg2, arg3);
 
2436
  return new (session->mem_root) Item_func_lpad(arg1, arg2, arg3);
1663
2437
}
1664
2438
 
1665
2439
 
1684
2458
Create_func_make_set Create_func_make_set::s_singleton;
1685
2459
 
1686
2460
Item*
1687
 
Create_func_make_set::create_native(Session *session_arg, LEX_STRING name,
 
2461
Create_func_make_set::create_native(Session *session, LEX_STRING name,
1688
2462
                                    List<Item> *item_list)
1689
2463
{
1690
2464
  int arg_count= 0;
1694
2468
 
1695
2469
  if (arg_count < 2)
1696
2470
  {
1697
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2471
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1698
2472
    return NULL;
1699
2473
  }
1700
2474
 
1701
2475
  Item *param_1= item_list->pop();
1702
 
  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);
1703
2477
}
1704
2478
 
1705
2479
 
1731
2505
  return new (session->mem_root) Item_func_conv(arg1, i10, i8);
1732
2506
}
1733
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
 
1734
2518
Create_func_period_add Create_func_period_add::s_singleton;
1735
2519
 
1736
2520
Item*
1757
2541
  return new (session->mem_root) Item_static_float_func("pi()", M_PI, 6, 8);
1758
2542
}
1759
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
 
1760
2563
Create_func_radians Create_func_radians::s_singleton;
1761
2564
 
1762
2565
Item*
1766
2569
                                             M_PI/180, 0.0);
1767
2570
}
1768
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
 
1769
2608
Create_func_round Create_func_round::s_singleton;
1770
2609
 
1771
2610
Item*
1795
2634
  }
1796
2635
  default:
1797
2636
  {
1798
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2637
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1799
2638
    break;
1800
2639
  }
1801
2640
  }
1818
2657
Item*
1819
2658
Create_func_rpad::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
1820
2659
{
1821
 
  return new (session->mem_root) Item_func_rpad(*session, arg1, arg2, arg3);
 
2660
  return new (session->mem_root) Item_func_rpad(arg1, arg2, arg3);
1822
2661
}
1823
2662
 
1824
2663
 
1839
2678
  return new (session->mem_root) Item_func_sign(arg1);
1840
2679
}
1841
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
 
1842
2691
Create_func_space Create_func_space::s_singleton;
1843
2692
 
1844
2693
Item*
1854
2703
 
1855
2704
  if (cs->mbminlen > 1)
1856
2705
  {
1857
 
    size_t dummy_errors;
1858
 
    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);
1859
2708
    sp->str_value.copy(" ", 1, &my_charset_utf8_general_ci, cs, &dummy_errors);
1860
2709
  }
1861
2710
  else
1862
2711
  {
1863
 
    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);
1864
2713
  }
1865
2714
 
1866
 
  return new (session->mem_root) Item_func_repeat(*session, sp, arg1);
1867
 
}
 
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
 
1868
2727
 
1869
2728
Create_func_strcmp Create_func_strcmp::s_singleton;
1870
2729
 
1875
2734
}
1876
2735
 
1877
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
 
1878
2745
Create_func_tan Create_func_tan::s_singleton;
1879
2746
 
1880
2747
Item*
1909
2776
  return new (session->mem_root) Item_func_ucase(arg1);
1910
2777
}
1911
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
 
1912
2789
Create_func_unix_timestamp Create_func_unix_timestamp::s_singleton;
1913
2790
 
1914
2791
Item*
1935
2812
  }
1936
2813
  default:
1937
2814
  {
1938
 
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
 
2815
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
1939
2816
    break;
1940
2817
  }
1941
2818
  }
1944
2821
}
1945
2822
 
1946
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
 
1947
2846
Create_func_weekday Create_func_weekday::s_singleton;
1948
2847
 
1949
2848
Item*
1969
2868
 
1970
2869
static Native_func_registry func_array[] =
1971
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)},
1972
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)},
1973
2885
  { { C_STRING_WITH_LEN("CONCAT") }, BUILDER(Create_func_concat)},
1974
2886
  { { C_STRING_WITH_LEN("CONCAT_WS") }, BUILDER(Create_func_concat_ws)},
 
2887
  { { C_STRING_WITH_LEN("CONNECTION_ID") }, BUILDER(Create_func_connection_id)},
1975
2888
  { { C_STRING_WITH_LEN("CONV") }, BUILDER(Create_func_conv)},
 
2889
  { { C_STRING_WITH_LEN("COS") }, BUILDER(Create_func_cos)},
1976
2890
  { { C_STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)},
1977
2891
  { { C_STRING_WITH_LEN("DATEDIFF") }, BUILDER(Create_func_datediff)},
1978
2892
  { { C_STRING_WITH_LEN("DATE_FORMAT") }, BUILDER(Create_func_date_format)},
1981
2895
  { { C_STRING_WITH_LEN("DAYOFWEEK") }, BUILDER(Create_func_dayofweek)},
1982
2896
  { { C_STRING_WITH_LEN("DAYOFYEAR") }, BUILDER(Create_func_dayofyear)},
1983
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)},
1984
2900
  { { C_STRING_WITH_LEN("EXPORT_SET") }, BUILDER(Create_func_export_set)},
1985
2901
  { { C_STRING_WITH_LEN("FIELD") }, BUILDER(Create_func_field)},
1986
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)},
1987
2905
  { { C_STRING_WITH_LEN("FOUND_ROWS") }, BUILDER(Create_func_found_rows)},
1988
2906
  { { C_STRING_WITH_LEN("FROM_DAYS") }, BUILDER(Create_func_from_days)},
1989
2907
  { { C_STRING_WITH_LEN("FROM_UNIXTIME") }, BUILDER(Create_func_from_unixtime)},
1990
2908
  { { C_STRING_WITH_LEN("GREATEST") }, BUILDER(Create_func_greatest)},
 
2909
  { { C_STRING_WITH_LEN("HEX") }, BUILDER(Create_func_hex)},
1991
2910
  { { C_STRING_WITH_LEN("IFNULL") }, BUILDER(Create_func_ifnull)},
1992
2911
  { { C_STRING_WITH_LEN("INSTR") }, BUILDER(Create_func_instr)},
1993
2912
  { { C_STRING_WITH_LEN("ISNULL") }, BUILDER(Create_func_isnull)},
1995
2914
  { { C_STRING_WITH_LEN("LAST_INSERT_ID") }, BUILDER(Create_func_last_insert_id)},
1996
2915
  { { C_STRING_WITH_LEN("LCASE") }, BUILDER(Create_func_lcase)},
1997
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)},
1998
2919
  { { C_STRING_WITH_LEN("LOAD_FILE") }, BUILDER(Create_func_load_file)},
1999
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)},
2000
2924
  { { C_STRING_WITH_LEN("LOWER") }, BUILDER(Create_func_lcase)},
2001
2925
  { { C_STRING_WITH_LEN("LPAD") }, BUILDER(Create_func_lpad)},
2002
2926
  { { C_STRING_WITH_LEN("LTRIM") }, BUILDER(Create_func_ltrim)},
2005
2929
  { { C_STRING_WITH_LEN("MONTHNAME") }, BUILDER(Create_func_monthname)},
2006
2930
  { { C_STRING_WITH_LEN("NULLIF") }, BUILDER(Create_func_nullif)},
2007
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)},
2008
2934
  { { C_STRING_WITH_LEN("PERIOD_ADD") }, BUILDER(Create_func_period_add)},
2009
2935
  { { C_STRING_WITH_LEN("PERIOD_DIFF") }, BUILDER(Create_func_period_diff)},
2010
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)},
2011
2940
  { { C_STRING_WITH_LEN("RADIANS") }, BUILDER(Create_func_radians)},
 
2941
  { { C_STRING_WITH_LEN("RAND") }, BUILDER(Create_func_rand)},
2012
2942
  { { C_STRING_WITH_LEN("ROUND") }, BUILDER(Create_func_round)},
2013
2943
  { { C_STRING_WITH_LEN("ROW_COUNT") }, BUILDER(Create_func_row_count)},
2014
2944
  { { C_STRING_WITH_LEN("RPAD") }, BUILDER(Create_func_rpad)},
2015
2945
  { { C_STRING_WITH_LEN("RTRIM") }, BUILDER(Create_func_rtrim)},
2016
2946
  { { C_STRING_WITH_LEN("SIGN") }, BUILDER(Create_func_sign)},
 
2947
  { { C_STRING_WITH_LEN("SIN") }, BUILDER(Create_func_sin)},
2017
2948
  { { C_STRING_WITH_LEN("SPACE") }, BUILDER(Create_func_space)},
 
2949
  { { C_STRING_WITH_LEN("SQRT") }, BUILDER(Create_func_sqrt)},
2018
2950
  { { C_STRING_WITH_LEN("STRCMP") }, BUILDER(Create_func_strcmp)},
 
2951
  { { C_STRING_WITH_LEN("SUBSTRING_INDEX") }, BUILDER(Create_func_substr_index)},
2019
2952
  { { C_STRING_WITH_LEN("TAN") }, BUILDER(Create_func_tan)},
2020
2953
  { { C_STRING_WITH_LEN("TIME_FORMAT") }, BUILDER(Create_func_time_format)},
2021
2954
  { { C_STRING_WITH_LEN("TO_DAYS") }, BUILDER(Create_func_to_days)},
2022
2955
  { { C_STRING_WITH_LEN("UCASE") }, BUILDER(Create_func_ucase)},
 
2956
  { { C_STRING_WITH_LEN("UNHEX") }, BUILDER(Create_func_unhex)},
2023
2957
  { { C_STRING_WITH_LEN("UNIX_TIMESTAMP") }, BUILDER(Create_func_unix_timestamp)},
2024
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)},
2025
2961
  { { C_STRING_WITH_LEN("WEEKDAY") }, BUILDER(Create_func_weekday)},
2026
2962
 
2027
2963
  { {0, 0}, NULL}
2028
2964
};
2029
2965
 
 
2966
static map<string, Native_func_registry *> native_functions_map;
 
2967
 
2030
2968
/*
2031
2969
  Load the hash table for native functions.
2032
2970
  Note: this code is not thread safe, and is intended to be used at server
2041
2979
  for (func= func_array; func->builder != NULL; func++)
2042
2980
  {
2043
2981
    func_name.assign(func->name.str, func->name.length);
 
2982
    transform(func_name.begin(), func_name.end(), func_name.begin(), ::tolower);
2044
2983
 
2045
 
    FunctionContainer::getMap()[func_name]= func;
 
2984
    native_functions_map[func_name]= func;
2046
2985
  }
2047
2986
 
2048
2987
  return 0;
2056
2995
  Create_func *builder= NULL;
2057
2996
 
2058
2997
  string func_name(name.str, name.length);
2059
 
 
2060
 
  NativeFunctionsMap::iterator func_iter=
2061
 
    FunctionContainer::getMap().find(func_name);
2062
 
 
2063
 
  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())
2064
3004
  {
2065
3005
    func= (*func_iter).second;
2066
3006
    builder= func->builder;
2091
3031
  case ITEM_CAST_BINARY:
2092
3032
    res= new (session->mem_root) Item_func_binary(a);
2093
3033
    break;
 
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;
2094
3040
  case ITEM_CAST_DATE:
2095
3041
    res= new (session->mem_root) Item_date_typecast(a);
2096
3042
    break;
2137
3083
  }
2138
3084
  return res;
2139
3085
}
2140
 
 
2141
 
} /* namespace drizzled */