~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_create.cc

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

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