~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/create.cc

pandora-build v0.71. Added check for avahi.

Show diffs side-by-side

added added

removed removed

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