~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_create.cc

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:59 UTC
  • mfrom: (518 drizzle)
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063259-fwbqogq7lnezct0l
Merged with trunk.

Show diffs side-by-side

added added

removed removed

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