~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/create.cc

pandora-build v0.100 - Fixes several bugs found by cb1kenobi. Add several thoughts from folks at LCA.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
  Functions to create an item. Used by sql_yac.yy
21
21
*/
22
22
 
23
 
#include <drizzled/server_includes.h>
 
23
#include "config.h"
 
24
#include <drizzled/item/create.h>
 
25
#include <drizzled/item/func.h>
 
26
#include <drizzled/error.h>
 
27
 
 
28
#include <drizzled/function/str/binary.h>
 
29
#include <drizzled/function/str/concat.h>
 
30
#include <drizzled/function/str/conv.h>
 
31
#include <drizzled/function/str/elt.h>
 
32
#include <drizzled/function/str/export_set.h>
 
33
#include <drizzled/function/str/format.h>
 
34
#include <drizzled/function/str/hex.h>
 
35
#include <drizzled/function/str/load_file.h>
 
36
#include <drizzled/function/str/make_set.h>
 
37
#include <drizzled/function/str/pad.h>
 
38
#include <drizzled/function/str/repeat.h>
 
39
#include <drizzled/function/str/str_conv.h>
 
40
#include <drizzled/function/str/substr.h>
 
41
#include <drizzled/function/str/trim.h>
 
42
#include <drizzled/function/str/uuid.h>
 
43
 
 
44
#include <drizzled/function/time/date_format.h>
 
45
#include <drizzled/function/time/dayname.h>
 
46
#include <drizzled/function/time/dayofmonth.h>
 
47
#include <drizzled/function/time/dayofyear.h>
 
48
#include <drizzled/function/time/from_unixtime.h>
 
49
#include <drizzled/function/time/from_days.h>
 
50
#include <drizzled/function/time/last_day.h>
 
51
#include <drizzled/function/time/makedate.h>
 
52
#include <drizzled/function/time/month.h>
 
53
#include <drizzled/function/time/period_add.h>
 
54
#include <drizzled/function/time/period_diff.h>
 
55
#include <drizzled/function/time/to_days.h>
 
56
#include <drizzled/function/time/typecast.h>
 
57
#include <drizzled/function/time/unix_timestamp.h>
 
58
#include <drizzled/function/time/weekday.h>
 
59
 
 
60
#include <drizzled/item/cmpfunc.h>
 
61
#include <drizzled/plugin/function.h>
 
62
#include <drizzled/session.h>
 
63
 
 
64
/* Function declarations */
 
65
 
 
66
#include <drizzled/function/func.h>
 
67
#include <drizzled/function/math/abs.h>
 
68
#include <drizzled/function/math/acos.h>
 
69
#include <drizzled/function/additive_op.h>
 
70
#include <drizzled/function/math/asin.h>
 
71
#include <drizzled/function/math/atan.h>
 
72
#include <drizzled/function/math/ceiling.h>
 
73
#include <drizzled/function/coercibility.h>
 
74
#include <drizzled/function/math/cos.h>
 
75
#include <drizzled/function/math/dec.h>
 
76
#include <drizzled/function/math/decimal_typecast.h>
 
77
#include <drizzled/function/math//exp.h>
 
78
#include <drizzled/function/field.h>
 
79
#include <drizzled/function/find_in_set.h>
 
80
#include <drizzled/function/math/floor.h>
 
81
#include <drizzled/function/found_rows.h>
 
82
#include <drizzled/function/get_system_var.h>
 
83
#include <drizzled/function/math/int_val.h>
 
84
#include <drizzled/function/math/integer.h>
 
85
#include <drizzled/function/last_insert.h>
 
86
#include <drizzled/function/math/ln.h>
 
87
#include <drizzled/function/locate.h>
 
88
#include <drizzled/function/math/log.h>
 
89
#include <drizzled/function/min_max.h>
 
90
#include <drizzled/function/num1.h>
 
91
#include <drizzled/function/num_op.h>
 
92
#include <drizzled/function/numhybrid.h>
 
93
#include <drizzled/function/math/ord.h>
 
94
#include <drizzled/function/math/pow.h>
 
95
#include <drizzled/function/math/rand.h>
 
96
#include <drizzled/function/math/real.h>
 
97
#include <drizzled/function/row_count.h>
 
98
#include <drizzled/function/set_user_var.h>
 
99
#include <drizzled/function/sign.h>
 
100
#include <drizzled/function/math/sin.h>
 
101
#include <drizzled/function/math/sqrt.h>
 
102
#include <drizzled/function/str/quote.h>
 
103
#include <drizzled/function/math/tan.h>
 
104
#include <drizzled/function/units.h>
 
105
 
 
106
#include <map>
 
107
 
 
108
using namespace std;
 
109
using namespace drizzled;
 
110
 
 
111
class Item;
 
112
 
24
113
 
25
114
/*
26
115
=============================================================================
39
128
class Create_native_func : public Create_func
40
129
{
41
130
public:
42
 
  virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
 
131
  virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
43
132
 
44
133
  /**
45
134
    Builder method, with no arguments.
46
 
    @param thd The current thread
 
135
    @param session The current thread
47
136
    @param name The native function name
48
137
    @param item_list The function parameters, none of which are named
49
138
    @return An item representing the function call
50
139
  */
51
 
  virtual Item *create_native(THD *thd, LEX_STRING name,
 
140
  virtual Item *create_native(Session *session, LEX_STRING name,
52
141
                              List<Item> *item_list) = 0;
53
142
 
54
143
protected:
66
155
class Create_func_arg0 : public Create_func
67
156
{
68
157
public:
69
 
  virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
 
158
  virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
70
159
 
71
160
  /**
72
161
    Builder method, with no arguments.
73
 
    @param thd The current thread
 
162
    @param session The current thread
74
163
    @return An item representing the function call
75
164
  */
76
 
  virtual Item *create(THD *thd) = 0;
 
165
  virtual Item *create(Session *session) = 0;
77
166
 
78
167
protected:
79
168
  /** Constructor. */
90
179
class Create_func_arg1 : public Create_func
91
180
{
92
181
public:
93
 
  virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
 
182
  virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
94
183
 
95
184
  /**
96
185
    Builder method, with one argument.
97
 
    @param thd The current thread
 
186
    @param session The current thread
98
187
    @param arg1 The first argument of the function
99
188
    @return An item representing the function call
100
189
  */
101
 
  virtual Item *create(THD *thd, Item *arg1) = 0;
 
190
  virtual Item *create(Session *session, Item *arg1) = 0;
102
191
 
103
192
protected:
104
193
  /** Constructor. */
115
204
class Create_func_arg2 : public Create_func
116
205
{
117
206
public:
118
 
  virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
 
207
  virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
119
208
 
120
209
  /**
121
210
    Builder method, with two arguments.
122
 
    @param thd The current thread
 
211
    @param session The current thread
123
212
    @param arg1 The first argument of the function
124
213
    @param arg2 The second argument of the function
125
214
    @return An item representing the function call
126
215
  */
127
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2) = 0;
 
216
  virtual Item *create(Session *session, Item *arg1, Item *arg2) = 0;
128
217
 
129
218
protected:
130
219
  /** Constructor. */
141
230
class Create_func_arg3 : public Create_func
142
231
{
143
232
public:
144
 
  virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
 
233
  virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
145
234
 
146
235
  /**
147
236
    Builder method, with three arguments.
148
 
    @param thd The current thread
 
237
    @param session The current thread
149
238
    @param arg1 The first argument of the function
150
239
    @param arg2 The second argument of the function
151
240
    @param arg3 The third argument of the function
152
241
    @return An item representing the function call
153
242
  */
154
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2, Item *arg3) = 0;
 
243
  virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3) = 0;
155
244
 
156
245
protected:
157
246
  /** Constructor. */
174
263
class Create_func_abs : public Create_func_arg1
175
264
{
176
265
public:
177
 
  virtual Item *create(THD *thd, Item *arg1);
 
266
  using Create_func_arg1::create;
 
267
 
 
268
  virtual Item *create(Session *session, Item *arg1);
178
269
 
179
270
  static Create_func_abs s_singleton;
180
271
 
187
278
class Create_func_acos : public Create_func_arg1
188
279
{
189
280
public:
190
 
  virtual Item *create(THD *thd, Item *arg1);
 
281
  using Create_func_arg1::create;
 
282
 
 
283
  virtual Item *create(Session *session, Item *arg1);
191
284
 
192
285
  static Create_func_acos s_singleton;
193
286
 
196
289
  virtual ~Create_func_acos() {}
197
290
};
198
291
 
199
 
 
200
 
class Create_func_addtime : public Create_func_arg2
201
 
{
202
 
public:
203
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
204
 
 
205
 
  static Create_func_addtime s_singleton;
206
 
 
207
 
protected:
208
 
  Create_func_addtime() {}
209
 
  virtual ~Create_func_addtime() {}
210
 
};
211
 
 
212
 
 
213
292
class Create_func_asin : public Create_func_arg1
214
293
{
215
294
public:
216
 
  virtual Item *create(THD *thd, Item *arg1);
 
295
  using Create_func_arg1::create;
 
296
 
 
297
  virtual Item *create(Session *session, Item *arg1);
217
298
 
218
299
  static Create_func_asin s_singleton;
219
300
 
226
307
class Create_func_atan : public Create_native_func
227
308
{
228
309
public:
229
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
310
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
230
311
 
231
312
  static Create_func_atan s_singleton;
232
313
 
235
316
  virtual ~Create_func_atan() {}
236
317
};
237
318
 
238
 
 
239
 
class Create_func_benchmark : public Create_func_arg2
240
 
{
241
 
public:
242
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
243
 
 
244
 
  static Create_func_benchmark s_singleton;
245
 
 
246
 
protected:
247
 
  Create_func_benchmark() {}
248
 
  virtual ~Create_func_benchmark() {}
249
 
};
250
 
 
251
 
 
252
319
class Create_func_bin : public Create_func_arg1
253
320
{
254
321
public:
255
 
  virtual Item *create(THD *thd, Item *arg1);
 
322
  using Create_func_arg1::create;
 
323
 
 
324
  virtual Item *create(Session *session, Item *arg1);
256
325
 
257
326
  static Create_func_bin s_singleton;
258
327
 
262
331
};
263
332
 
264
333
 
265
 
class Create_func_bit_count : public Create_func_arg1
266
 
{
267
 
public:
268
 
  virtual Item *create(THD *thd, Item *arg1);
269
 
 
270
 
  static Create_func_bit_count s_singleton;
271
 
 
272
 
protected:
273
 
  Create_func_bit_count() {}
274
 
  virtual ~Create_func_bit_count() {}
275
 
};
276
 
 
277
 
 
278
 
class Create_func_bit_length : public Create_func_arg1
279
 
{
280
 
public:
281
 
  virtual Item *create(THD *thd, Item *arg1);
282
 
 
283
 
  static Create_func_bit_length s_singleton;
284
 
 
285
 
protected:
286
 
  Create_func_bit_length() {}
287
 
  virtual ~Create_func_bit_length() {}
288
 
};
289
 
 
290
 
 
291
334
class Create_func_ceiling : public Create_func_arg1
292
335
{
293
336
public:
294
 
  virtual Item *create(THD *thd, Item *arg1);
 
337
  using Create_func_arg1::create;
 
338
 
 
339
  virtual Item *create(Session *session, Item *arg1);
295
340
 
296
341
  static Create_func_ceiling s_singleton;
297
342
 
301
346
};
302
347
 
303
348
 
304
 
class Create_func_char_length : public Create_func_arg1
305
 
{
306
 
public:
307
 
  virtual Item *create(THD *thd, Item *arg1);
308
 
 
309
 
  static Create_func_char_length s_singleton;
310
 
 
311
 
protected:
312
 
  Create_func_char_length() {}
313
 
  virtual ~Create_func_char_length() {}
314
 
};
315
 
 
316
 
 
317
349
class Create_func_coercibility : public Create_func_arg1
318
350
{
319
351
public:
320
 
  virtual Item *create(THD *thd, Item *arg1);
 
352
  using Create_func_arg1::create;
 
353
 
 
354
  virtual Item *create(Session *session, Item *arg1);
321
355
 
322
356
  static Create_func_coercibility s_singleton;
323
357
 
330
364
class Create_func_concat : public Create_native_func
331
365
{
332
366
public:
333
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
367
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
334
368
 
335
369
  static Create_func_concat s_singleton;
336
370
 
343
377
class Create_func_concat_ws : public Create_native_func
344
378
{
345
379
public:
346
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
380
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
347
381
 
348
382
  static Create_func_concat_ws s_singleton;
349
383
 
353
387
};
354
388
 
355
389
 
356
 
class Create_func_connection_id : public Create_func_arg0
357
 
{
358
 
public:
359
 
  virtual Item *create(THD *thd);
360
 
 
361
 
  static Create_func_connection_id s_singleton;
362
 
 
363
 
protected:
364
 
  Create_func_connection_id() {}
365
 
  virtual ~Create_func_connection_id() {}
366
 
};
367
 
 
368
 
 
369
390
class Create_func_conv : public Create_func_arg3
370
391
{
371
392
public:
372
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2, Item *arg3);
 
393
  using Create_func_arg3::create;
 
394
 
 
395
  virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3);
373
396
 
374
397
  static Create_func_conv s_singleton;
375
398
 
382
405
class Create_func_cos : public Create_func_arg1
383
406
{
384
407
public:
385
 
  virtual Item *create(THD *thd, Item *arg1);
 
408
  using Create_func_arg1::create;
 
409
 
 
410
  virtual Item *create(Session *session, Item *arg1);
386
411
 
387
412
  static Create_func_cos s_singleton;
388
413
 
395
420
class Create_func_cot : public Create_func_arg1
396
421
{
397
422
public:
398
 
  virtual Item *create(THD *thd, Item *arg1);
 
423
  using Create_func_arg1::create;
 
424
 
 
425
  virtual Item *create(Session *session, Item *arg1);
399
426
 
400
427
  static Create_func_cot s_singleton;
401
428
 
407
434
class Create_func_date_format : public Create_func_arg2
408
435
{
409
436
public:
410
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
437
  using Create_func_arg2::create;
 
438
 
 
439
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
411
440
 
412
441
  static Create_func_date_format s_singleton;
413
442
 
420
449
class Create_func_datediff : public Create_func_arg2
421
450
{
422
451
public:
423
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
452
  using Create_func_arg2::create;
 
453
 
 
454
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
424
455
 
425
456
  static Create_func_datediff s_singleton;
426
457
 
433
464
class Create_func_dayname : public Create_func_arg1
434
465
{
435
466
public:
436
 
  virtual Item *create(THD *thd, Item *arg1);
 
467
  using Create_func_arg1::create;
 
468
 
 
469
  virtual Item *create(Session *session, Item *arg1);
437
470
 
438
471
  static Create_func_dayname s_singleton;
439
472
 
446
479
class Create_func_dayofmonth : public Create_func_arg1
447
480
{
448
481
public:
449
 
  virtual Item *create(THD *thd, Item *arg1);
 
482
  using Create_func_arg1::create;
 
483
 
 
484
  virtual Item *create(Session *session, Item *arg1);
450
485
 
451
486
  static Create_func_dayofmonth s_singleton;
452
487
 
459
494
class Create_func_dayofweek : public Create_func_arg1
460
495
{
461
496
public:
462
 
  virtual Item *create(THD *thd, Item *arg1);
 
497
  using Create_func_arg1::create;
 
498
 
 
499
  virtual Item *create(Session *session, Item *arg1);
463
500
 
464
501
  static Create_func_dayofweek s_singleton;
465
502
 
472
509
class Create_func_dayofyear : public Create_func_arg1
473
510
{
474
511
public:
475
 
  virtual Item *create(THD *thd, Item *arg1);
 
512
  using Create_func_arg1::create;
 
513
 
 
514
  virtual Item *create(Session *session, Item *arg1);
476
515
 
477
516
  static Create_func_dayofyear s_singleton;
478
517
 
485
524
class Create_func_decode : public Create_func_arg2
486
525
{
487
526
public:
488
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
527
  using Create_func_arg2::create;
 
528
 
 
529
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
489
530
 
490
531
  static Create_func_decode s_singleton;
491
532
 
498
539
class Create_func_degrees : public Create_func_arg1
499
540
{
500
541
public:
501
 
  virtual Item *create(THD *thd, Item *arg1);
 
542
  using Create_func_arg1::create;
 
543
 
 
544
  virtual Item *create(Session *session, Item *arg1);
502
545
 
503
546
  static Create_func_degrees s_singleton;
504
547
 
511
554
class Create_func_elt : public Create_native_func
512
555
{
513
556
public:
514
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
557
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
515
558
 
516
559
  static Create_func_elt s_singleton;
517
560
 
524
567
class Create_func_exp : public Create_func_arg1
525
568
{
526
569
public:
527
 
  virtual Item *create(THD *thd, Item *arg1);
 
570
  using Create_func_arg1::create;
 
571
 
 
572
  virtual Item *create(Session *session, Item *arg1);
528
573
 
529
574
  static Create_func_exp s_singleton;
530
575
 
537
582
class Create_func_export_set : public Create_native_func
538
583
{
539
584
public:
540
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
585
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
541
586
 
542
587
  static Create_func_export_set s_singleton;
543
588
 
550
595
class Create_func_field : public Create_native_func
551
596
{
552
597
public:
553
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
598
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
554
599
 
555
600
  static Create_func_field s_singleton;
556
601
 
563
608
class Create_func_find_in_set : public Create_func_arg2
564
609
{
565
610
public:
566
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
611
  using Create_func_arg2::create;
 
612
 
 
613
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
567
614
 
568
615
  static Create_func_find_in_set s_singleton;
569
616
 
576
623
class Create_func_floor : public Create_func_arg1
577
624
{
578
625
public:
579
 
  virtual Item *create(THD *thd, Item *arg1);
 
626
  using Create_func_arg1::create;
 
627
 
 
628
  virtual Item *create(Session *session, Item *arg1);
580
629
 
581
630
  static Create_func_floor s_singleton;
582
631
 
589
638
class Create_func_format : public Create_func_arg2
590
639
{
591
640
public:
592
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
641
  using Create_func_arg2::create;
 
642
 
 
643
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
593
644
 
594
645
  static Create_func_format s_singleton;
595
646
 
602
653
class Create_func_found_rows : public Create_func_arg0
603
654
{
604
655
public:
605
 
  virtual Item *create(THD *thd);
 
656
  using Create_func_arg0::create;
 
657
 
 
658
  virtual Item *create(Session *session);
606
659
 
607
660
  static Create_func_found_rows s_singleton;
608
661
 
615
668
class Create_func_from_days : public Create_func_arg1
616
669
{
617
670
public:
618
 
  virtual Item *create(THD *thd, Item *arg1);
 
671
  using Create_func_arg1::create;
 
672
 
 
673
  virtual Item *create(Session *session, Item *arg1);
619
674
 
620
675
  static Create_func_from_days s_singleton;
621
676
 
628
683
class Create_func_from_unixtime : public Create_native_func
629
684
{
630
685
public:
631
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
686
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
632
687
 
633
688
  static Create_func_from_unixtime s_singleton;
634
689
 
641
696
class Create_func_greatest : public Create_native_func
642
697
{
643
698
public:
644
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
699
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
645
700
 
646
701
  static Create_func_greatest s_singleton;
647
702
 
654
709
class Create_func_hex : public Create_func_arg1
655
710
{
656
711
public:
657
 
  virtual Item *create(THD *thd, Item *arg1);
 
712
  using Create_func_arg1::create;
 
713
 
 
714
  virtual Item *create(Session *session, Item *arg1);
658
715
 
659
716
  static Create_func_hex s_singleton;
660
717
 
667
724
class Create_func_ifnull : public Create_func_arg2
668
725
{
669
726
public:
670
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
727
  using Create_func_arg2::create;
 
728
 
 
729
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
671
730
 
672
731
  static Create_func_ifnull s_singleton;
673
732
 
680
739
class Create_func_instr : public Create_func_arg2
681
740
{
682
741
public:
683
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
742
  using Create_func_arg2::create;
 
743
 
 
744
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
684
745
 
685
746
  static Create_func_instr s_singleton;
686
747
 
693
754
class Create_func_isnull : public Create_func_arg1
694
755
{
695
756
public:
696
 
  virtual Item *create(THD *thd, Item *arg1);
 
757
  using Create_func_arg1::create;
 
758
 
 
759
  virtual Item *create(Session *session, Item *arg1);
697
760
 
698
761
  static Create_func_isnull s_singleton;
699
762
 
706
769
class Create_func_last_day : public Create_func_arg1
707
770
{
708
771
public:
709
 
  virtual Item *create(THD *thd, Item *arg1);
 
772
  using Create_func_arg1::create;
 
773
 
 
774
  virtual Item *create(Session *session, Item *arg1);
710
775
 
711
776
  static Create_func_last_day s_singleton;
712
777
 
719
784
class Create_func_last_insert_id : public Create_native_func
720
785
{
721
786
public:
722
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
787
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
723
788
 
724
789
  static Create_func_last_insert_id s_singleton;
725
790
 
732
797
class Create_func_lcase : public Create_func_arg1
733
798
{
734
799
public:
735
 
  virtual Item *create(THD *thd, Item *arg1);
 
800
  using Create_func_arg1::create;
 
801
 
 
802
  virtual Item *create(Session *session, Item *arg1);
736
803
 
737
804
  static Create_func_lcase s_singleton;
738
805
 
745
812
class Create_func_least : public Create_native_func
746
813
{
747
814
public:
748
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
815
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
749
816
 
750
817
  static Create_func_least s_singleton;
751
818
 
755
822
};
756
823
 
757
824
 
758
 
class Create_func_length : public Create_func_arg1
759
 
{
760
 
public:
761
 
  virtual Item *create(THD *thd, Item *arg1);
762
 
 
763
 
  static Create_func_length s_singleton;
764
 
 
765
 
protected:
766
 
  Create_func_length() {}
767
 
  virtual ~Create_func_length() {}
768
 
};
769
 
 
770
 
 
771
825
class Create_func_ln : public Create_func_arg1
772
826
{
773
827
public:
774
 
  virtual Item *create(THD *thd, Item *arg1);
 
828
  using Create_func_arg1::create;
 
829
 
 
830
  virtual Item *create(Session *session, Item *arg1);
775
831
 
776
832
  static Create_func_ln s_singleton;
777
833
 
784
840
class Create_func_load_file : public Create_func_arg1
785
841
{
786
842
public:
787
 
  virtual Item *create(THD *thd, Item *arg1);
 
843
  using Create_func_arg1::create;
 
844
 
 
845
  virtual Item *create(Session *session, Item *arg1);
788
846
 
789
847
  static Create_func_load_file s_singleton;
790
848
 
797
855
class Create_func_locate : public Create_native_func
798
856
{
799
857
public:
800
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
858
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
801
859
 
802
860
  static Create_func_locate s_singleton;
803
861
 
810
868
class Create_func_log : public Create_native_func
811
869
{
812
870
public:
813
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
871
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
814
872
 
815
873
  static Create_func_log s_singleton;
816
874
 
823
881
class Create_func_log10 : public Create_func_arg1
824
882
{
825
883
public:
826
 
  virtual Item *create(THD *thd, Item *arg1);
 
884
  using Create_func_arg1::create;
 
885
 
 
886
  virtual Item *create(Session *session, Item *arg1);
827
887
 
828
888
  static Create_func_log10 s_singleton;
829
889
 
836
896
class Create_func_log2 : public Create_func_arg1
837
897
{
838
898
public:
839
 
  virtual Item *create(THD *thd, Item *arg1);
 
899
  using Create_func_arg1::create;
 
900
 
 
901
  virtual Item *create(Session *session, Item *arg1);
840
902
 
841
903
  static Create_func_log2 s_singleton;
842
904
 
849
911
class Create_func_lpad : public Create_func_arg3
850
912
{
851
913
public:
852
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2, Item *arg3);
 
914
  using Create_func_arg3::create;
 
915
 
 
916
  virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3);
853
917
 
854
918
  static Create_func_lpad s_singleton;
855
919
 
862
926
class Create_func_ltrim : public Create_func_arg1
863
927
{
864
928
public:
865
 
  virtual Item *create(THD *thd, Item *arg1);
 
929
  using Create_func_arg1::create;
 
930
 
 
931
  virtual Item *create(Session *session, Item *arg1);
866
932
 
867
933
  static Create_func_ltrim s_singleton;
868
934
 
875
941
class Create_func_makedate : public Create_func_arg2
876
942
{
877
943
public:
878
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
944
  using Create_func_arg2::create;
 
945
 
 
946
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
879
947
 
880
948
  static Create_func_makedate s_singleton;
881
949
 
884
952
  virtual ~Create_func_makedate() {}
885
953
};
886
954
 
887
 
 
888
 
class Create_func_maketime : public Create_func_arg3
889
 
{
890
 
public:
891
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2, Item *arg3);
892
 
 
893
 
  static Create_func_maketime s_singleton;
894
 
 
895
 
protected:
896
 
  Create_func_maketime() {}
897
 
  virtual ~Create_func_maketime() {}
898
 
};
899
 
 
900
 
 
901
955
class Create_func_make_set : public Create_native_func
902
956
{
903
957
public:
904
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
958
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
905
959
 
906
960
  static Create_func_make_set s_singleton;
907
961
 
911
965
};
912
966
 
913
967
 
914
 
class Create_func_master_pos_wait : public Create_native_func
915
 
{
916
 
public:
917
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
918
 
 
919
 
  static Create_func_master_pos_wait s_singleton;
920
 
 
921
 
protected:
922
 
  Create_func_master_pos_wait() {}
923
 
  virtual ~Create_func_master_pos_wait() {}
924
 
};
925
 
 
926
968
class Create_func_monthname : public Create_func_arg1
927
969
{
928
970
public:
929
 
  virtual Item *create(THD *thd, Item *arg1);
 
971
  using Create_func_arg1::create;
 
972
 
 
973
  virtual Item *create(Session *session, Item *arg1);
930
974
 
931
975
  static Create_func_monthname s_singleton;
932
976
 
939
983
class Create_func_name_const : public Create_func_arg2
940
984
{
941
985
public:
942
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
986
  using Create_func_arg2::create;
 
987
 
 
988
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
943
989
 
944
990
  static Create_func_name_const s_singleton;
945
991
 
952
998
class Create_func_nullif : public Create_func_arg2
953
999
{
954
1000
public:
955
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
1001
  using Create_func_arg2::create;
 
1002
 
 
1003
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
956
1004
 
957
1005
  static Create_func_nullif s_singleton;
958
1006
 
965
1013
class Create_func_oct : public Create_func_arg1
966
1014
{
967
1015
public:
968
 
  virtual Item *create(THD *thd, Item *arg1);
 
1016
  using Create_func_arg1::create;
 
1017
 
 
1018
  virtual Item *create(Session *session, Item *arg1);
969
1019
 
970
1020
  static Create_func_oct s_singleton;
971
1021
 
978
1028
class Create_func_ord : public Create_func_arg1
979
1029
{
980
1030
public:
981
 
  virtual Item *create(THD *thd, Item *arg1);
 
1031
  using Create_func_arg1::create;
 
1032
 
 
1033
  virtual Item *create(Session *session, Item *arg1);
982
1034
 
983
1035
  static Create_func_ord s_singleton;
984
1036
 
991
1043
class Create_func_period_add : public Create_func_arg2
992
1044
{
993
1045
public:
994
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
1046
  using Create_func_arg2::create;
 
1047
 
 
1048
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
995
1049
 
996
1050
  static Create_func_period_add s_singleton;
997
1051
 
1004
1058
class Create_func_period_diff : public Create_func_arg2
1005
1059
{
1006
1060
public:
1007
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
1061
  using Create_func_arg2::create;
 
1062
 
 
1063
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1008
1064
 
1009
1065
  static Create_func_period_diff s_singleton;
1010
1066
 
1017
1073
class Create_func_pi : public Create_func_arg0
1018
1074
{
1019
1075
public:
1020
 
  virtual Item *create(THD *thd);
 
1076
  using Create_func_arg0::create;
 
1077
 
 
1078
  virtual Item *create(Session *session);
1021
1079
 
1022
1080
  static Create_func_pi s_singleton;
1023
1081
 
1030
1088
class Create_func_pow : public Create_func_arg2
1031
1089
{
1032
1090
public:
1033
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
1091
  using Create_func_arg2::create;
 
1092
 
 
1093
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1034
1094
 
1035
1095
  static Create_func_pow s_singleton;
1036
1096
 
1043
1103
class Create_func_quote : public Create_func_arg1
1044
1104
{
1045
1105
public:
1046
 
  virtual Item *create(THD *thd, Item *arg1);
 
1106
  using Create_func_arg1::create;
 
1107
 
 
1108
  virtual Item *create(Session *session, Item *arg1);
1047
1109
 
1048
1110
  static Create_func_quote s_singleton;
1049
1111
 
1056
1118
class Create_func_radians : public Create_func_arg1
1057
1119
{
1058
1120
public:
1059
 
  virtual Item *create(THD *thd, Item *arg1);
 
1121
  using Create_func_arg1::create;
 
1122
 
 
1123
  virtual Item *create(Session *session, Item *arg1);
1060
1124
 
1061
1125
  static Create_func_radians s_singleton;
1062
1126
 
1069
1133
class Create_func_rand : public Create_native_func
1070
1134
{
1071
1135
public:
1072
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
1136
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1073
1137
 
1074
1138
  static Create_func_rand s_singleton;
1075
1139
 
1082
1146
class Create_func_round : public Create_native_func
1083
1147
{
1084
1148
public:
1085
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
1149
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1086
1150
 
1087
1151
  static Create_func_round s_singleton;
1088
1152
 
1095
1159
class Create_func_row_count : public Create_func_arg0
1096
1160
{
1097
1161
public:
1098
 
  virtual Item *create(THD *thd);
 
1162
  using Create_func_arg0::create;
 
1163
 
 
1164
  virtual Item *create(Session *session);
1099
1165
 
1100
1166
  static Create_func_row_count s_singleton;
1101
1167
 
1108
1174
class Create_func_rpad : public Create_func_arg3
1109
1175
{
1110
1176
public:
1111
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2, Item *arg3);
 
1177
  using Create_func_arg3::create;
 
1178
 
 
1179
  virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3);
1112
1180
 
1113
1181
  static Create_func_rpad s_singleton;
1114
1182
 
1121
1189
class Create_func_rtrim : public Create_func_arg1
1122
1190
{
1123
1191
public:
1124
 
  virtual Item *create(THD *thd, Item *arg1);
 
1192
  using Create_func_arg1::create;
 
1193
 
 
1194
  virtual Item *create(Session *session, Item *arg1);
1125
1195
 
1126
1196
  static Create_func_rtrim s_singleton;
1127
1197
 
1130
1200
  virtual ~Create_func_rtrim() {}
1131
1201
};
1132
1202
 
1133
 
 
1134
 
class Create_func_sec_to_time : public Create_func_arg1
1135
 
{
1136
 
public:
1137
 
  virtual Item *create(THD *thd, Item *arg1);
1138
 
 
1139
 
  static Create_func_sec_to_time s_singleton;
1140
 
 
1141
 
protected:
1142
 
  Create_func_sec_to_time() {}
1143
 
  virtual ~Create_func_sec_to_time() {}
1144
 
};
1145
 
 
1146
 
 
1147
1203
class Create_func_sign : public Create_func_arg1
1148
1204
{
1149
1205
public:
1150
 
  virtual Item *create(THD *thd, Item *arg1);
 
1206
  using Create_func_arg1::create;
 
1207
 
 
1208
  virtual Item *create(Session *session, Item *arg1);
1151
1209
 
1152
1210
  static Create_func_sign s_singleton;
1153
1211
 
1160
1218
class Create_func_sin : public Create_func_arg1
1161
1219
{
1162
1220
public:
1163
 
  virtual Item *create(THD *thd, Item *arg1);
 
1221
  using Create_func_arg1::create;
 
1222
 
 
1223
  virtual Item *create(Session *session, Item *arg1);
1164
1224
 
1165
1225
  static Create_func_sin s_singleton;
1166
1226
 
1173
1233
class Create_func_space : public Create_func_arg1
1174
1234
{
1175
1235
public:
1176
 
  virtual Item *create(THD *thd, Item *arg1);
 
1236
  using Create_func_arg1::create;
 
1237
 
 
1238
  virtual Item *create(Session *session, Item *arg1);
1177
1239
 
1178
1240
  static Create_func_space s_singleton;
1179
1241
 
1186
1248
class Create_func_sqrt : public Create_func_arg1
1187
1249
{
1188
1250
public:
1189
 
  virtual Item *create(THD *thd, Item *arg1);
 
1251
  using Create_func_arg1::create;
 
1252
 
 
1253
  virtual Item *create(Session *session, Item *arg1);
1190
1254
 
1191
1255
  static Create_func_sqrt s_singleton;
1192
1256
 
1196
1260
};
1197
1261
 
1198
1262
 
1199
 
class Create_func_str_to_date : public Create_func_arg2
1200
 
{
1201
 
public:
1202
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
1203
 
 
1204
 
  static Create_func_str_to_date s_singleton;
1205
 
 
1206
 
protected:
1207
 
  Create_func_str_to_date() {}
1208
 
  virtual ~Create_func_str_to_date() {}
1209
 
};
1210
 
 
1211
 
 
1212
1263
class Create_func_strcmp : public Create_func_arg2
1213
1264
{
1214
1265
public:
1215
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
1266
  using Create_func_arg2::create;
 
1267
 
 
1268
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1216
1269
 
1217
1270
  static Create_func_strcmp s_singleton;
1218
1271
 
1225
1278
class Create_func_substr_index : public Create_func_arg3
1226
1279
{
1227
1280
public:
1228
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2, Item *arg3);
 
1281
  using Create_func_arg3::create;
 
1282
 
 
1283
  virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3);
1229
1284
 
1230
1285
  static Create_func_substr_index s_singleton;
1231
1286
 
1235
1290
};
1236
1291
 
1237
1292
 
1238
 
class Create_func_subtime : public Create_func_arg2
1239
 
{
1240
 
public:
1241
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
1242
 
 
1243
 
  static Create_func_subtime s_singleton;
1244
 
 
1245
 
protected:
1246
 
  Create_func_subtime() {}
1247
 
  virtual ~Create_func_subtime() {}
1248
 
};
1249
 
 
1250
 
 
1251
1293
class Create_func_tan : public Create_func_arg1
1252
1294
{
1253
1295
public:
1254
 
  virtual Item *create(THD *thd, Item *arg1);
 
1296
  using Create_func_arg1::create;
 
1297
 
 
1298
  virtual Item *create(Session *session, Item *arg1);
1255
1299
 
1256
1300
  static Create_func_tan s_singleton;
1257
1301
 
1264
1308
class Create_func_time_format : public Create_func_arg2
1265
1309
{
1266
1310
public:
1267
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
1311
  using Create_func_arg2::create;
 
1312
 
 
1313
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1268
1314
 
1269
1315
  static Create_func_time_format s_singleton;
1270
1316
 
1277
1323
class Create_func_time_to_sec : public Create_func_arg1
1278
1324
{
1279
1325
public:
1280
 
  virtual Item *create(THD *thd, Item *arg1);
 
1326
  using Create_func_arg1::create;
 
1327
 
 
1328
  virtual Item *create(Session *session, Item *arg1);
1281
1329
 
1282
1330
  static Create_func_time_to_sec s_singleton;
1283
1331
 
1287
1335
};
1288
1336
 
1289
1337
 
1290
 
class Create_func_timediff : public Create_func_arg2
1291
 
{
1292
 
public:
1293
 
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
1294
 
 
1295
 
  static Create_func_timediff s_singleton;
1296
 
 
1297
 
protected:
1298
 
  Create_func_timediff() {}
1299
 
  virtual ~Create_func_timediff() {}
1300
 
};
1301
 
 
1302
 
 
1303
1338
class Create_func_to_days : public Create_func_arg1
1304
1339
{
1305
1340
public:
1306
 
  virtual Item *create(THD *thd, Item *arg1);
 
1341
  using Create_func_arg1::create;
 
1342
 
 
1343
  virtual Item *create(Session *session, Item *arg1);
1307
1344
 
1308
1345
  static Create_func_to_days s_singleton;
1309
1346
 
1316
1353
class Create_func_ucase : public Create_func_arg1
1317
1354
{
1318
1355
public:
1319
 
  virtual Item *create(THD *thd, Item *arg1);
 
1356
  using Create_func_arg1::create;
 
1357
 
 
1358
  virtual Item *create(Session *session, Item *arg1);
1320
1359
 
1321
1360
  static Create_func_ucase s_singleton;
1322
1361
 
1329
1368
class Create_func_unhex : public Create_func_arg1
1330
1369
{
1331
1370
public:
1332
 
  virtual Item *create(THD *thd, Item *arg1);
 
1371
  using Create_func_arg1::create;
 
1372
 
 
1373
  virtual Item *create(Session *session, Item *arg1);
1333
1374
 
1334
1375
  static Create_func_unhex s_singleton;
1335
1376
 
1342
1383
class Create_func_unix_timestamp : public Create_native_func
1343
1384
{
1344
1385
public:
1345
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
1386
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1346
1387
 
1347
1388
  static Create_func_unix_timestamp s_singleton;
1348
1389
 
1355
1396
class Create_func_uuid : public Create_func_arg0
1356
1397
{
1357
1398
public:
1358
 
  virtual Item *create(THD *thd);
 
1399
  using Create_func_arg0::create;
 
1400
 
 
1401
  virtual Item *create(Session *session);
1359
1402
 
1360
1403
  static Create_func_uuid s_singleton;
1361
1404
 
1365
1408
};
1366
1409
 
1367
1410
 
1368
 
class Create_func_version : public Create_func_arg0
1369
 
{
1370
 
public:
1371
 
  virtual Item *create(THD *thd);
1372
 
 
1373
 
  static Create_func_version s_singleton;
1374
 
 
1375
 
protected:
1376
 
  Create_func_version() {}
1377
 
  virtual ~Create_func_version() {}
1378
 
};
1379
 
 
1380
 
 
1381
1411
class Create_func_weekday : public Create_func_arg1
1382
1412
{
1383
1413
public:
1384
 
  virtual Item *create(THD *thd, Item *arg1);
 
1414
  using Create_func_arg1::create;
 
1415
 
 
1416
  virtual Item *create(Session *session, Item *arg1);
1385
1417
 
1386
1418
  static Create_func_weekday s_singleton;
1387
1419
 
1390
1422
  virtual ~Create_func_weekday() {}
1391
1423
};
1392
1424
 
1393
 
 
1394
 
class Create_func_weekofyear : public Create_func_arg1
1395
 
{
1396
 
public:
1397
 
  virtual Item *create(THD *thd, Item *arg1);
1398
 
 
1399
 
  static Create_func_weekofyear s_singleton;
1400
 
 
1401
 
protected:
1402
 
  Create_func_weekofyear() {}
1403
 
  virtual ~Create_func_weekofyear() {}
1404
 
};
1405
 
 
1406
 
 
1407
 
class Create_func_year_week : public Create_native_func
1408
 
{
1409
 
public:
1410
 
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
1411
 
 
1412
 
  static Create_func_year_week s_singleton;
1413
 
 
1414
 
protected:
1415
 
  Create_func_year_week() {}
1416
 
  virtual ~Create_func_year_week() {}
1417
 
};
1418
 
 
1419
 
 
1420
1425
/*
1421
1426
=============================================================================
1422
1427
  IMPLEMENTATION
1450
1455
Create_udf_func Create_udf_func::s_singleton;
1451
1456
 
1452
1457
Item*
1453
 
Create_udf_func::create(THD *thd, LEX_STRING name, List<Item> *item_list)
 
1458
Create_udf_func::create(Session *session, LEX_STRING name, List<Item> *item_list)
1454
1459
{
1455
 
  udf_func *udf= find_udf(name.str, name.length);
 
1460
  const plugin::Function *udf= plugin::Function::get(name.str, name.length);
1456
1461
  assert(udf);
1457
 
  return create(thd, udf, item_list);
 
1462
  return create(session, udf, item_list);
1458
1463
}
1459
1464
 
1460
1465
 
1461
1466
Item*
1462
 
Create_udf_func::create(THD *thd, udf_func *udf, List<Item> *item_list)
 
1467
Create_udf_func::create(Session *session, const plugin::Function *udf,
 
1468
                        List<Item> *item_list)
1463
1469
{
1464
 
  Item *func= NULL;
 
1470
  Item_func *func= NULL;
1465
1471
  int arg_count= 0;
1466
1472
 
1467
1473
  if (item_list != NULL)
1468
1474
    arg_count= item_list->elements;
1469
1475
 
1470
 
  thd->lex->set_stmt_unsafe();
1471
 
 
1472
 
  assert(   (udf->type == UDFTYPE_FUNCTION)
1473
 
              || (udf->type == UDFTYPE_AGGREGATE));
1474
 
 
1475
 
  switch(udf->returns) {
1476
 
  case STRING_RESULT:
1477
 
  {
1478
 
    if (udf->type == UDFTYPE_FUNCTION)
1479
 
    {
1480
 
      if (arg_count)
1481
 
        func= new (thd->mem_root) Item_func_udf_str(udf, *item_list);
1482
 
      else
1483
 
        func= new (thd->mem_root) Item_func_udf_str(udf);
1484
 
    }
1485
 
    else
1486
 
    {
1487
 
      if (arg_count)
1488
 
        func= new (thd->mem_root) Item_sum_udf_str(udf, *item_list);
1489
 
      else
1490
 
        func= new (thd->mem_root) Item_sum_udf_str(udf);
1491
 
    }
1492
 
    break;
1493
 
  }
1494
 
  case REAL_RESULT:
1495
 
  {
1496
 
    if (udf->type == UDFTYPE_FUNCTION)
1497
 
    {
1498
 
      if (arg_count)
1499
 
        func= new (thd->mem_root) Item_func_udf_float(udf, *item_list);
1500
 
      else
1501
 
        func= new (thd->mem_root) Item_func_udf_float(udf);
1502
 
    }
1503
 
    else
1504
 
    {
1505
 
      if (arg_count)
1506
 
        func= new (thd->mem_root) Item_sum_udf_float(udf, *item_list);
1507
 
      else
1508
 
        func= new (thd->mem_root) Item_sum_udf_float(udf);
1509
 
    }
1510
 
    break;
1511
 
  }
1512
 
  case INT_RESULT:
1513
 
  {
1514
 
    if (udf->type == UDFTYPE_FUNCTION)
1515
 
    {
1516
 
      if (arg_count)
1517
 
        func= new (thd->mem_root) Item_func_udf_int(udf, *item_list);
1518
 
      else
1519
 
        func= new (thd->mem_root) Item_func_udf_int(udf);
1520
 
    }
1521
 
    else
1522
 
    {
1523
 
      if (arg_count)
1524
 
        func= new (thd->mem_root) Item_sum_udf_int(udf, *item_list);
1525
 
      else
1526
 
        func= new (thd->mem_root) Item_sum_udf_int(udf);
1527
 
    }
1528
 
    break;
1529
 
  }
1530
 
  case DECIMAL_RESULT:
1531
 
  {
1532
 
    if (udf->type == UDFTYPE_FUNCTION)
1533
 
    {
1534
 
      if (arg_count)
1535
 
        func= new (thd->mem_root) Item_func_udf_decimal(udf, *item_list);
1536
 
      else
1537
 
        func= new (thd->mem_root) Item_func_udf_decimal(udf);
1538
 
    }
1539
 
    else
1540
 
    {
1541
 
      if (arg_count)
1542
 
        func= new (thd->mem_root) Item_sum_udf_decimal(udf, *item_list);
1543
 
      else
1544
 
        func= new (thd->mem_root) Item_sum_udf_decimal(udf);
1545
 
    }
1546
 
    break;
1547
 
  }
1548
 
  default:
1549
 
  {
1550
 
    my_error(ER_NOT_SUPPORTED_YET, MYF(0), "UDF return type");
1551
 
  }
1552
 
  }
 
1476
  func= (*udf)(session->mem_root);
 
1477
 
 
1478
  if(!func->check_argument_count(arg_count))
 
1479
  {
 
1480
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), func->func_name());
 
1481
    return NULL;
 
1482
  }
 
1483
 
 
1484
  if(item_list)
 
1485
    func->set_arguments(*item_list);
 
1486
 
1553
1487
  return func;
1554
1488
}
1555
1489
 
1556
1490
 
1557
1491
Item*
1558
 
Create_native_func::create(THD *thd, LEX_STRING name, List<Item> *item_list)
 
1492
Create_native_func::create(Session *session, LEX_STRING name, List<Item> *item_list)
1559
1493
{
1560
1494
  if (has_named_parameters(item_list))
1561
1495
  {
1563
1497
    return NULL;
1564
1498
  }
1565
1499
 
1566
 
  return create_native(thd, name, item_list);
 
1500
  return create_native(session, name, item_list);
1567
1501
}
1568
1502
 
1569
1503
 
1570
1504
Item*
1571
 
Create_func_arg0::create(THD *thd, LEX_STRING name, List<Item> *item_list)
 
1505
Create_func_arg0::create(Session *session, LEX_STRING name, List<Item> *item_list)
1572
1506
{
1573
1507
  int arg_count= 0;
1574
1508
 
1577
1511
 
1578
1512
  if (arg_count != 0)
1579
1513
  {
1580
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
1514
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1581
1515
    return NULL;
1582
1516
  }
1583
1517
 
1584
 
  return create(thd);
 
1518
  return create(session);
1585
1519
}
1586
1520
 
1587
1521
 
1588
1522
Item*
1589
 
Create_func_arg1::create(THD *thd, LEX_STRING name, List<Item> *item_list)
 
1523
Create_func_arg1::create(Session *session, LEX_STRING name, List<Item> *item_list)
1590
1524
{
1591
1525
  int arg_count= 0;
1592
1526
 
1595
1529
 
1596
1530
  if (arg_count != 1)
1597
1531
  {
1598
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
1532
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1599
1533
    return NULL;
1600
1534
  }
1601
1535
 
1607
1541
    return NULL;
1608
1542
  }
1609
1543
 
1610
 
  return create(thd, param_1);
 
1544
  return create(session, param_1);
1611
1545
}
1612
1546
 
1613
1547
 
1614
1548
Item*
1615
 
Create_func_arg2::create(THD *thd, LEX_STRING name, List<Item> *item_list)
 
1549
Create_func_arg2::create(Session *session, LEX_STRING name, List<Item> *item_list)
1616
1550
{
1617
1551
  int arg_count= 0;
1618
1552
 
1621
1555
 
1622
1556
  if (arg_count != 2)
1623
1557
  {
1624
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
1558
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1625
1559
    return NULL;
1626
1560
  }
1627
1561
 
1635
1569
    return NULL;
1636
1570
  }
1637
1571
 
1638
 
  return create(thd, param_1, param_2);
 
1572
  return create(session, param_1, param_2);
1639
1573
}
1640
1574
 
1641
1575
 
1642
1576
Item*
1643
 
Create_func_arg3::create(THD *thd, LEX_STRING name, List<Item> *item_list)
 
1577
Create_func_arg3::create(Session *session, LEX_STRING name, List<Item> *item_list)
1644
1578
{
1645
1579
  int arg_count= 0;
1646
1580
 
1649
1583
 
1650
1584
  if (arg_count != 3)
1651
1585
  {
1652
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
1586
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1653
1587
    return NULL;
1654
1588
  }
1655
1589
 
1665
1599
    return NULL;
1666
1600
  }
1667
1601
 
1668
 
  return create(thd, param_1, param_2, param_3);
 
1602
  return create(session, param_1, param_2, param_3);
1669
1603
}
1670
1604
 
1671
1605
 
1672
1606
Create_func_abs Create_func_abs::s_singleton;
1673
1607
 
1674
1608
Item*
1675
 
Create_func_abs::create(THD *thd, Item *arg1)
 
1609
Create_func_abs::create(Session *session, Item *arg1)
1676
1610
{
1677
 
  return new (thd->mem_root) Item_func_abs(arg1);
 
1611
  return new (session->mem_root) Item_func_abs(arg1);
1678
1612
}
1679
1613
 
1680
1614
 
1681
1615
Create_func_acos Create_func_acos::s_singleton;
1682
1616
 
1683
1617
Item*
1684
 
Create_func_acos::create(THD *thd, Item *arg1)
1685
 
{
1686
 
  return new (thd->mem_root) Item_func_acos(arg1);
1687
 
}
1688
 
 
1689
 
 
1690
 
Create_func_addtime Create_func_addtime::s_singleton;
1691
 
 
1692
 
Item*
1693
 
Create_func_addtime::create(THD *thd, Item *arg1, Item *arg2)
1694
 
{
1695
 
  return new (thd->mem_root) Item_func_add_time(arg1, arg2, 0, 0);
1696
 
}
1697
 
 
 
1618
Create_func_acos::create(Session *session, Item *arg1)
 
1619
{
 
1620
  return new (session->mem_root) Item_func_acos(arg1);
 
1621
}
1698
1622
 
1699
1623
Create_func_asin Create_func_asin::s_singleton;
1700
1624
 
1701
1625
Item*
1702
 
Create_func_asin::create(THD *thd, Item *arg1)
 
1626
Create_func_asin::create(Session *session, Item *arg1)
1703
1627
{
1704
 
  return new (thd->mem_root) Item_func_asin(arg1);
 
1628
  return new (session->mem_root) Item_func_asin(arg1);
1705
1629
}
1706
1630
 
1707
1631
 
1708
1632
Create_func_atan Create_func_atan::s_singleton;
1709
1633
 
1710
1634
Item*
1711
 
Create_func_atan::create_native(THD *thd, LEX_STRING name,
 
1635
Create_func_atan::create_native(Session *session, LEX_STRING name,
1712
1636
                                List<Item> *item_list)
1713
1637
{
1714
1638
  Item* func= NULL;
1721
1645
  case 1:
1722
1646
  {
1723
1647
    Item *param_1= item_list->pop();
1724
 
    func= new (thd->mem_root) Item_func_atan(param_1);
 
1648
    func= new (session->mem_root) Item_func_atan(param_1);
1725
1649
    break;
1726
1650
  }
1727
1651
  case 2:
1728
1652
  {
1729
1653
    Item *param_1= item_list->pop();
1730
1654
    Item *param_2= item_list->pop();
1731
 
    func= new (thd->mem_root) Item_func_atan(param_1, param_2);
 
1655
    func= new (session->mem_root) Item_func_atan(param_1, param_2);
1732
1656
    break;
1733
1657
  }
1734
1658
  default:
1735
1659
  {
1736
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
1660
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1737
1661
    break;
1738
1662
  }
1739
1663
  }
1741
1665
  return func;
1742
1666
}
1743
1667
 
1744
 
 
1745
 
Create_func_benchmark Create_func_benchmark::s_singleton;
1746
 
 
1747
 
Item*
1748
 
Create_func_benchmark::create(THD *thd, Item *arg1, Item *arg2)
1749
 
{
1750
 
  return new (thd->mem_root) Item_func_benchmark(arg1, arg2);
1751
 
}
1752
 
 
1753
 
 
1754
1668
Create_func_bin Create_func_bin::s_singleton;
1755
1669
 
1756
1670
Item*
1757
 
Create_func_bin::create(THD *thd, Item *arg1)
1758
 
{
1759
 
  Item *i10= new (thd->mem_root) Item_int((int32_t) 10,2);
1760
 
  Item *i2= new (thd->mem_root) Item_int((int32_t) 2,1);
1761
 
  return new (thd->mem_root) Item_func_conv(arg1, i10, i2);
1762
 
}
1763
 
 
1764
 
 
1765
 
Create_func_bit_count Create_func_bit_count::s_singleton;
1766
 
 
1767
 
Item*
1768
 
Create_func_bit_count::create(THD *thd, Item *arg1)
1769
 
{
1770
 
  return new (thd->mem_root) Item_func_bit_count(arg1);
1771
 
}
1772
 
 
1773
 
 
1774
 
Create_func_bit_length Create_func_bit_length::s_singleton;
1775
 
 
1776
 
Item*
1777
 
Create_func_bit_length::create(THD *thd, Item *arg1)
1778
 
{
1779
 
  return new (thd->mem_root) Item_func_bit_length(arg1);
 
1671
Create_func_bin::create(Session *session, Item *arg1)
 
1672
{
 
1673
  Item *i10= new (session->mem_root) Item_int((int32_t) 10,2);
 
1674
  Item *i2= new (session->mem_root) Item_int((int32_t) 2,1);
 
1675
  return new (session->mem_root) Item_func_conv(arg1, i10, i2);
1780
1676
}
1781
1677
 
1782
1678
 
1783
1679
Create_func_ceiling Create_func_ceiling::s_singleton;
1784
1680
 
1785
1681
Item*
1786
 
Create_func_ceiling::create(THD *thd, Item *arg1)
1787
 
{
1788
 
  return new (thd->mem_root) Item_func_ceiling(arg1);
1789
 
}
1790
 
 
1791
 
 
1792
 
Create_func_char_length Create_func_char_length::s_singleton;
1793
 
 
1794
 
Item*
1795
 
Create_func_char_length::create(THD *thd, Item *arg1)
1796
 
{
1797
 
  return new (thd->mem_root) Item_func_char_length(arg1);
 
1682
Create_func_ceiling::create(Session *session, Item *arg1)
 
1683
{
 
1684
  return new (session->mem_root) Item_func_ceiling(arg1);
1798
1685
}
1799
1686
 
1800
1687
 
1801
1688
Create_func_coercibility Create_func_coercibility::s_singleton;
1802
1689
 
1803
1690
Item*
1804
 
Create_func_coercibility::create(THD *thd, Item *arg1)
 
1691
Create_func_coercibility::create(Session *session, Item *arg1)
1805
1692
{
1806
 
  return new (thd->mem_root) Item_func_coercibility(arg1);
 
1693
  return new (session->mem_root) Item_func_coercibility(arg1);
1807
1694
}
1808
1695
 
1809
1696
 
1810
1697
Create_func_concat Create_func_concat::s_singleton;
1811
1698
 
1812
1699
Item*
1813
 
Create_func_concat::create_native(THD *thd, LEX_STRING name,
 
1700
Create_func_concat::create_native(Session *session, LEX_STRING name,
1814
1701
                                  List<Item> *item_list)
1815
1702
{
1816
1703
  int arg_count= 0;
1820
1707
 
1821
1708
  if (arg_count < 1)
1822
1709
  {
1823
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
1710
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1824
1711
    return NULL;
1825
1712
  }
1826
1713
 
1827
 
  return new (thd->mem_root) Item_func_concat(*item_list);
 
1714
  return new (session->mem_root) Item_func_concat(*item_list);
1828
1715
}
1829
1716
 
1830
1717
 
1831
1718
Create_func_concat_ws Create_func_concat_ws::s_singleton;
1832
1719
 
1833
1720
Item*
1834
 
Create_func_concat_ws::create_native(THD *thd, LEX_STRING name,
 
1721
Create_func_concat_ws::create_native(Session *session, LEX_STRING name,
1835
1722
                                     List<Item> *item_list)
1836
1723
{
1837
1724
  int arg_count= 0;
1842
1729
  /* "WS" stands for "With Separator": this function takes 2+ arguments */
1843
1730
  if (arg_count < 2)
1844
1731
  {
1845
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
1732
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1846
1733
    return NULL;
1847
1734
  }
1848
1735
 
1849
 
  return new (thd->mem_root) Item_func_concat_ws(*item_list);
1850
 
}
1851
 
 
1852
 
 
1853
 
Create_func_connection_id Create_func_connection_id::s_singleton;
1854
 
 
1855
 
Item*
1856
 
Create_func_connection_id::create(THD *thd)
1857
 
{
1858
 
  return new (thd->mem_root) Item_func_connection_id();
 
1736
  return new (session->mem_root) Item_func_concat_ws(*item_list);
1859
1737
}
1860
1738
 
1861
1739
 
1862
1740
Create_func_conv Create_func_conv::s_singleton;
1863
1741
 
1864
1742
Item*
1865
 
Create_func_conv::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
 
1743
Create_func_conv::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
1866
1744
{
1867
 
  return new (thd->mem_root) Item_func_conv(arg1, arg2, arg3);
 
1745
  return new (session->mem_root) Item_func_conv(arg1, arg2, arg3);
1868
1746
}
1869
1747
 
1870
1748
 
1871
1749
Create_func_cos Create_func_cos::s_singleton;
1872
1750
 
1873
1751
Item*
1874
 
Create_func_cos::create(THD *thd, Item *arg1)
 
1752
Create_func_cos::create(Session *session, Item *arg1)
1875
1753
{
1876
 
  return new (thd->mem_root) Item_func_cos(arg1);
 
1754
  return new (session->mem_root) Item_func_cos(arg1);
1877
1755
}
1878
1756
 
1879
1757
 
1880
1758
Create_func_cot Create_func_cot::s_singleton;
1881
1759
 
1882
1760
Item*
1883
 
Create_func_cot::create(THD *thd, Item *arg1)
 
1761
Create_func_cot::create(Session *session, Item *arg1)
1884
1762
{
1885
 
  Item *i1= new (thd->mem_root) Item_int((char*) "1", 1, 1);
1886
 
  Item *i2= new (thd->mem_root) Item_func_tan(arg1);
1887
 
  return new (thd->mem_root) Item_func_div(i1, i2);
 
1763
  Item *i1= new (session->mem_root) Item_int((char*) "1", 1, 1);
 
1764
  Item *i2= new (session->mem_root) Item_func_tan(arg1);
 
1765
  return new (session->mem_root) Item_func_div(i1, i2);
1888
1766
}
1889
1767
 
1890
1768
Create_func_date_format Create_func_date_format::s_singleton;
1891
1769
 
1892
1770
Item*
1893
 
Create_func_date_format::create(THD *thd, Item *arg1, Item *arg2)
 
1771
Create_func_date_format::create(Session *session, Item *arg1, Item *arg2)
1894
1772
{
1895
 
  return new (thd->mem_root) Item_func_date_format(arg1, arg2, 0);
 
1773
  return new (session->mem_root) Item_func_date_format(arg1, arg2, 0);
1896
1774
}
1897
1775
 
1898
1776
 
1899
1777
Create_func_datediff Create_func_datediff::s_singleton;
1900
1778
 
1901
1779
Item*
1902
 
Create_func_datediff::create(THD *thd, Item *arg1, Item *arg2)
 
1780
Create_func_datediff::create(Session *session, Item *arg1, Item *arg2)
1903
1781
{
1904
 
  Item *i1= new (thd->mem_root) Item_func_to_days(arg1);
1905
 
  Item *i2= new (thd->mem_root) Item_func_to_days(arg2);
 
1782
  Item *i1= new (session->mem_root) Item_func_to_days(arg1);
 
1783
  Item *i2= new (session->mem_root) Item_func_to_days(arg2);
1906
1784
 
1907
 
  return new (thd->mem_root) Item_func_minus(i1, i2);
 
1785
  return new (session->mem_root) Item_func_minus(i1, i2);
1908
1786
}
1909
1787
 
1910
1788
 
1911
1789
Create_func_dayname Create_func_dayname::s_singleton;
1912
1790
 
1913
1791
Item*
1914
 
Create_func_dayname::create(THD *thd, Item *arg1)
 
1792
Create_func_dayname::create(Session *session, Item *arg1)
1915
1793
{
1916
 
  return new (thd->mem_root) Item_func_dayname(arg1);
 
1794
  return new (session->mem_root) Item_func_dayname(arg1);
1917
1795
}
1918
1796
 
1919
1797
 
1920
1798
Create_func_dayofmonth Create_func_dayofmonth::s_singleton;
1921
1799
 
1922
1800
Item*
1923
 
Create_func_dayofmonth::create(THD *thd, Item *arg1)
 
1801
Create_func_dayofmonth::create(Session *session, Item *arg1)
1924
1802
{
1925
 
  return new (thd->mem_root) Item_func_dayofmonth(arg1);
 
1803
  return new (session->mem_root) Item_func_dayofmonth(arg1);
1926
1804
}
1927
1805
 
1928
1806
 
1929
1807
Create_func_dayofweek Create_func_dayofweek::s_singleton;
1930
1808
 
1931
1809
Item*
1932
 
Create_func_dayofweek::create(THD *thd, Item *arg1)
 
1810
Create_func_dayofweek::create(Session *session, Item *arg1)
1933
1811
{
1934
 
  return new (thd->mem_root) Item_func_weekday(arg1, 1);
 
1812
  return new (session->mem_root) Item_func_weekday(arg1, 1);
1935
1813
}
1936
1814
 
1937
1815
 
1938
1816
Create_func_dayofyear Create_func_dayofyear::s_singleton;
1939
1817
 
1940
1818
Item*
1941
 
Create_func_dayofyear::create(THD *thd, Item *arg1)
 
1819
Create_func_dayofyear::create(Session *session, Item *arg1)
1942
1820
{
1943
 
  return new (thd->mem_root) Item_func_dayofyear(arg1);
 
1821
  return new (session->mem_root) Item_func_dayofyear(arg1);
1944
1822
}
1945
1823
 
1946
1824
 
1947
1825
Create_func_degrees Create_func_degrees::s_singleton;
1948
1826
 
1949
1827
Item*
1950
 
Create_func_degrees::create(THD *thd, Item *arg1)
 
1828
Create_func_degrees::create(Session *session, Item *arg1)
1951
1829
{
1952
 
  return new (thd->mem_root) Item_func_units((char*) "degrees", arg1,
 
1830
  return new (session->mem_root) Item_func_units((char*) "degrees", arg1,
1953
1831
                                             180/M_PI, 0.0);
1954
1832
}
1955
1833
 
1957
1835
Create_func_elt Create_func_elt::s_singleton;
1958
1836
 
1959
1837
Item*
1960
 
Create_func_elt::create_native(THD *thd, LEX_STRING name,
 
1838
Create_func_elt::create_native(Session *session, LEX_STRING name,
1961
1839
                               List<Item> *item_list)
1962
1840
{
1963
1841
  int arg_count= 0;
1967
1845
 
1968
1846
  if (arg_count < 2)
1969
1847
  {
1970
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
1848
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1971
1849
    return NULL;
1972
1850
  }
1973
1851
 
1974
 
  return new (thd->mem_root) Item_func_elt(*item_list);
 
1852
  return new (session->mem_root) Item_func_elt(*item_list);
1975
1853
}
1976
1854
 
1977
1855
 
1978
1856
Create_func_exp Create_func_exp::s_singleton;
1979
1857
 
1980
1858
Item*
1981
 
Create_func_exp::create(THD *thd, Item *arg1)
 
1859
Create_func_exp::create(Session *session, Item *arg1)
1982
1860
{
1983
 
  return new (thd->mem_root) Item_func_exp(arg1);
 
1861
  return new (session->mem_root) Item_func_exp(arg1);
1984
1862
}
1985
1863
 
1986
1864
 
1987
1865
Create_func_export_set Create_func_export_set::s_singleton;
1988
1866
 
1989
1867
Item*
1990
 
Create_func_export_set::create_native(THD *thd, LEX_STRING name,
 
1868
Create_func_export_set::create_native(Session *session, LEX_STRING name,
1991
1869
                                      List<Item> *item_list)
1992
1870
{
1993
1871
  Item *func= NULL;
2002
1880
    Item *param_1= item_list->pop();
2003
1881
    Item *param_2= item_list->pop();
2004
1882
    Item *param_3= item_list->pop();
2005
 
    func= new (thd->mem_root) Item_func_export_set(param_1, param_2, param_3);
 
1883
    func= new (session->mem_root) Item_func_export_set(param_1, param_2, param_3);
2006
1884
    break;
2007
1885
  }
2008
1886
  case 4:
2011
1889
    Item *param_2= item_list->pop();
2012
1890
    Item *param_3= item_list->pop();
2013
1891
    Item *param_4= item_list->pop();
2014
 
    func= new (thd->mem_root) Item_func_export_set(param_1, param_2, param_3,
 
1892
    func= new (session->mem_root) Item_func_export_set(param_1, param_2, param_3,
2015
1893
                                                   param_4);
2016
1894
    break;
2017
1895
  }
2022
1900
    Item *param_3= item_list->pop();
2023
1901
    Item *param_4= item_list->pop();
2024
1902
    Item *param_5= item_list->pop();
2025
 
    func= new (thd->mem_root) Item_func_export_set(param_1, param_2, param_3,
 
1903
    func= new (session->mem_root) Item_func_export_set(param_1, param_2, param_3,
2026
1904
                                                   param_4, param_5);
2027
1905
    break;
2028
1906
  }
2029
1907
  default:
2030
1908
  {
2031
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
1909
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2032
1910
    break;
2033
1911
  }
2034
1912
  }
2040
1918
Create_func_field Create_func_field::s_singleton;
2041
1919
 
2042
1920
Item*
2043
 
Create_func_field::create_native(THD *thd, LEX_STRING name,
 
1921
Create_func_field::create_native(Session *session, LEX_STRING name,
2044
1922
                                 List<Item> *item_list)
2045
1923
{
2046
1924
  int arg_count= 0;
2050
1928
 
2051
1929
  if (arg_count < 2)
2052
1930
  {
2053
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
1931
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2054
1932
    return NULL;
2055
1933
  }
2056
1934
 
2057
 
  return new (thd->mem_root) Item_func_field(*item_list);
 
1935
  return new (session->mem_root) Item_func_field(*item_list);
2058
1936
}
2059
1937
 
2060
1938
 
2061
1939
Create_func_find_in_set Create_func_find_in_set::s_singleton;
2062
1940
 
2063
1941
Item*
2064
 
Create_func_find_in_set::create(THD *thd, Item *arg1, Item *arg2)
 
1942
Create_func_find_in_set::create(Session *session, Item *arg1, Item *arg2)
2065
1943
{
2066
 
  return new (thd->mem_root) Item_func_find_in_set(arg1, arg2);
 
1944
  return new (session->mem_root) Item_func_find_in_set(arg1, arg2);
2067
1945
}
2068
1946
 
2069
1947
 
2070
1948
Create_func_floor Create_func_floor::s_singleton;
2071
1949
 
2072
1950
Item*
2073
 
Create_func_floor::create(THD *thd, Item *arg1)
 
1951
Create_func_floor::create(Session *session, Item *arg1)
2074
1952
{
2075
 
  return new (thd->mem_root) Item_func_floor(arg1);
 
1953
  return new (session->mem_root) Item_func_floor(arg1);
2076
1954
}
2077
1955
 
2078
1956
 
2079
1957
Create_func_format Create_func_format::s_singleton;
2080
1958
 
2081
1959
Item*
2082
 
Create_func_format::create(THD *thd, Item *arg1, Item *arg2)
 
1960
Create_func_format::create(Session *session, Item *arg1, Item *arg2)
2083
1961
{
2084
 
  return new (thd->mem_root) Item_func_format(arg1, arg2);
 
1962
  return new (session->mem_root) Item_func_format(arg1, arg2);
2085
1963
}
2086
1964
 
2087
1965
 
2088
1966
Create_func_found_rows Create_func_found_rows::s_singleton;
2089
1967
 
2090
1968
Item*
2091
 
Create_func_found_rows::create(THD *thd)
 
1969
Create_func_found_rows::create(Session *session)
2092
1970
{
2093
 
  thd->lex->set_stmt_unsafe();
2094
 
  return new (thd->mem_root) Item_func_found_rows();
 
1971
  return new (session->mem_root) Item_func_found_rows();
2095
1972
}
2096
1973
 
2097
1974
 
2098
1975
Create_func_from_days Create_func_from_days::s_singleton;
2099
1976
 
2100
1977
Item*
2101
 
Create_func_from_days::create(THD *thd, Item *arg1)
 
1978
Create_func_from_days::create(Session *session, Item *arg1)
2102
1979
{
2103
 
  return new (thd->mem_root) Item_func_from_days(arg1);
 
1980
  return new (session->mem_root) Item_func_from_days(arg1);
2104
1981
}
2105
1982
 
2106
1983
 
2107
1984
Create_func_from_unixtime Create_func_from_unixtime::s_singleton;
2108
1985
 
2109
1986
Item*
2110
 
Create_func_from_unixtime::create_native(THD *thd, LEX_STRING name,
 
1987
Create_func_from_unixtime::create_native(Session *session, LEX_STRING name,
2111
1988
                                         List<Item> *item_list)
2112
1989
{
2113
1990
  Item *func= NULL;
2120
1997
  case 1:
2121
1998
  {
2122
1999
    Item *param_1= item_list->pop();
2123
 
    func= new (thd->mem_root) Item_func_from_unixtime(param_1);
 
2000
    func= new (session->mem_root) Item_func_from_unixtime(param_1);
2124
2001
    break;
2125
2002
  }
2126
2003
  case 2:
2127
2004
  {
2128
2005
    Item *param_1= item_list->pop();
2129
2006
    Item *param_2= item_list->pop();
2130
 
    Item *ut= new (thd->mem_root) Item_func_from_unixtime(param_1);
2131
 
    func= new (thd->mem_root) Item_func_date_format(ut, param_2, 0);
 
2007
    Item *ut= new (session->mem_root) Item_func_from_unixtime(param_1);
 
2008
    func= new (session->mem_root) Item_func_date_format(ut, param_2, 0);
2132
2009
    break;
2133
2010
  }
2134
2011
  default:
2135
2012
  {
2136
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2013
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2137
2014
    break;
2138
2015
  }
2139
2016
  }
2145
2022
Create_func_greatest Create_func_greatest::s_singleton;
2146
2023
 
2147
2024
Item*
2148
 
Create_func_greatest::create_native(THD *thd, LEX_STRING name,
 
2025
Create_func_greatest::create_native(Session *session, LEX_STRING name,
2149
2026
                                    List<Item> *item_list)
2150
2027
{
2151
2028
  int arg_count= 0;
2155
2032
 
2156
2033
  if (arg_count < 2)
2157
2034
  {
2158
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2035
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2159
2036
    return NULL;
2160
2037
  }
2161
2038
 
2162
 
  return new (thd->mem_root) Item_func_max(*item_list);
 
2039
  return new (session->mem_root) Item_func_max(*item_list);
2163
2040
}
2164
2041
 
2165
2042
 
2166
2043
Create_func_hex Create_func_hex::s_singleton;
2167
2044
 
2168
2045
Item*
2169
 
Create_func_hex::create(THD *thd, Item *arg1)
 
2046
Create_func_hex::create(Session *session, Item *arg1)
2170
2047
{
2171
 
  return new (thd->mem_root) Item_func_hex(arg1);
 
2048
  return new (session->mem_root) Item_func_hex(arg1);
2172
2049
}
2173
2050
 
2174
2051
 
2175
2052
Create_func_ifnull Create_func_ifnull::s_singleton;
2176
2053
 
2177
2054
Item*
2178
 
Create_func_ifnull::create(THD *thd, Item *arg1, Item *arg2)
 
2055
Create_func_ifnull::create(Session *session, Item *arg1, Item *arg2)
2179
2056
{
2180
 
  return new (thd->mem_root) Item_func_ifnull(arg1, arg2);
 
2057
  return new (session->mem_root) Item_func_ifnull(arg1, arg2);
2181
2058
}
2182
2059
 
2183
2060
 
2184
2061
Create_func_instr Create_func_instr::s_singleton;
2185
2062
 
2186
2063
Item*
2187
 
Create_func_instr::create(THD *thd, Item *arg1, Item *arg2)
 
2064
Create_func_instr::create(Session *session, Item *arg1, Item *arg2)
2188
2065
{
2189
 
  return new (thd->mem_root) Item_func_locate(arg1, arg2);
 
2066
  return new (session->mem_root) Item_func_locate(arg1, arg2);
2190
2067
}
2191
2068
 
2192
2069
 
2193
2070
Create_func_isnull Create_func_isnull::s_singleton;
2194
2071
 
2195
2072
Item*
2196
 
Create_func_isnull::create(THD *thd, Item *arg1)
 
2073
Create_func_isnull::create(Session *session, Item *arg1)
2197
2074
{
2198
 
  return new (thd->mem_root) Item_func_isnull(arg1);
 
2075
  return new (session->mem_root) Item_func_isnull(arg1);
2199
2076
}
2200
2077
 
2201
2078
 
2202
2079
Create_func_last_day Create_func_last_day::s_singleton;
2203
2080
 
2204
2081
Item*
2205
 
Create_func_last_day::create(THD *thd, Item *arg1)
 
2082
Create_func_last_day::create(Session *session, Item *arg1)
2206
2083
{
2207
 
  return new (thd->mem_root) Item_func_last_day(arg1);
 
2084
  return new (session->mem_root) Item_func_last_day(arg1);
2208
2085
}
2209
2086
 
2210
2087
 
2211
2088
Create_func_last_insert_id Create_func_last_insert_id::s_singleton;
2212
2089
 
2213
2090
Item*
2214
 
Create_func_last_insert_id::create_native(THD *thd, LEX_STRING name,
 
2091
Create_func_last_insert_id::create_native(Session *session, LEX_STRING name,
2215
2092
                                          List<Item> *item_list)
2216
2093
{
2217
2094
  Item *func= NULL;
2223
2100
  switch (arg_count) {
2224
2101
  case 0:
2225
2102
  {
2226
 
    func= new (thd->mem_root) Item_func_last_insert_id();
 
2103
    func= new (session->mem_root) Item_func_last_insert_id();
2227
2104
    break;
2228
2105
  }
2229
2106
  case 1:
2230
2107
  {
2231
2108
    Item *param_1= item_list->pop();
2232
 
    func= new (thd->mem_root) Item_func_last_insert_id(param_1);
 
2109
    func= new (session->mem_root) Item_func_last_insert_id(param_1);
2233
2110
    break;
2234
2111
  }
2235
2112
  default:
2236
2113
  {
2237
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2114
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2238
2115
    break;
2239
2116
  }
2240
2117
  }
2246
2123
Create_func_lcase Create_func_lcase::s_singleton;
2247
2124
 
2248
2125
Item*
2249
 
Create_func_lcase::create(THD *thd, Item *arg1)
 
2126
Create_func_lcase::create(Session *session, Item *arg1)
2250
2127
{
2251
 
  return new (thd->mem_root) Item_func_lcase(arg1);
 
2128
  return new (session->mem_root) Item_func_lcase(arg1);
2252
2129
}
2253
2130
 
2254
2131
 
2255
2132
Create_func_least Create_func_least::s_singleton;
2256
2133
 
2257
2134
Item*
2258
 
Create_func_least::create_native(THD *thd, LEX_STRING name,
 
2135
Create_func_least::create_native(Session *session, LEX_STRING name,
2259
2136
                                 List<Item> *item_list)
2260
2137
{
2261
2138
  int arg_count= 0;
2265
2142
 
2266
2143
  if (arg_count < 2)
2267
2144
  {
2268
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2145
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2269
2146
    return NULL;
2270
2147
  }
2271
2148
 
2272
 
  return new (thd->mem_root) Item_func_min(*item_list);
2273
 
}
2274
 
 
2275
 
 
2276
 
Create_func_length Create_func_length::s_singleton;
2277
 
 
2278
 
Item*
2279
 
Create_func_length::create(THD *thd, Item *arg1)
2280
 
{
2281
 
  return new (thd->mem_root) Item_func_length(arg1);
 
2149
  return new (session->mem_root) Item_func_min(*item_list);
2282
2150
}
2283
2151
 
2284
2152
 
2285
2153
Create_func_ln Create_func_ln::s_singleton;
2286
2154
 
2287
2155
Item*
2288
 
Create_func_ln::create(THD *thd, Item *arg1)
 
2156
Create_func_ln::create(Session *session, Item *arg1)
2289
2157
{
2290
 
  return new (thd->mem_root) Item_func_ln(arg1);
 
2158
  return new (session->mem_root) Item_func_ln(arg1);
2291
2159
}
2292
2160
 
2293
2161
 
2294
2162
Create_func_load_file Create_func_load_file::s_singleton;
2295
2163
 
2296
2164
Item*
2297
 
Create_func_load_file::create(THD *thd, Item *arg1)
 
2165
Create_func_load_file::create(Session *session, Item *arg1)
2298
2166
{
2299
 
  return new (thd->mem_root) Item_load_file(arg1);
 
2167
  return new (session->mem_root) Item_load_file(arg1);
2300
2168
}
2301
2169
 
2302
2170
 
2303
2171
Create_func_locate Create_func_locate::s_singleton;
2304
2172
 
2305
2173
Item*
2306
 
Create_func_locate::create_native(THD *thd, LEX_STRING name,
 
2174
Create_func_locate::create_native(Session *session, LEX_STRING name,
2307
2175
                                  List<Item> *item_list)
2308
2176
{
2309
2177
  Item *func= NULL;
2318
2186
    Item *param_1= item_list->pop();
2319
2187
    Item *param_2= item_list->pop();
2320
2188
    /* Yes, parameters in that order : 2, 1 */
2321
 
    func= new (thd->mem_root) Item_func_locate(param_2, param_1);
 
2189
    func= new (session->mem_root) Item_func_locate(param_2, param_1);
2322
2190
    break;
2323
2191
  }
2324
2192
  case 3:
2327
2195
    Item *param_2= item_list->pop();
2328
2196
    Item *param_3= item_list->pop();
2329
2197
    /* Yes, parameters in that order : 2, 1, 3 */
2330
 
    func= new (thd->mem_root) Item_func_locate(param_2, param_1, param_3);
 
2198
    func= new (session->mem_root) Item_func_locate(param_2, param_1, param_3);
2331
2199
    break;
2332
2200
  }
2333
2201
  default:
2334
2202
  {
2335
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2203
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2336
2204
    break;
2337
2205
  }
2338
2206
  }
2344
2212
Create_func_log Create_func_log::s_singleton;
2345
2213
 
2346
2214
Item*
2347
 
Create_func_log::create_native(THD *thd, LEX_STRING name,
 
2215
Create_func_log::create_native(Session *session, LEX_STRING name,
2348
2216
                               List<Item> *item_list)
2349
2217
{
2350
2218
  Item *func= NULL;
2357
2225
  case 1:
2358
2226
  {
2359
2227
    Item *param_1= item_list->pop();
2360
 
    func= new (thd->mem_root) Item_func_log(param_1);
 
2228
    func= new (session->mem_root) Item_func_log(param_1);
2361
2229
    break;
2362
2230
  }
2363
2231
  case 2:
2364
2232
  {
2365
2233
    Item *param_1= item_list->pop();
2366
2234
    Item *param_2= item_list->pop();
2367
 
    func= new (thd->mem_root) Item_func_log(param_1, param_2);
 
2235
    func= new (session->mem_root) Item_func_log(param_1, param_2);
2368
2236
    break;
2369
2237
  }
2370
2238
  default:
2371
2239
  {
2372
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2240
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2373
2241
    break;
2374
2242
  }
2375
2243
  }
2381
2249
Create_func_log10 Create_func_log10::s_singleton;
2382
2250
 
2383
2251
Item*
2384
 
Create_func_log10::create(THD *thd, Item *arg1)
 
2252
Create_func_log10::create(Session *session, Item *arg1)
2385
2253
{
2386
 
  return new (thd->mem_root) Item_func_log10(arg1);
 
2254
  return new (session->mem_root) Item_func_log10(arg1);
2387
2255
}
2388
2256
 
2389
2257
 
2390
2258
Create_func_log2 Create_func_log2::s_singleton;
2391
2259
 
2392
2260
Item*
2393
 
Create_func_log2::create(THD *thd, Item *arg1)
 
2261
Create_func_log2::create(Session *session, Item *arg1)
2394
2262
{
2395
 
  return new (thd->mem_root) Item_func_log2(arg1);
 
2263
  return new (session->mem_root) Item_func_log2(arg1);
2396
2264
}
2397
2265
 
2398
2266
 
2399
2267
Create_func_lpad Create_func_lpad::s_singleton;
2400
2268
 
2401
2269
Item*
2402
 
Create_func_lpad::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
 
2270
Create_func_lpad::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
2403
2271
{
2404
 
  return new (thd->mem_root) Item_func_lpad(arg1, arg2, arg3);
 
2272
  return new (session->mem_root) Item_func_lpad(arg1, arg2, arg3);
2405
2273
}
2406
2274
 
2407
2275
 
2408
2276
Create_func_ltrim Create_func_ltrim::s_singleton;
2409
2277
 
2410
2278
Item*
2411
 
Create_func_ltrim::create(THD *thd, Item *arg1)
 
2279
Create_func_ltrim::create(Session *session, Item *arg1)
2412
2280
{
2413
 
  return new (thd->mem_root) Item_func_ltrim(arg1);
 
2281
  return new (session->mem_root) Item_func_ltrim(arg1);
2414
2282
}
2415
2283
 
2416
2284
 
2417
2285
Create_func_makedate Create_func_makedate::s_singleton;
2418
2286
 
2419
2287
Item*
2420
 
Create_func_makedate::create(THD *thd, Item *arg1, Item *arg2)
2421
 
{
2422
 
  return new (thd->mem_root) Item_func_makedate(arg1, arg2);
2423
 
}
2424
 
 
2425
 
 
2426
 
Create_func_maketime Create_func_maketime::s_singleton;
2427
 
 
2428
 
Item*
2429
 
Create_func_maketime::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
2430
 
{
2431
 
  return new (thd->mem_root) Item_func_maketime(arg1, arg2, arg3);
 
2288
Create_func_makedate::create(Session *session, Item *arg1, Item *arg2)
 
2289
{
 
2290
  return new (session->mem_root) Item_func_makedate(arg1, arg2);
2432
2291
}
2433
2292
 
2434
2293
 
2435
2294
Create_func_make_set Create_func_make_set::s_singleton;
2436
2295
 
2437
2296
Item*
2438
 
Create_func_make_set::create_native(THD *thd, LEX_STRING name,
 
2297
Create_func_make_set::create_native(Session *session, LEX_STRING name,
2439
2298
                                    List<Item> *item_list)
2440
2299
{
2441
2300
  int arg_count= 0;
2445
2304
 
2446
2305
  if (arg_count < 2)
2447
2306
  {
2448
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2307
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2449
2308
    return NULL;
2450
2309
  }
2451
2310
 
2452
2311
  Item *param_1= item_list->pop();
2453
 
  return new (thd->mem_root) Item_func_make_set(param_1, *item_list);
2454
 
}
2455
 
 
2456
 
 
2457
 
Create_func_master_pos_wait Create_func_master_pos_wait::s_singleton;
2458
 
 
2459
 
Item*
2460
 
Create_func_master_pos_wait::create_native(THD *thd, LEX_STRING name,
2461
 
                                           List<Item> *item_list)
2462
 
 
2463
 
{
2464
 
  Item *func= NULL;
2465
 
  int arg_count= 0;
2466
 
 
2467
 
  if (item_list != NULL)
2468
 
    arg_count= item_list->elements;
2469
 
 
2470
 
  switch (arg_count) {
2471
 
  case 2:
2472
 
  {
2473
 
    Item *param_1= item_list->pop();
2474
 
    Item *param_2= item_list->pop();
2475
 
    func= new (thd->mem_root) Item_master_pos_wait(param_1, param_2);
2476
 
    break;
2477
 
  }
2478
 
  case 3:
2479
 
  {
2480
 
    Item *param_1= item_list->pop();
2481
 
    Item *param_2= item_list->pop();
2482
 
    Item *param_3= item_list->pop();
2483
 
    func= new (thd->mem_root) Item_master_pos_wait(param_1, param_2, param_3);
2484
 
    break;
2485
 
  }
2486
 
  default:
2487
 
  {
2488
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2489
 
    break;
2490
 
  }
2491
 
  }
2492
 
 
2493
 
  return func;
 
2312
  return new (session->mem_root) Item_func_make_set(param_1, *item_list);
2494
2313
}
2495
2314
 
2496
2315
 
2497
2316
Create_func_monthname Create_func_monthname::s_singleton;
2498
2317
 
2499
2318
Item*
2500
 
Create_func_monthname::create(THD *thd, Item *arg1)
 
2319
Create_func_monthname::create(Session *session, Item *arg1)
2501
2320
{
2502
 
  return new (thd->mem_root) Item_func_monthname(arg1);
 
2321
  return new (session->mem_root) Item_func_monthname(arg1);
2503
2322
}
2504
2323
 
2505
2324
 
2506
2325
Create_func_nullif Create_func_nullif::s_singleton;
2507
2326
 
2508
2327
Item*
2509
 
Create_func_nullif::create(THD *thd, Item *arg1, Item *arg2)
 
2328
Create_func_nullif::create(Session *session, Item *arg1, Item *arg2)
2510
2329
{
2511
 
  return new (thd->mem_root) Item_func_nullif(arg1, arg2);
 
2330
  return new (session->mem_root) Item_func_nullif(arg1, arg2);
2512
2331
}
2513
2332
 
2514
2333
 
2515
2334
Create_func_oct Create_func_oct::s_singleton;
2516
2335
 
2517
2336
Item*
2518
 
Create_func_oct::create(THD *thd, Item *arg1)
 
2337
Create_func_oct::create(Session *session, Item *arg1)
2519
2338
{
2520
 
  Item *i10= new (thd->mem_root) Item_int((int32_t) 10,2);
2521
 
  Item *i8= new (thd->mem_root) Item_int((int32_t) 8,1);
2522
 
  return new (thd->mem_root) Item_func_conv(arg1, i10, i8);
 
2339
  Item *i10= new (session->mem_root) Item_int((int32_t) 10,2);
 
2340
  Item *i8= new (session->mem_root) Item_int((int32_t) 8,1);
 
2341
  return new (session->mem_root) Item_func_conv(arg1, i10, i8);
2523
2342
}
2524
2343
 
2525
2344
 
2526
2345
Create_func_ord Create_func_ord::s_singleton;
2527
2346
 
2528
2347
Item*
2529
 
Create_func_ord::create(THD *thd, Item *arg1)
 
2348
Create_func_ord::create(Session *session, Item *arg1)
2530
2349
{
2531
 
  return new (thd->mem_root) Item_func_ord(arg1);
 
2350
  return new (session->mem_root) Item_func_ord(arg1);
2532
2351
}
2533
2352
 
2534
2353
 
2535
2354
Create_func_period_add Create_func_period_add::s_singleton;
2536
2355
 
2537
2356
Item*
2538
 
Create_func_period_add::create(THD *thd, Item *arg1, Item *arg2)
 
2357
Create_func_period_add::create(Session *session, Item *arg1, Item *arg2)
2539
2358
{
2540
 
  return new (thd->mem_root) Item_func_period_add(arg1, arg2);
 
2359
  return new (session->mem_root) Item_func_period_add(arg1, arg2);
2541
2360
}
2542
2361
 
2543
2362
 
2544
2363
Create_func_period_diff Create_func_period_diff::s_singleton;
2545
2364
 
2546
2365
Item*
2547
 
Create_func_period_diff::create(THD *thd, Item *arg1, Item *arg2)
 
2366
Create_func_period_diff::create(Session *session, Item *arg1, Item *arg2)
2548
2367
{
2549
 
  return new (thd->mem_root) Item_func_period_diff(arg1, arg2);
 
2368
  return new (session->mem_root) Item_func_period_diff(arg1, arg2);
2550
2369
}
2551
2370
 
2552
2371
 
2553
2372
Create_func_pi Create_func_pi::s_singleton;
2554
2373
 
2555
2374
Item*
2556
 
Create_func_pi::create(THD *thd)
 
2375
Create_func_pi::create(Session *session)
2557
2376
{
2558
 
  return new (thd->mem_root) Item_static_float_func("pi()", M_PI, 6, 8);
 
2377
  return new (session->mem_root) Item_static_float_func("pi()", M_PI, 6, 8);
2559
2378
}
2560
2379
 
2561
2380
 
2562
2381
Create_func_pow Create_func_pow::s_singleton;
2563
2382
 
2564
2383
Item*
2565
 
Create_func_pow::create(THD *thd, Item *arg1, Item *arg2)
 
2384
Create_func_pow::create(Session *session, Item *arg1, Item *arg2)
2566
2385
{
2567
 
  return new (thd->mem_root) Item_func_pow(arg1, arg2);
 
2386
  return new (session->mem_root) Item_func_pow(arg1, arg2);
2568
2387
}
2569
2388
 
2570
2389
 
2571
2390
Create_func_quote Create_func_quote::s_singleton;
2572
2391
 
2573
2392
Item*
2574
 
Create_func_quote::create(THD *thd, Item *arg1)
 
2393
Create_func_quote::create(Session *session, Item *arg1)
2575
2394
{
2576
 
  return new (thd->mem_root) Item_func_quote(arg1);
 
2395
  return new (session->mem_root) Item_func_quote(arg1);
2577
2396
}
2578
2397
 
2579
2398
 
2580
2399
Create_func_radians Create_func_radians::s_singleton;
2581
2400
 
2582
2401
Item*
2583
 
Create_func_radians::create(THD *thd, Item *arg1)
 
2402
Create_func_radians::create(Session *session, Item *arg1)
2584
2403
{
2585
 
  return new (thd->mem_root) Item_func_units((char*) "radians", arg1,
 
2404
  return new (session->mem_root) Item_func_units((char*) "radians", arg1,
2586
2405
                                             M_PI/180, 0.0);
2587
2406
}
2588
2407
 
2590
2409
Create_func_rand Create_func_rand::s_singleton;
2591
2410
 
2592
2411
Item*
2593
 
Create_func_rand::create_native(THD *thd, LEX_STRING name,
 
2412
Create_func_rand::create_native(Session *session, LEX_STRING name,
2594
2413
                                List<Item> *item_list)
2595
2414
{
2596
2415
  Item *func= NULL;
2602
2421
  switch (arg_count) {
2603
2422
  case 0:
2604
2423
  {
2605
 
    func= new (thd->mem_root) Item_func_rand();
 
2424
    func= new (session->mem_root) Item_func_rand();
2606
2425
    break;
2607
2426
  }
2608
2427
  case 1:
2609
2428
  {
2610
2429
    Item *param_1= item_list->pop();
2611
 
    func= new (thd->mem_root) Item_func_rand(param_1);
 
2430
    func= new (session->mem_root) Item_func_rand(param_1);
2612
2431
    break;
2613
2432
  }
2614
2433
  default:
2615
2434
  {
2616
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2435
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2617
2436
    break;
2618
2437
  }
2619
2438
  }
2625
2444
Create_func_round Create_func_round::s_singleton;
2626
2445
 
2627
2446
Item*
2628
 
Create_func_round::create_native(THD *thd, LEX_STRING name,
 
2447
Create_func_round::create_native(Session *session, LEX_STRING name,
2629
2448
                                 List<Item> *item_list)
2630
2449
{
2631
2450
  Item *func= NULL;
2638
2457
  case 1:
2639
2458
  {
2640
2459
    Item *param_1= item_list->pop();
2641
 
    Item *i0 = new (thd->mem_root) Item_int((char*)"0", 0, 1);
2642
 
    func= new (thd->mem_root) Item_func_round(param_1, i0, 0);
 
2460
    Item *i0 = new (session->mem_root) Item_int((char*)"0", 0, 1);
 
2461
    func= new (session->mem_root) Item_func_round(param_1, i0, 0);
2643
2462
    break;
2644
2463
  }
2645
2464
  case 2:
2646
2465
  {
2647
2466
    Item *param_1= item_list->pop();
2648
2467
    Item *param_2= item_list->pop();
2649
 
    func= new (thd->mem_root) Item_func_round(param_1, param_2, 0);
 
2468
    func= new (session->mem_root) Item_func_round(param_1, param_2, 0);
2650
2469
    break;
2651
2470
  }
2652
2471
  default:
2653
2472
  {
2654
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2473
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2655
2474
    break;
2656
2475
  }
2657
2476
  }
2663
2482
Create_func_row_count Create_func_row_count::s_singleton;
2664
2483
 
2665
2484
Item*
2666
 
Create_func_row_count::create(THD *thd)
 
2485
Create_func_row_count::create(Session *session)
2667
2486
{
2668
 
  thd->lex->set_stmt_unsafe();
2669
 
  return new (thd->mem_root) Item_func_row_count();
 
2487
  return new (session->mem_root) Item_func_row_count();
2670
2488
}
2671
2489
 
2672
2490
 
2673
2491
Create_func_rpad Create_func_rpad::s_singleton;
2674
2492
 
2675
2493
Item*
2676
 
Create_func_rpad::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
 
2494
Create_func_rpad::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
2677
2495
{
2678
 
  return new (thd->mem_root) Item_func_rpad(arg1, arg2, arg3);
 
2496
  return new (session->mem_root) Item_func_rpad(arg1, arg2, arg3);
2679
2497
}
2680
2498
 
2681
2499
 
2682
2500
Create_func_rtrim Create_func_rtrim::s_singleton;
2683
2501
 
2684
2502
Item*
2685
 
Create_func_rtrim::create(THD *thd, Item *arg1)
2686
 
{
2687
 
  return new (thd->mem_root) Item_func_rtrim(arg1);
2688
 
}
2689
 
 
2690
 
 
2691
 
Create_func_sec_to_time Create_func_sec_to_time::s_singleton;
2692
 
 
2693
 
Item*
2694
 
Create_func_sec_to_time::create(THD *thd, Item *arg1)
2695
 
{
2696
 
  return new (thd->mem_root) Item_func_sec_to_time(arg1);
 
2503
Create_func_rtrim::create(Session *session, Item *arg1)
 
2504
{
 
2505
  return new (session->mem_root) Item_func_rtrim(arg1);
2697
2506
}
2698
2507
 
2699
2508
 
2700
2509
Create_func_sign Create_func_sign::s_singleton;
2701
2510
 
2702
2511
Item*
2703
 
Create_func_sign::create(THD *thd, Item *arg1)
 
2512
Create_func_sign::create(Session *session, Item *arg1)
2704
2513
{
2705
 
  return new (thd->mem_root) Item_func_sign(arg1);
 
2514
  return new (session->mem_root) Item_func_sign(arg1);
2706
2515
}
2707
2516
 
2708
2517
 
2709
2518
Create_func_sin Create_func_sin::s_singleton;
2710
2519
 
2711
2520
Item*
2712
 
Create_func_sin::create(THD *thd, Item *arg1)
 
2521
Create_func_sin::create(Session *session, Item *arg1)
2713
2522
{
2714
 
  return new (thd->mem_root) Item_func_sin(arg1);
 
2523
  return new (session->mem_root) Item_func_sin(arg1);
2715
2524
}
2716
2525
 
2717
2526
 
2718
2527
Create_func_space Create_func_space::s_singleton;
2719
2528
 
2720
2529
Item*
2721
 
Create_func_space::create(THD *thd, Item *arg1)
 
2530
Create_func_space::create(Session *session, Item *arg1)
2722
2531
{
2723
2532
  /**
2724
2533
    TODO: Fix Bug#23637
2725
2534
    The parsed item tree should not depend on
2726
 
    <code>thd->variables.collation_connection</code>.
 
2535
    <code>session->variables.collation_connection</code>.
2727
2536
  */
2728
 
  const CHARSET_INFO * const cs= thd->variables.collation_connection;
 
2537
  const CHARSET_INFO * const cs= session->variables.getCollation();
2729
2538
  Item *sp;
2730
2539
 
2731
2540
  if (cs->mbminlen > 1)
2732
2541
  {
2733
 
    uint dummy_errors;
2734
 
    sp= new (thd->mem_root) Item_string("", 0, cs, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
2735
 
    sp->str_value.copy(" ", 1, &my_charset_latin1, cs, &dummy_errors);
 
2542
    uint32_t dummy_errors;
 
2543
    sp= new (session->mem_root) Item_string("", 0, cs, DERIVATION_COERCIBLE);
 
2544
    sp->str_value.copy(" ", 1, &my_charset_utf8_general_ci, cs, &dummy_errors);
2736
2545
  }
2737
2546
  else
2738
2547
  {
2739
 
    sp= new (thd->mem_root) Item_string(" ", 1, cs, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
 
2548
    sp= new (session->mem_root) Item_string(" ", 1, cs, DERIVATION_COERCIBLE);
2740
2549
  }
2741
2550
 
2742
 
  return new (thd->mem_root) Item_func_repeat(sp, arg1);
 
2551
  return new (session->mem_root) Item_func_repeat(sp, arg1);
2743
2552
}
2744
2553
 
2745
2554
 
2746
2555
Create_func_sqrt Create_func_sqrt::s_singleton;
2747
2556
 
2748
2557
Item*
2749
 
Create_func_sqrt::create(THD *thd, Item *arg1)
2750
 
{
2751
 
  return new (thd->mem_root) Item_func_sqrt(arg1);
2752
 
}
2753
 
 
2754
 
 
2755
 
Create_func_str_to_date Create_func_str_to_date::s_singleton;
2756
 
 
2757
 
Item*
2758
 
Create_func_str_to_date::create(THD *thd, Item *arg1, Item *arg2)
2759
 
{
2760
 
  return new (thd->mem_root) Item_func_str_to_date(arg1, arg2);
 
2558
Create_func_sqrt::create(Session *session, Item *arg1)
 
2559
{
 
2560
  return new (session->mem_root) Item_func_sqrt(arg1);
2761
2561
}
2762
2562
 
2763
2563
 
2764
2564
Create_func_strcmp Create_func_strcmp::s_singleton;
2765
2565
 
2766
2566
Item*
2767
 
Create_func_strcmp::create(THD *thd, Item *arg1, Item *arg2)
 
2567
Create_func_strcmp::create(Session *session, Item *arg1, Item *arg2)
2768
2568
{
2769
 
  return new (thd->mem_root) Item_func_strcmp(arg1, arg2);
 
2569
  return new (session->mem_root) Item_func_strcmp(arg1, arg2);
2770
2570
}
2771
2571
 
2772
2572
 
2773
2573
Create_func_substr_index Create_func_substr_index::s_singleton;
2774
2574
 
2775
2575
Item*
2776
 
Create_func_substr_index::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
2777
 
{
2778
 
  return new (thd->mem_root) Item_func_substr_index(arg1, arg2, arg3);
2779
 
}
2780
 
 
2781
 
 
2782
 
Create_func_subtime Create_func_subtime::s_singleton;
2783
 
 
2784
 
Item*
2785
 
Create_func_subtime::create(THD *thd, Item *arg1, Item *arg2)
2786
 
{
2787
 
  return new (thd->mem_root) Item_func_add_time(arg1, arg2, 0, 1);
2788
 
}
2789
 
 
 
2576
Create_func_substr_index::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
 
2577
{
 
2578
  return new (session->mem_root) Item_func_substr_index(arg1, arg2, arg3);
 
2579
}
2790
2580
 
2791
2581
Create_func_tan Create_func_tan::s_singleton;
2792
2582
 
2793
2583
Item*
2794
 
Create_func_tan::create(THD *thd, Item *arg1)
 
2584
Create_func_tan::create(Session *session, Item *arg1)
2795
2585
{
2796
 
  return new (thd->mem_root) Item_func_tan(arg1);
 
2586
  return new (session->mem_root) Item_func_tan(arg1);
2797
2587
}
2798
2588
 
2799
2589
 
2800
2590
Create_func_time_format Create_func_time_format::s_singleton;
2801
2591
 
2802
2592
Item*
2803
 
Create_func_time_format::create(THD *thd, Item *arg1, Item *arg2)
2804
 
{
2805
 
  return new (thd->mem_root) Item_func_date_format(arg1, arg2, 1);
2806
 
}
2807
 
 
2808
 
 
2809
 
Create_func_time_to_sec Create_func_time_to_sec::s_singleton;
2810
 
 
2811
 
Item*
2812
 
Create_func_time_to_sec::create(THD *thd, Item *arg1)
2813
 
{
2814
 
  return new (thd->mem_root) Item_func_time_to_sec(arg1);
2815
 
}
2816
 
 
2817
 
 
2818
 
Create_func_timediff Create_func_timediff::s_singleton;
2819
 
 
2820
 
Item*
2821
 
Create_func_timediff::create(THD *thd, Item *arg1, Item *arg2)
2822
 
{
2823
 
  return new (thd->mem_root) Item_func_timediff(arg1, arg2);
2824
 
}
2825
 
 
 
2593
Create_func_time_format::create(Session *session, Item *arg1, Item *arg2)
 
2594
{
 
2595
  return new (session->mem_root) Item_func_date_format(arg1, arg2, 1);
 
2596
}
2826
2597
 
2827
2598
Create_func_to_days Create_func_to_days::s_singleton;
2828
2599
 
2829
2600
Item*
2830
 
Create_func_to_days::create(THD *thd, Item *arg1)
 
2601
Create_func_to_days::create(Session *session, Item *arg1)
2831
2602
{
2832
 
  return new (thd->mem_root) Item_func_to_days(arg1);
 
2603
  return new (session->mem_root) Item_func_to_days(arg1);
2833
2604
}
2834
2605
 
2835
2606
 
2836
2607
Create_func_ucase Create_func_ucase::s_singleton;
2837
2608
 
2838
2609
Item*
2839
 
Create_func_ucase::create(THD *thd, Item *arg1)
 
2610
Create_func_ucase::create(Session *session, Item *arg1)
2840
2611
{
2841
 
  return new (thd->mem_root) Item_func_ucase(arg1);
 
2612
  return new (session->mem_root) Item_func_ucase(arg1);
2842
2613
}
2843
2614
 
2844
2615
 
2845
2616
Create_func_unhex Create_func_unhex::s_singleton;
2846
2617
 
2847
2618
Item*
2848
 
Create_func_unhex::create(THD *thd, Item *arg1)
 
2619
Create_func_unhex::create(Session *session, Item *arg1)
2849
2620
{
2850
 
  return new (thd->mem_root) Item_func_unhex(arg1);
 
2621
  return new (session->mem_root) Item_func_unhex(arg1);
2851
2622
}
2852
2623
 
2853
2624
 
2854
2625
Create_func_unix_timestamp Create_func_unix_timestamp::s_singleton;
2855
2626
 
2856
2627
Item*
2857
 
Create_func_unix_timestamp::create_native(THD *thd, LEX_STRING name,
 
2628
Create_func_unix_timestamp::create_native(Session *session, LEX_STRING name,
2858
2629
                                          List<Item> *item_list)
2859
2630
{
2860
2631
  Item *func= NULL;
2866
2637
  switch (arg_count) {
2867
2638
  case 0:
2868
2639
  {
2869
 
    func= new (thd->mem_root) Item_func_unix_timestamp();
 
2640
    func= new (session->mem_root) Item_func_unix_timestamp();
2870
2641
    break;
2871
2642
  }
2872
2643
  case 1:
2873
2644
  {
2874
2645
    Item *param_1= item_list->pop();
2875
 
    func= new (thd->mem_root) Item_func_unix_timestamp(param_1);
 
2646
    func= new (session->mem_root) Item_func_unix_timestamp(param_1);
2876
2647
    break;
2877
2648
  }
2878
2649
  default:
2879
2650
  {
2880
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2651
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2881
2652
    break;
2882
2653
  }
2883
2654
  }
2889
2660
Create_func_uuid Create_func_uuid::s_singleton;
2890
2661
 
2891
2662
Item*
2892
 
Create_func_uuid::create(THD *thd)
2893
 
{
2894
 
  thd->lex->set_stmt_unsafe();
2895
 
  return new (thd->mem_root) Item_func_uuid();
2896
 
}
2897
 
 
2898
 
 
2899
 
Create_func_version Create_func_version::s_singleton;
2900
 
 
2901
 
Item*
2902
 
Create_func_version::create(THD *thd)
2903
 
{
2904
 
  return new (thd->mem_root) Item_static_string_func("version()",
2905
 
                                                     server_version,
2906
 
                                                     (uint) strlen(server_version),
2907
 
                                                     system_charset_info,
2908
 
                                                     DERIVATION_SYSCONST);
 
2663
Create_func_uuid::create(Session *session)
 
2664
{
 
2665
  return new (session->mem_root) Item_func_uuid();
2909
2666
}
2910
2667
 
2911
2668
 
2912
2669
Create_func_weekday Create_func_weekday::s_singleton;
2913
2670
 
2914
2671
Item*
2915
 
Create_func_weekday::create(THD *thd, Item *arg1)
2916
 
{
2917
 
  return new (thd->mem_root) Item_func_weekday(arg1, 0);
2918
 
}
2919
 
 
2920
 
 
2921
 
Create_func_weekofyear Create_func_weekofyear::s_singleton;
2922
 
 
2923
 
Item*
2924
 
Create_func_weekofyear::create(THD *thd, Item *arg1)
2925
 
{
2926
 
  Item *i1= new (thd->mem_root) Item_int((char*) "0", 3, 1);
2927
 
  return new (thd->mem_root) Item_func_week(arg1, i1);
2928
 
}
2929
 
 
2930
 
 
2931
 
Create_func_year_week Create_func_year_week::s_singleton;
2932
 
 
2933
 
Item*
2934
 
Create_func_year_week::create_native(THD *thd, LEX_STRING name,
2935
 
                                     List<Item> *item_list)
2936
 
{
2937
 
  Item *func= NULL;
2938
 
  int arg_count= 0;
2939
 
 
2940
 
  if (item_list != NULL)
2941
 
    arg_count= item_list->elements;
2942
 
 
2943
 
  switch (arg_count) {
2944
 
  case 1:
2945
 
  {
2946
 
    Item *param_1= item_list->pop();
2947
 
    Item *i0= new (thd->mem_root) Item_int((char*) "0", 0, 1);
2948
 
    func= new (thd->mem_root) Item_func_yearweek(param_1, i0);
2949
 
    break;
2950
 
  }
2951
 
  case 2:
2952
 
  {
2953
 
    Item *param_1= item_list->pop();
2954
 
    Item *param_2= item_list->pop();
2955
 
    func= new (thd->mem_root) Item_func_yearweek(param_1, param_2);
2956
 
    break;
2957
 
  }
2958
 
  default:
2959
 
  {
2960
 
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
2961
 
    break;
2962
 
  }
2963
 
  }
2964
 
 
2965
 
  return func;
2966
 
}
2967
 
 
 
2672
Create_func_weekday::create(Session *session, Item *arg1)
 
2673
{
 
2674
  return new (session->mem_root) Item_func_weekday(arg1, 0);
 
2675
}
2968
2676
 
2969
2677
struct Native_func_registry
2970
2678
{
2985
2693
{
2986
2694
  { { C_STRING_WITH_LEN("ABS") }, BUILDER(Create_func_abs)},
2987
2695
  { { C_STRING_WITH_LEN("ACOS") }, BUILDER(Create_func_acos)},
2988
 
  { { C_STRING_WITH_LEN("ADDTIME") }, BUILDER(Create_func_addtime)},
2989
2696
  { { C_STRING_WITH_LEN("ASIN") }, BUILDER(Create_func_asin)},
2990
2697
  { { C_STRING_WITH_LEN("ATAN") }, BUILDER(Create_func_atan)},
2991
2698
  { { C_STRING_WITH_LEN("ATAN2") }, BUILDER(Create_func_atan)},
2992
 
  { { C_STRING_WITH_LEN("BENCHMARK") }, BUILDER(Create_func_benchmark)},
2993
2699
  { { C_STRING_WITH_LEN("BIN") }, BUILDER(Create_func_bin)},
2994
 
  { { C_STRING_WITH_LEN("BIT_COUNT") }, BUILDER(Create_func_bit_count)},
2995
 
  { { C_STRING_WITH_LEN("BIT_LENGTH") }, BUILDER(Create_func_bit_length)},
2996
2700
  { { C_STRING_WITH_LEN("CEIL") }, BUILDER(Create_func_ceiling)},
2997
2701
  { { C_STRING_WITH_LEN("CEILING") }, BUILDER(Create_func_ceiling)},
2998
 
  { { C_STRING_WITH_LEN("CHARACTER_LENGTH") }, BUILDER(Create_func_char_length)},
2999
 
  { { C_STRING_WITH_LEN("CHAR_LENGTH") }, BUILDER(Create_func_char_length)},
3000
2702
  { { C_STRING_WITH_LEN("COERCIBILITY") }, BUILDER(Create_func_coercibility)},
3001
2703
  { { C_STRING_WITH_LEN("CONCAT") }, BUILDER(Create_func_concat)},
3002
2704
  { { C_STRING_WITH_LEN("CONCAT_WS") }, BUILDER(Create_func_concat_ws)},
3003
 
  { { C_STRING_WITH_LEN("CONNECTION_ID") }, BUILDER(Create_func_connection_id)},
3004
2705
  { { C_STRING_WITH_LEN("CONV") }, BUILDER(Create_func_conv)},
3005
2706
  { { C_STRING_WITH_LEN("COS") }, BUILDER(Create_func_cos)},
3006
2707
  { { C_STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)},
3030
2731
  { { C_STRING_WITH_LEN("LAST_INSERT_ID") }, BUILDER(Create_func_last_insert_id)},
3031
2732
  { { C_STRING_WITH_LEN("LCASE") }, BUILDER(Create_func_lcase)},
3032
2733
  { { C_STRING_WITH_LEN("LEAST") }, BUILDER(Create_func_least)},
3033
 
  { { C_STRING_WITH_LEN("LENGTH") }, BUILDER(Create_func_length)},
3034
2734
  { { C_STRING_WITH_LEN("LN") }, BUILDER(Create_func_ln)},
3035
2735
  { { C_STRING_WITH_LEN("LOAD_FILE") }, BUILDER(Create_func_load_file)},
3036
2736
  { { C_STRING_WITH_LEN("LOCATE") }, BUILDER(Create_func_locate)},
3041
2741
  { { C_STRING_WITH_LEN("LPAD") }, BUILDER(Create_func_lpad)},
3042
2742
  { { C_STRING_WITH_LEN("LTRIM") }, BUILDER(Create_func_ltrim)},
3043
2743
  { { C_STRING_WITH_LEN("MAKEDATE") }, BUILDER(Create_func_makedate)},
3044
 
  { { C_STRING_WITH_LEN("MAKETIME") }, BUILDER(Create_func_maketime)},
3045
2744
  { { C_STRING_WITH_LEN("MAKE_SET") }, BUILDER(Create_func_make_set)},
3046
 
  { { C_STRING_WITH_LEN("MASTER_POS_WAIT") }, BUILDER(Create_func_master_pos_wait)},
3047
2745
  { { C_STRING_WITH_LEN("MONTHNAME") }, BUILDER(Create_func_monthname)},
3048
2746
  { { C_STRING_WITH_LEN("NULLIF") }, BUILDER(Create_func_nullif)},
3049
2747
  { { C_STRING_WITH_LEN("OCT") }, BUILDER(Create_func_oct)},
3050
 
  { { C_STRING_WITH_LEN("OCTET_LENGTH") }, BUILDER(Create_func_length)},
3051
2748
  { { C_STRING_WITH_LEN("ORD") }, BUILDER(Create_func_ord)},
3052
2749
  { { C_STRING_WITH_LEN("PERIOD_ADD") }, BUILDER(Create_func_period_add)},
3053
2750
  { { C_STRING_WITH_LEN("PERIOD_DIFF") }, BUILDER(Create_func_period_diff)},
3061
2758
  { { C_STRING_WITH_LEN("ROW_COUNT") }, BUILDER(Create_func_row_count)},
3062
2759
  { { C_STRING_WITH_LEN("RPAD") }, BUILDER(Create_func_rpad)},
3063
2760
  { { C_STRING_WITH_LEN("RTRIM") }, BUILDER(Create_func_rtrim)},
3064
 
  { { C_STRING_WITH_LEN("SEC_TO_TIME") }, BUILDER(Create_func_sec_to_time)},
3065
2761
  { { C_STRING_WITH_LEN("SIGN") }, BUILDER(Create_func_sign)},
3066
2762
  { { C_STRING_WITH_LEN("SIN") }, BUILDER(Create_func_sin)},
3067
2763
  { { C_STRING_WITH_LEN("SPACE") }, BUILDER(Create_func_space)},
3068
2764
  { { C_STRING_WITH_LEN("SQRT") }, BUILDER(Create_func_sqrt)},
3069
2765
  { { C_STRING_WITH_LEN("STRCMP") }, BUILDER(Create_func_strcmp)},
3070
 
  { { C_STRING_WITH_LEN("STR_TO_DATE") }, BUILDER(Create_func_str_to_date)},
3071
2766
  { { C_STRING_WITH_LEN("SUBSTRING_INDEX") }, BUILDER(Create_func_substr_index)},
3072
 
  { { C_STRING_WITH_LEN("SUBTIME") }, BUILDER(Create_func_subtime)},
3073
2767
  { { C_STRING_WITH_LEN("TAN") }, BUILDER(Create_func_tan)},
3074
 
  { { C_STRING_WITH_LEN("TIMEDIFF") }, BUILDER(Create_func_timediff)},
3075
2768
  { { C_STRING_WITH_LEN("TIME_FORMAT") }, BUILDER(Create_func_time_format)},
3076
 
  { { C_STRING_WITH_LEN("TIME_TO_SEC") }, BUILDER(Create_func_time_to_sec)},
3077
2769
  { { C_STRING_WITH_LEN("TO_DAYS") }, BUILDER(Create_func_to_days)},
3078
2770
  { { C_STRING_WITH_LEN("UCASE") }, BUILDER(Create_func_ucase)},
3079
2771
  { { C_STRING_WITH_LEN("UNHEX") }, BUILDER(Create_func_unhex)},
3080
2772
  { { C_STRING_WITH_LEN("UNIX_TIMESTAMP") }, BUILDER(Create_func_unix_timestamp)},
3081
2773
  { { C_STRING_WITH_LEN("UPPER") }, BUILDER(Create_func_ucase)},
3082
2774
  { { C_STRING_WITH_LEN("UUID") }, BUILDER(Create_func_uuid)},
3083
 
  { { C_STRING_WITH_LEN("VERSION") }, BUILDER(Create_func_version)},
3084
2775
  { { C_STRING_WITH_LEN("WEEKDAY") }, BUILDER(Create_func_weekday)},
3085
 
  { { C_STRING_WITH_LEN("WEEKOFYEAR") }, BUILDER(Create_func_weekofyear)},
3086
 
  { { C_STRING_WITH_LEN("YEARWEEK") }, BUILDER(Create_func_year_week)},
3087
2776
 
3088
2777
  { {0, 0}, NULL}
3089
2778
};
3090
2779
 
3091
 
static HASH native_functions_hash;
3092
 
 
3093
 
extern "C" uchar*
3094
 
get_native_fct_hash_key(const uchar *buff, size_t *length,
3095
 
                        bool /* unused */)
3096
 
{
3097
 
  Native_func_registry *func= (Native_func_registry*) buff;
3098
 
  *length= func->name.length;
3099
 
  return (uchar*) func->name.str;
3100
 
}
 
2780
static map<string, Native_func_registry *> native_functions_map;
3101
2781
 
3102
2782
/*
3103
2783
  Load the hash table for native functions.
3107
2787
 
3108
2788
int item_create_init()
3109
2789
{
 
2790
  string func_name;
 
2791
 
3110
2792
  Native_func_registry *func;
3111
 
 
3112
 
  if (hash_init(& native_functions_hash,
3113
 
                system_charset_info,
3114
 
                array_elements(func_array),
3115
 
                0,
3116
 
                0,
3117
 
                (hash_get_key) get_native_fct_hash_key,
3118
 
                NULL,                          /* Nothing to free */
3119
 
                MYF(0)))
3120
 
    return(1);
3121
 
 
3122
2793
  for (func= func_array; func->builder != NULL; func++)
3123
2794
  {
3124
 
    if (my_hash_insert(& native_functions_hash, (uchar*) func))
3125
 
      return(1);
 
2795
    func_name.assign(func->name.str, func->name.length);
 
2796
    transform(func_name.begin(), func_name.end(), func_name.begin(), ::tolower);
 
2797
 
 
2798
    native_functions_map[func_name]= func;
3126
2799
  }
3127
2800
 
3128
 
  return(0);
3129
 
}
3130
 
 
3131
 
/*
3132
 
  Empty the hash table for native functions.
3133
 
  Note: this code is not thread safe, and is intended to be used at server
3134
 
  shutdown only (after thread requests have been executed).
3135
 
*/
3136
 
 
3137
 
void item_create_cleanup()
3138
 
{
3139
 
  hash_free(& native_functions_hash);
3140
 
  return;
3141
 
}
 
2801
  return 0;
 
2802
}
 
2803
 
3142
2804
 
3143
2805
Create_func *
3144
 
find_native_function_builder(THD *thd __attribute__((unused)),
3145
 
                             LEX_STRING name)
 
2806
find_native_function_builder(LEX_STRING name)
3146
2807
{
3147
2808
  Native_func_registry *func;
3148
2809
  Create_func *builder= NULL;
3149
2810
 
3150
 
  /* Thread safe */
3151
 
  func= (Native_func_registry*) hash_search(& native_functions_hash,
3152
 
                                            (uchar*) name.str,
3153
 
                                             name.length);
3154
 
 
3155
 
  if (func)
 
2811
  string func_name(name.str, name.length);
 
2812
  transform(func_name.begin(), func_name.end(), func_name.begin(), ::tolower);
 
2813
 
 
2814
  map<string, Native_func_registry *>::iterator func_iter=
 
2815
    native_functions_map.find(func_name);
 
2816
 
 
2817
  if (func_iter != native_functions_map.end())
3156
2818
  {
 
2819
    func= (*func_iter).second;
3157
2820
    builder= func->builder;
3158
2821
  }
3159
2822
 
3162
2825
 
3163
2826
 
3164
2827
Item*
3165
 
create_func_char_cast(THD *thd, Item *a, int len, const CHARSET_INFO * const cs)
 
2828
create_func_char_cast(Session *session, Item *a, int len, const CHARSET_INFO * const cs)
3166
2829
{
3167
 
  const CHARSET_INFO * const real_cs= (cs ? cs : thd->variables.collation_connection);
3168
 
  return new (thd->mem_root) Item_char_typecast(a, len, real_cs);
 
2830
  const CHARSET_INFO * const real_cs= (cs ? cs : session->variables.getCollation());
 
2831
  return new (session->mem_root) Item_char_typecast(a, len, real_cs);
3169
2832
}
3170
2833
 
3171
2834
 
3172
2835
Item *
3173
 
create_func_cast(THD *thd, Item *a, Cast_target cast_type,
 
2836
create_func_cast(Session *session, Item *a, Cast_target cast_type,
3174
2837
                 const char *c_len, const char *c_dec,
3175
2838
                 const CHARSET_INFO * const cs)
3176
2839
{
3177
2840
  Item *res;
3178
2841
  uint32_t len;
3179
 
  uint dec;
 
2842
  uint32_t dec;
3180
2843
 
3181
2844
  switch (cast_type) {
3182
2845
  case ITEM_CAST_BINARY:
3183
 
    res= new (thd->mem_root) Item_func_binary(a);
3184
 
    break;
3185
 
  case ITEM_CAST_SIGNED_INT:
3186
 
    res= new (thd->mem_root) Item_func_signed(a);
3187
 
    break;
3188
 
  case ITEM_CAST_UNSIGNED_INT:
3189
 
    res= new (thd->mem_root) Item_func_unsigned(a);
 
2846
    res= new (session->mem_root) Item_func_binary(a);
3190
2847
    break;
3191
2848
  case ITEM_CAST_DATE:
3192
 
    res= new (thd->mem_root) Item_date_typecast(a);
3193
 
    break;
3194
 
  case ITEM_CAST_TIME:
3195
 
    res= new (thd->mem_root) Item_time_typecast(a);
 
2849
    res= new (session->mem_root) Item_date_typecast(a);
3196
2850
    break;
3197
2851
  case ITEM_CAST_DATETIME:
3198
 
    res= new (thd->mem_root) Item_datetime_typecast(a);
 
2852
    res= new (session->mem_root) Item_datetime_typecast(a);
3199
2853
    break;
3200
2854
  case ITEM_CAST_DECIMAL:
3201
2855
  {
3219
2873
               DECIMAL_MAX_SCALE);
3220
2874
      return 0;
3221
2875
    }
3222
 
    res= new (thd->mem_root) Item_decimal_typecast(a, len, dec);
 
2876
    res= new (session->mem_root) Item_decimal_typecast(a, len, dec);
3223
2877
    break;
3224
2878
  }
3225
2879
  case ITEM_CAST_CHAR:
3226
2880
  {
3227
2881
    len= c_len ? atoi(c_len) : -1;
3228
 
    res= create_func_char_cast(thd, a, len, cs);
 
2882
    res= create_func_char_cast(session, a, len, cs);
3229
2883
    break;
3230
2884
  }
3231
2885
  default: