~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item_create.cc

  • Committer: Jay Pipes
  • Date: 2008-07-18 20:20:47 UTC
  • mto: This revision was merged to the branch mainline in revision 182.
  • Revision ID: jay@mysql.com-20080718202047-1tnd4i9z3k3cvg9v
DBUG entirely removed from server and client

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