~drizzle-trunk/drizzle/development

1 by brian
clean slate
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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
16
/**
17
  @file
18
19
  @brief
20
  Functions to create an item. Used by sql_yac.yy
21
*/
22
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
23
#include <config.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
24
#include <drizzled/item/create.h>
25
#include <drizzled/item/func.h>
550 by Monty Taylor
Moved error.h into just the files that need it.
26
#include <drizzled/error.h>
1 by brian
clean slate
27
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
28
#include <drizzled/function_container.h>
1751.3.3 by Brian Aker
Shuffle native functions over to hash such that we have a specific container
29
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
30
#include <drizzled/function/str/binary.h>
31
#include <drizzled/function/str/concat.h>
32
#include <drizzled/function/str/conv.h>
33
#include <drizzled/function/str/export_set.h>
34
#include <drizzled/function/str/load_file.h>
35
#include <drizzled/function/str/make_set.h>
36
#include <drizzled/function/str/pad.h>
37
#include <drizzled/function/str/repeat.h>
38
#include <drizzled/function/str/str_conv.h>
39
#include <drizzled/function/str/trim.h>
642.1.12 by Lee
remove drizzled/item/strfunc.h, no longer needed
40
670.1.22 by Monty Taylor
Merged from Lee.
41
#include <drizzled/function/time/date_format.h>
42
#include <drizzled/function/time/dayname.h>
43
#include <drizzled/function/time/dayofmonth.h>
44
#include <drizzled/function/time/dayofyear.h>
45
#include <drizzled/function/time/from_unixtime.h>
46
#include <drizzled/function/time/from_days.h>
47
#include <drizzled/function/time/last_day.h>
48
#include <drizzled/function/time/makedate.h>
49
#include <drizzled/function/time/month.h>
50
#include <drizzled/function/time/period_add.h>
51
#include <drizzled/function/time/period_diff.h>
52
#include <drizzled/function/time/to_days.h>
53
#include <drizzled/function/time/typecast.h>
54
#include <drizzled/function/time/unix_timestamp.h>
55
#include <drizzled/function/time/weekday.h>
642.1.13 by Lee
remove drizzled/item/timefunc.h, no longer needed
56
584.4.7 by Monty Taylor
Removed a big bank of includes from item.h.
57
#include <drizzled/item/cmpfunc.h>
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
58
#include <drizzled/plugin/function.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
59
#include <drizzled/session.h>
584.4.7 by Monty Taylor
Removed a big bank of includes from item.h.
60
648 by Brian Aker
Fix for create to keep its include files (which speeds up recompiles).
61
/* Function declarations */
62
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
63
#include <drizzled/function/func.h>
64
#include <drizzled/function/additive_op.h>
642.1.30 by Lee
move math functions to drizzled/function/math directory
65
#include <drizzled/function/math/dec.h>
66
#include <drizzled/function/math/decimal_typecast.h>
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
67
#include <drizzled/function/field.h>
68
#include <drizzled/function/find_in_set.h>
69
#include <drizzled/function/found_rows.h>
70
#include <drizzled/function/get_system_var.h>
642.1.30 by Lee
move math functions to drizzled/function/math directory
71
#include <drizzled/function/math/int_val.h>
72
#include <drizzled/function/math/integer.h>
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
73
#include <drizzled/function/last_insert.h>
74
#include <drizzled/function/locate.h>
75
#include <drizzled/function/min_max.h>
76
#include <drizzled/function/num1.h>
77
#include <drizzled/function/num_op.h>
78
#include <drizzled/function/numhybrid.h>
642.1.30 by Lee
move math functions to drizzled/function/math directory
79
#include <drizzled/function/math/real.h>
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
80
#include <drizzled/function/row_count.h>
81
#include <drizzled/function/set_user_var.h>
82
#include <drizzled/function/sign.h>
642.1.30 by Lee
move math functions to drizzled/function/math directory
83
#include <drizzled/function/math/tan.h>
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
84
#include <drizzled/function/units.h>
648 by Brian Aker
Fix for create to keep its include files (which speeds up recompiles).
85
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
86
#include <drizzled/function/cast/boolean.h>
87
#include <drizzled/function/cast/signed.h>
88
#include <drizzled/function/cast/time.h>
89
#include <drizzled/function/cast/unsigned.h>
1999.4.8 by Brian Aker
Adding in time type.
90
873.2.19 by Monty Taylor
Removed another HASH and another set of useless utf8 hashing.
91
using namespace std;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
92
93
namespace drizzled
94
{
648 by Brian Aker
Fix for create to keep its include files (which speeds up recompiles).
95
584.4.7 by Monty Taylor
Removed a big bank of includes from item.h.
96
class Item;
97
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
98
1 by brian
clean slate
99
/*
100
=============================================================================
101
  LOCAL DECLARATIONS
102
=============================================================================
103
*/
104
105
/**
106
  Adapter for native functions with a variable number of arguments.
107
  The main use of this class is to discard the following calls:
108
  <code>foo(expr1 AS name1, expr2 AS name2, ...)</code>
109
  which are syntactically correct (the syntax can refer to a UDF),
110
  but semantically invalid for native functions.
111
*/
112
113
class Create_native_func : public Create_func
114
{
115
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
116
  virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
117
118
  /**
119
    Builder method, with no arguments.
520.1.22 by Brian Aker
Second pass of thd cleanup
120
    @param session The current thread
1 by brian
clean slate
121
    @param name The native function name
122
    @param item_list The function parameters, none of which are named
123
    @return An item representing the function call
124
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
125
  virtual Item *create_native(Session *session, LEX_STRING name,
1 by brian
clean slate
126
                              List<Item> *item_list) = 0;
127
128
protected:
129
  /** Constructor. */
130
  Create_native_func() {}
131
  /** Destructor. */
132
  virtual ~Create_native_func() {}
133
};
134
135
136
/**
137
  Adapter for functions that takes exactly zero arguments.
138
*/
139
140
class Create_func_arg0 : public Create_func
141
{
142
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
143
  virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
144
145
  /**
146
    Builder method, with no arguments.
520.1.22 by Brian Aker
Second pass of thd cleanup
147
    @param session The current thread
1 by brian
clean slate
148
    @return An item representing the function call
149
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
150
  virtual Item *create(Session *session) = 0;
1 by brian
clean slate
151
152
protected:
153
  /** Constructor. */
154
  Create_func_arg0() {}
155
  /** Destructor. */
156
  virtual ~Create_func_arg0() {}
157
};
158
159
160
/**
161
  Adapter for functions that takes exactly one argument.
162
*/
163
164
class Create_func_arg1 : public Create_func
165
{
166
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
167
  virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
168
169
  /**
170
    Builder method, with one argument.
520.1.22 by Brian Aker
Second pass of thd cleanup
171
    @param session The current thread
1 by brian
clean slate
172
    @param arg1 The first argument of the function
173
    @return An item representing the function call
174
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
175
  virtual Item *create(Session *session, Item *arg1) = 0;
1 by brian
clean slate
176
177
protected:
178
  /** Constructor. */
179
  Create_func_arg1() {}
180
  /** Destructor. */
181
  virtual ~Create_func_arg1() {}
182
};
183
184
185
/**
186
  Adapter for functions that takes exactly two arguments.
187
*/
188
189
class Create_func_arg2 : public Create_func
190
{
191
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
192
  virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
193
194
  /**
195
    Builder method, with two arguments.
520.1.22 by Brian Aker
Second pass of thd cleanup
196
    @param session The current thread
1 by brian
clean slate
197
    @param arg1 The first argument of the function
198
    @param arg2 The second argument of the function
199
    @return An item representing the function call
200
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
201
  virtual Item *create(Session *session, Item *arg1, Item *arg2) = 0;
1 by brian
clean slate
202
203
protected:
204
  /** Constructor. */
205
  Create_func_arg2() {}
206
  /** Destructor. */
207
  virtual ~Create_func_arg2() {}
208
};
209
210
211
/**
212
  Adapter for functions that takes exactly three arguments.
213
*/
214
215
class Create_func_arg3 : public Create_func
216
{
217
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
218
  virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
219
220
  /**
221
    Builder method, with three arguments.
520.1.22 by Brian Aker
Second pass of thd cleanup
222
    @param session The current thread
1 by brian
clean slate
223
    @param arg1 The first argument of the function
224
    @param arg2 The second argument of the function
225
    @param arg3 The third argument of the function
226
    @return An item representing the function call
227
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
228
  virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3) = 0;
1 by brian
clean slate
229
230
protected:
231
  /** Constructor. */
232
  Create_func_arg3() {}
233
  /** Destructor. */
234
  virtual ~Create_func_arg3() {}
235
};
236
237
238
/**
239
  Function builder for Stored Functions.
240
*/
241
242
/*
243
  Concrete functions builders (native functions).
244
  Please keep this list sorted in alphabetical order,
245
  it helps to compare code between versions, and helps with merges conflicts.
246
*/
247
248
249
class Create_func_bin : public Create_func_arg1
250
{
251
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
252
  using Create_func_arg1::create;
253
520.1.22 by Brian Aker
Second pass of thd cleanup
254
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
255
256
  static Create_func_bin s_singleton;
257
258
protected:
259
  Create_func_bin() {}
260
  virtual ~Create_func_bin() {}
261
};
262
263
class Create_func_concat : public Create_native_func
264
{
265
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
266
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
267
268
  static Create_func_concat s_singleton;
269
270
protected:
271
  Create_func_concat() {}
272
  virtual ~Create_func_concat() {}
273
};
274
275
276
class Create_func_concat_ws : public Create_native_func
277
{
278
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
279
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
280
281
  static Create_func_concat_ws s_singleton;
282
283
protected:
284
  Create_func_concat_ws() {}
285
  virtual ~Create_func_concat_ws() {}
286
};
287
288
289
class Create_func_conv : public Create_func_arg3
290
{
291
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
292
  using Create_func_arg3::create;
293
520.1.22 by Brian Aker
Second pass of thd cleanup
294
  virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3);
1 by brian
clean slate
295
296
  static Create_func_conv s_singleton;
297
298
protected:
299
  Create_func_conv() {}
300
  virtual ~Create_func_conv() {}
301
};
302
303
class Create_func_cot : public Create_func_arg1
304
{
305
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
306
  using Create_func_arg1::create;
307
520.1.22 by Brian Aker
Second pass of thd cleanup
308
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
309
310
  static Create_func_cot s_singleton;
311
312
protected:
313
  Create_func_cot() {}
314
  virtual ~Create_func_cot() {}
315
};
316
317
class Create_func_date_format : public Create_func_arg2
318
{
319
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
320
  using Create_func_arg2::create;
321
520.1.22 by Brian Aker
Second pass of thd cleanup
322
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
323
324
  static Create_func_date_format s_singleton;
325
326
protected:
327
  Create_func_date_format() {}
328
  virtual ~Create_func_date_format() {}
329
};
330
331
332
class Create_func_datediff : public Create_func_arg2
333
{
334
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
335
  using Create_func_arg2::create;
336
520.1.22 by Brian Aker
Second pass of thd cleanup
337
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
338
339
  static Create_func_datediff s_singleton;
340
341
protected:
342
  Create_func_datediff() {}
343
  virtual ~Create_func_datediff() {}
344
};
345
346
347
class Create_func_dayname : public Create_func_arg1
348
{
349
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
350
  using Create_func_arg1::create;
351
520.1.22 by Brian Aker
Second pass of thd cleanup
352
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
353
354
  static Create_func_dayname s_singleton;
355
356
protected:
357
  Create_func_dayname() {}
358
  virtual ~Create_func_dayname() {}
359
};
360
361
362
class Create_func_dayofmonth : public Create_func_arg1
363
{
364
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
365
  using Create_func_arg1::create;
366
520.1.22 by Brian Aker
Second pass of thd cleanup
367
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
368
369
  static Create_func_dayofmonth s_singleton;
370
371
protected:
372
  Create_func_dayofmonth() {}
373
  virtual ~Create_func_dayofmonth() {}
374
};
375
376
377
class Create_func_dayofweek : public Create_func_arg1
378
{
379
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
380
  using Create_func_arg1::create;
381
520.1.22 by Brian Aker
Second pass of thd cleanup
382
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
383
384
  static Create_func_dayofweek s_singleton;
385
386
protected:
387
  Create_func_dayofweek() {}
388
  virtual ~Create_func_dayofweek() {}
389
};
390
391
392
class Create_func_dayofyear : public Create_func_arg1
393
{
394
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
395
  using Create_func_arg1::create;
396
520.1.22 by Brian Aker
Second pass of thd cleanup
397
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
398
399
  static Create_func_dayofyear s_singleton;
400
401
protected:
402
  Create_func_dayofyear() {}
403
  virtual ~Create_func_dayofyear() {}
404
};
405
406
407
class Create_func_decode : public Create_func_arg2
408
{
409
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
410
  using Create_func_arg2::create;
411
520.1.22 by Brian Aker
Second pass of thd cleanup
412
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
413
414
  static Create_func_decode s_singleton;
415
416
protected:
417
  Create_func_decode() {}
418
  virtual ~Create_func_decode() {}
419
};
420
421
422
class Create_func_degrees : public Create_func_arg1
423
{
424
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
425
  using Create_func_arg1::create;
426
520.1.22 by Brian Aker
Second pass of thd cleanup
427
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
428
429
  static Create_func_degrees s_singleton;
430
431
protected:
432
  Create_func_degrees() {}
433
  virtual ~Create_func_degrees() {}
434
};
435
436
class Create_func_export_set : public Create_native_func
437
{
1759.3.15 by Stewart Smith
move SQRT() function into math_functions plugin
438
1 by brian
clean slate
439
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
440
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
441
442
  static Create_func_export_set s_singleton;
443
444
protected:
445
  Create_func_export_set() {}
446
  virtual ~Create_func_export_set() {}
447
};
448
449
450
class Create_func_field : public Create_native_func
451
{
452
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
453
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
454
455
  static Create_func_field s_singleton;
456
457
protected:
458
  Create_func_field() {}
459
  virtual ~Create_func_field() {}
460
};
461
462
463
class Create_func_find_in_set : public Create_func_arg2
464
{
465
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
466
  using Create_func_arg2::create;
467
520.1.22 by Brian Aker
Second pass of thd cleanup
468
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
469
470
  static Create_func_find_in_set s_singleton;
471
472
protected:
473
  Create_func_find_in_set() {}
474
  virtual ~Create_func_find_in_set() {}
475
};
476
477
class Create_func_found_rows : public Create_func_arg0
478
{
479
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
480
  using Create_func_arg0::create;
481
520.1.22 by Brian Aker
Second pass of thd cleanup
482
  virtual Item *create(Session *session);
1 by brian
clean slate
483
484
  static Create_func_found_rows s_singleton;
485
486
protected:
487
  Create_func_found_rows() {}
488
  virtual ~Create_func_found_rows() {}
489
};
490
491
492
class Create_func_from_days : public Create_func_arg1
493
{
494
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
495
  using Create_func_arg1::create;
496
520.1.22 by Brian Aker
Second pass of thd cleanup
497
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
498
499
  static Create_func_from_days s_singleton;
500
501
protected:
502
  Create_func_from_days() {}
503
  virtual ~Create_func_from_days() {}
504
};
505
506
507
class Create_func_from_unixtime : public Create_native_func
508
{
509
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
510
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
511
512
  static Create_func_from_unixtime s_singleton;
513
514
protected:
515
  Create_func_from_unixtime() {}
516
  virtual ~Create_func_from_unixtime() {}
517
};
518
519
520
class Create_func_greatest : public Create_native_func
521
{
522
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
523
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
524
525
  static Create_func_greatest s_singleton;
526
527
protected:
528
  Create_func_greatest() {}
529
  virtual ~Create_func_greatest() {}
530
};
531
532
533
class Create_func_ifnull : public Create_func_arg2
534
{
535
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
536
  using Create_func_arg2::create;
537
520.1.22 by Brian Aker
Second pass of thd cleanup
538
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
539
540
  static Create_func_ifnull s_singleton;
541
542
protected:
543
  Create_func_ifnull() {}
544
  virtual ~Create_func_ifnull() {}
545
};
546
547
548
class Create_func_instr : public Create_func_arg2
549
{
550
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
551
  using Create_func_arg2::create;
552
520.1.22 by Brian Aker
Second pass of thd cleanup
553
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
554
555
  static Create_func_instr s_singleton;
556
557
protected:
558
  Create_func_instr() {}
559
  virtual ~Create_func_instr() {}
560
};
561
562
563
class Create_func_isnull : public Create_func_arg1
564
{
565
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
566
  using Create_func_arg1::create;
567
520.1.22 by Brian Aker
Second pass of thd cleanup
568
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
569
570
  static Create_func_isnull s_singleton;
571
572
protected:
573
  Create_func_isnull() {}
574
  virtual ~Create_func_isnull() {}
575
};
576
577
578
class Create_func_last_day : public Create_func_arg1
579
{
580
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
581
  using Create_func_arg1::create;
582
520.1.22 by Brian Aker
Second pass of thd cleanup
583
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
584
585
  static Create_func_last_day s_singleton;
586
587
protected:
588
  Create_func_last_day() {}
589
  virtual ~Create_func_last_day() {}
590
};
591
592
593
class Create_func_last_insert_id : public Create_native_func
594
{
595
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
596
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
597
598
  static Create_func_last_insert_id s_singleton;
599
600
protected:
601
  Create_func_last_insert_id() {}
602
  virtual ~Create_func_last_insert_id() {}
603
};
604
605
606
class Create_func_lcase : public Create_func_arg1
607
{
608
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
609
  using Create_func_arg1::create;
610
520.1.22 by Brian Aker
Second pass of thd cleanup
611
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
612
613
  static Create_func_lcase s_singleton;
614
615
protected:
616
  Create_func_lcase() {}
617
  virtual ~Create_func_lcase() {}
618
};
619
620
621
class Create_func_least : public Create_native_func
622
{
623
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
624
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
625
626
  static Create_func_least s_singleton;
627
628
protected:
629
  Create_func_least() {}
630
  virtual ~Create_func_least() {}
631
};
632
633
class Create_func_load_file : public Create_func_arg1
634
{
635
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
636
  using Create_func_arg1::create;
637
520.1.22 by Brian Aker
Second pass of thd cleanup
638
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
639
640
  static Create_func_load_file s_singleton;
641
642
protected:
643
  Create_func_load_file() {}
644
  virtual ~Create_func_load_file() {}
645
};
646
647
648
class Create_func_locate : public Create_native_func
649
{
650
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
651
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
652
653
  static Create_func_locate s_singleton;
654
655
protected:
656
  Create_func_locate() {}
657
  virtual ~Create_func_locate() {}
658
};
659
660
661
class Create_func_lpad : public Create_func_arg3
662
{
663
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
664
  using Create_func_arg3::create;
665
520.1.22 by Brian Aker
Second pass of thd cleanup
666
  virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3);
1 by brian
clean slate
667
668
  static Create_func_lpad s_singleton;
669
670
protected:
671
  Create_func_lpad() {}
672
  virtual ~Create_func_lpad() {}
673
};
674
675
676
class Create_func_ltrim : public Create_func_arg1
677
{
678
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
679
  using Create_func_arg1::create;
680
520.1.22 by Brian Aker
Second pass of thd cleanup
681
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
682
683
  static Create_func_ltrim s_singleton;
684
685
protected:
686
  Create_func_ltrim() {}
687
  virtual ~Create_func_ltrim() {}
688
};
689
690
691
class Create_func_makedate : public Create_func_arg2
692
{
693
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
694
  using Create_func_arg2::create;
695
520.1.22 by Brian Aker
Second pass of thd cleanup
696
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
697
698
  static Create_func_makedate s_singleton;
699
700
protected:
701
  Create_func_makedate() {}
702
  virtual ~Create_func_makedate() {}
703
};
704
705
class Create_func_make_set : public Create_native_func
706
{
707
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
708
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
709
710
  static Create_func_make_set s_singleton;
711
712
protected:
713
  Create_func_make_set() {}
714
  virtual ~Create_func_make_set() {}
715
};
716
717
718
class Create_func_monthname : public Create_func_arg1
719
{
720
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
721
  using Create_func_arg1::create;
722
520.1.22 by Brian Aker
Second pass of thd cleanup
723
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
724
725
  static Create_func_monthname s_singleton;
726
727
protected:
728
  Create_func_monthname() {}
729
  virtual ~Create_func_monthname() {}
730
};
731
732
733
class Create_func_name_const : public Create_func_arg2
734
{
735
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
736
  using Create_func_arg2::create;
737
520.1.22 by Brian Aker
Second pass of thd cleanup
738
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
739
740
  static Create_func_name_const s_singleton;
741
742
protected:
743
  Create_func_name_const() {}
744
  virtual ~Create_func_name_const() {}
745
};
746
747
748
class Create_func_nullif : public Create_func_arg2
749
{
750
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
751
  using Create_func_arg2::create;
752
520.1.22 by Brian Aker
Second pass of thd cleanup
753
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
754
755
  static Create_func_nullif s_singleton;
756
757
protected:
758
  Create_func_nullif() {}
759
  virtual ~Create_func_nullif() {}
760
};
761
762
763
class Create_func_oct : public Create_func_arg1
764
{
765
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
766
  using Create_func_arg1::create;
767
520.1.22 by Brian Aker
Second pass of thd cleanup
768
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
769
770
  static Create_func_oct s_singleton;
771
772
protected:
773
  Create_func_oct() {}
774
  virtual ~Create_func_oct() {}
775
};
776
777
class Create_func_period_add : public Create_func_arg2
778
{
779
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
780
  using Create_func_arg2::create;
781
520.1.22 by Brian Aker
Second pass of thd cleanup
782
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
783
784
  static Create_func_period_add s_singleton;
785
786
protected:
787
  Create_func_period_add() {}
788
  virtual ~Create_func_period_add() {}
789
};
790
791
792
class Create_func_period_diff : public Create_func_arg2
793
{
794
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
795
  using Create_func_arg2::create;
796
520.1.22 by Brian Aker
Second pass of thd cleanup
797
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
798
799
  static Create_func_period_diff s_singleton;
800
801
protected:
802
  Create_func_period_diff() {}
803
  virtual ~Create_func_period_diff() {}
804
};
805
806
807
class Create_func_pi : public Create_func_arg0
808
{
809
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
810
  using Create_func_arg0::create;
811
520.1.22 by Brian Aker
Second pass of thd cleanup
812
  virtual Item *create(Session *session);
1 by brian
clean slate
813
814
  static Create_func_pi s_singleton;
815
816
protected:
817
  Create_func_pi() {}
818
  virtual ~Create_func_pi() {}
819
};
820
821
class Create_func_radians : public Create_func_arg1
822
{
823
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
824
  using Create_func_arg1::create;
825
520.1.22 by Brian Aker
Second pass of thd cleanup
826
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
827
828
  static Create_func_radians s_singleton;
829
830
protected:
831
  Create_func_radians() {}
832
  virtual ~Create_func_radians() {}
833
};
834
835
836
class Create_func_round : public Create_native_func
837
{
838
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
839
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
840
841
  static Create_func_round s_singleton;
842
843
protected:
844
  Create_func_round() {}
845
  virtual ~Create_func_round() {}
846
};
847
848
849
class Create_func_row_count : public Create_func_arg0
850
{
851
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
852
  using Create_func_arg0::create;
853
520.1.22 by Brian Aker
Second pass of thd cleanup
854
  virtual Item *create(Session *session);
1 by brian
clean slate
855
856
  static Create_func_row_count s_singleton;
857
858
protected:
859
  Create_func_row_count() {}
860
  virtual ~Create_func_row_count() {}
861
};
862
863
864
class Create_func_rpad : public Create_func_arg3
865
{
866
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
867
  using Create_func_arg3::create;
868
520.1.22 by Brian Aker
Second pass of thd cleanup
869
  virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3);
1 by brian
clean slate
870
871
  static Create_func_rpad s_singleton;
872
873
protected:
874
  Create_func_rpad() {}
875
  virtual ~Create_func_rpad() {}
876
};
877
878
879
class Create_func_rtrim : public Create_func_arg1
880
{
881
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
882
  using Create_func_arg1::create;
883
520.1.22 by Brian Aker
Second pass of thd cleanup
884
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
885
886
  static Create_func_rtrim s_singleton;
887
888
protected:
889
  Create_func_rtrim() {}
890
  virtual ~Create_func_rtrim() {}
891
};
892
893
class Create_func_sign : public Create_func_arg1
894
{
895
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
896
  using Create_func_arg1::create;
897
520.1.22 by Brian Aker
Second pass of thd cleanup
898
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
899
900
  static Create_func_sign s_singleton;
901
902
protected:
903
  Create_func_sign() {}
904
  virtual ~Create_func_sign() {}
905
};
906
907
class Create_func_space : public Create_func_arg1
908
{
909
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
910
  using Create_func_arg1::create;
911
520.1.22 by Brian Aker
Second pass of thd cleanup
912
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
913
914
  static Create_func_space s_singleton;
915
916
protected:
917
  Create_func_space() {}
918
  virtual ~Create_func_space() {}
919
};
920
921
class Create_func_strcmp : public Create_func_arg2
922
{
923
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
924
  using Create_func_arg2::create;
925
520.1.22 by Brian Aker
Second pass of thd cleanup
926
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
927
928
  static Create_func_strcmp s_singleton;
929
930
protected:
931
  Create_func_strcmp() {}
932
  virtual ~Create_func_strcmp() {}
933
};
934
935
936
class Create_func_tan : public Create_func_arg1
937
{
938
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
939
  using Create_func_arg1::create;
940
520.1.22 by Brian Aker
Second pass of thd cleanup
941
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
942
943
  static Create_func_tan s_singleton;
944
945
protected:
946
  Create_func_tan() {}
947
  virtual ~Create_func_tan() {}
948
};
949
950
951
class Create_func_time_format : public Create_func_arg2
952
{
953
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
954
  using Create_func_arg2::create;
955
520.1.22 by Brian Aker
Second pass of thd cleanup
956
  virtual Item *create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
957
958
  static Create_func_time_format s_singleton;
959
960
protected:
961
  Create_func_time_format() {}
962
  virtual ~Create_func_time_format() {}
963
};
964
965
966
class Create_func_time_to_sec : public Create_func_arg1
967
{
968
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
969
  using Create_func_arg1::create;
970
520.1.22 by Brian Aker
Second pass of thd cleanup
971
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
972
973
  static Create_func_time_to_sec s_singleton;
974
975
protected:
976
  Create_func_time_to_sec() {}
977
  virtual ~Create_func_time_to_sec() {}
978
};
979
980
981
class Create_func_to_days : public Create_func_arg1
982
{
983
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
984
  using Create_func_arg1::create;
985
520.1.22 by Brian Aker
Second pass of thd cleanup
986
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
987
988
  static Create_func_to_days s_singleton;
989
990
protected:
991
  Create_func_to_days() {}
992
  virtual ~Create_func_to_days() {}
993
};
994
995
996
class Create_func_ucase : public Create_func_arg1
997
{
998
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
999
  using Create_func_arg1::create;
1000
520.1.22 by Brian Aker
Second pass of thd cleanup
1001
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
1002
1003
  static Create_func_ucase s_singleton;
1004
1005
protected:
1006
  Create_func_ucase() {}
1007
  virtual ~Create_func_ucase() {}
1008
};
1009
1010
1011
class Create_func_unix_timestamp : public Create_native_func
1012
{
1013
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
1014
  virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
1015
1016
  static Create_func_unix_timestamp s_singleton;
1017
1018
protected:
1019
  Create_func_unix_timestamp() {}
1020
  virtual ~Create_func_unix_timestamp() {}
1021
};
1022
1023
1024
class Create_func_weekday : public Create_func_arg1
1025
{
1026
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
1027
  using Create_func_arg1::create;
1028
520.1.22 by Brian Aker
Second pass of thd cleanup
1029
  virtual Item *create(Session *session, Item *arg1);
1 by brian
clean slate
1030
1031
  static Create_func_weekday s_singleton;
1032
1033
protected:
1034
  Create_func_weekday() {}
1035
  virtual ~Create_func_weekday() {}
1036
};
1037
1038
/*
1039
=============================================================================
1040
  IMPLEMENTATION
1041
=============================================================================
1042
*/
1043
1044
/**
1045
  Checks if there are named parameters in a parameter list.
1046
  The syntax to name parameters in a function call is as follow:
1047
  <code>foo(expr AS named, expr named, expr AS "named", expr "named")</code>
1048
  @param params The parameter list, can be null
1049
  @return true if one or more parameter is named
1050
*/
1051
static bool has_named_parameters(List<Item> *params)
1052
{
1053
  if (params)
1054
  {
1055
    Item *param;
2183.2.11 by Olaf van der Spek
Use List::begin()
1056
    List<Item>::iterator it(params->begin());
1 by brian
clean slate
1057
    while ((param= it++))
1058
    {
1059
      if (! param->is_autogenerated_name)
1060
        return true;
1061
    }
1062
  }
1063
1064
  return false;
1065
}
1066
1067
1068
Create_udf_func Create_udf_func::s_singleton;
1069
1070
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1071
Create_udf_func::create(Session *session, LEX_STRING name, List<Item> *item_list)
1 by brian
clean slate
1072
{
2198.6.15 by Brian Aker
Remove caller convert to std::string (ie we were going back and forth in
1073
  const plugin::Function *udf= plugin::Function::get(std::string(name.str, name.length));
51.1.19 by Jay Pipes
Removed/replace DBUG symbols
1074
  assert(udf);
520.1.22 by Brian Aker
Second pass of thd cleanup
1075
  return create(session, udf, item_list);
1 by brian
clean slate
1076
}
1077
1078
1079
Item*
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
1080
Create_udf_func::create(Session *session, const plugin::Function *udf,
942.1.12 by Monty Taylor
Converted udf_func into a factory.
1081
                        List<Item> *item_list)
1 by brian
clean slate
1082
{
139.1.8 by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot.
1083
  Item_func *func= NULL;
1 by brian
clean slate
1084
  int arg_count= 0;
1085
1086
  if (item_list != NULL)
2183.2.17 by Olaf van der Spek
Use List::size()
1087
    arg_count= item_list->size();
1 by brian
clean slate
1088
942.1.12 by Monty Taylor
Converted udf_func into a factory.
1089
  func= (*udf)(session->mem_root);
139.1.8 by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot.
1090
997.8.1 by Stewart Smith
Add check for argument numbers for UDFs. Fix crc32 and md5
1091
  if(!func->check_argument_count(arg_count))
1092
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1093
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), func->func_name());
997.8.1 by Stewart Smith
Add check for argument numbers for UDFs. Fix crc32 and md5
1094
    return NULL;
1095
  }
1096
1097
  if(item_list)
1098
    func->set_arguments(*item_list);
139.1.8 by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot.
1099
1 by brian
clean slate
1100
  return func;
1101
}
1102
1103
1104
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1105
Create_native_func::create(Session *session, LEX_STRING name, List<Item> *item_list)
1 by brian
clean slate
1106
{
1107
  if (has_named_parameters(item_list))
1108
  {
1109
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1110
    return NULL;
1111
  }
1112
520.1.22 by Brian Aker
Second pass of thd cleanup
1113
  return create_native(session, name, item_list);
1 by brian
clean slate
1114
}
1115
1116
1117
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1118
Create_func_arg0::create(Session *session, LEX_STRING name, List<Item> *item_list)
1 by brian
clean slate
1119
{
1120
  int arg_count= 0;
1121
1122
  if (item_list != NULL)
2183.2.17 by Olaf van der Spek
Use List::size()
1123
    arg_count= item_list->size();
1 by brian
clean slate
1124
1125
  if (arg_count != 0)
1126
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1127
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1128
    return NULL;
1129
  }
1130
520.1.22 by Brian Aker
Second pass of thd cleanup
1131
  return create(session);
1 by brian
clean slate
1132
}
1133
1134
1135
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1136
Create_func_arg1::create(Session *session, LEX_STRING name, List<Item> *item_list)
1 by brian
clean slate
1137
{
1138
  int arg_count= 0;
1139
1140
  if (item_list)
2183.2.17 by Olaf van der Spek
Use List::size()
1141
    arg_count= item_list->size();
1 by brian
clean slate
1142
1143
  if (arg_count != 1)
1144
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1145
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1146
    return NULL;
1147
  }
1148
1149
  Item *param_1= item_list->pop();
1150
1151
  if (! param_1->is_autogenerated_name)
1152
  {
1153
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1154
    return NULL;
1155
  }
1156
520.1.22 by Brian Aker
Second pass of thd cleanup
1157
  return create(session, param_1);
1 by brian
clean slate
1158
}
1159
1160
1161
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1162
Create_func_arg2::create(Session *session, LEX_STRING name, List<Item> *item_list)
1 by brian
clean slate
1163
{
1164
  int arg_count= 0;
1165
1166
  if (item_list)
2183.2.17 by Olaf van der Spek
Use List::size()
1167
    arg_count= item_list->size();
1 by brian
clean slate
1168
1169
  if (arg_count != 2)
1170
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1171
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1172
    return NULL;
1173
  }
1174
1175
  Item *param_1= item_list->pop();
1176
  Item *param_2= item_list->pop();
1177
1178
  if (   (! param_1->is_autogenerated_name)
1179
      || (! param_2->is_autogenerated_name))
1180
  {
1181
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1182
    return NULL;
1183
  }
1184
520.1.22 by Brian Aker
Second pass of thd cleanup
1185
  return create(session, param_1, param_2);
1 by brian
clean slate
1186
}
1187
1188
1189
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1190
Create_func_arg3::create(Session *session, LEX_STRING name, List<Item> *item_list)
1 by brian
clean slate
1191
{
1192
  int arg_count= 0;
1193
1194
  if (item_list)
2183.2.17 by Olaf van der Spek
Use List::size()
1195
    arg_count= item_list->size();
1 by brian
clean slate
1196
1197
  if (arg_count != 3)
1198
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1199
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1200
    return NULL;
1201
  }
1202
1203
  Item *param_1= item_list->pop();
1204
  Item *param_2= item_list->pop();
1205
  Item *param_3= item_list->pop();
1206
1207
  if (   (! param_1->is_autogenerated_name)
1208
      || (! param_2->is_autogenerated_name)
1209
      || (! param_3->is_autogenerated_name))
1210
  {
1211
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1212
    return NULL;
1213
  }
1214
520.1.22 by Brian Aker
Second pass of thd cleanup
1215
  return create(session, param_1, param_2, param_3);
1 by brian
clean slate
1216
}
1217
1218
Create_func_bin Create_func_bin::s_singleton;
1219
1220
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1221
Create_func_bin::create(Session *session, Item *arg1)
1 by brian
clean slate
1222
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1223
  Item *i10= new (session->mem_root) Item_int((int32_t) 10,2);
1224
  Item *i2= new (session->mem_root) Item_int((int32_t) 2,1);
1225
  return new (session->mem_root) Item_func_conv(arg1, i10, i2);
1 by brian
clean slate
1226
}
1227
1228
Create_func_concat Create_func_concat::s_singleton;
1229
1230
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1231
Create_func_concat::create_native(Session *session, LEX_STRING name,
1 by brian
clean slate
1232
                                  List<Item> *item_list)
1233
{
1234
  int arg_count= 0;
1235
1236
  if (item_list != NULL)
2183.2.17 by Olaf van der Spek
Use List::size()
1237
    arg_count= item_list->size();
1 by brian
clean slate
1238
1239
  if (arg_count < 1)
1240
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1241
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1242
    return NULL;
1243
  }
1244
1633.4.4 by Brian Aker
Remove more of current_session
1245
  return new (session->mem_root) Item_func_concat(*session, *item_list);
1 by brian
clean slate
1246
}
1247
1248
1249
Create_func_concat_ws Create_func_concat_ws::s_singleton;
1250
1251
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1252
Create_func_concat_ws::create_native(Session *session, LEX_STRING name,
1 by brian
clean slate
1253
                                     List<Item> *item_list)
1254
{
1255
  int arg_count= 0;
1256
1257
  if (item_list != NULL)
2183.2.17 by Olaf van der Spek
Use List::size()
1258
    arg_count= item_list->size();
1 by brian
clean slate
1259
1260
  /* "WS" stands for "With Separator": this function takes 2+ arguments */
1261
  if (arg_count < 2)
1262
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1263
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1264
    return NULL;
1265
  }
1266
1633.4.4 by Brian Aker
Remove more of current_session
1267
  return new (session->mem_root) Item_func_concat_ws(*session, *item_list);
1 by brian
clean slate
1268
}
1269
1270
1271
Create_func_conv Create_func_conv::s_singleton;
1272
1273
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1274
Create_func_conv::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
1 by brian
clean slate
1275
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1276
  return new (session->mem_root) Item_func_conv(arg1, arg2, arg3);
1 by brian
clean slate
1277
}
1278
1279
Create_func_cot Create_func_cot::s_singleton;
1280
1281
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1282
Create_func_cot::create(Session *session, Item *arg1)
1 by brian
clean slate
1283
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1284
  Item *i1= new (session->mem_root) Item_int((char*) "1", 1, 1);
1285
  Item *i2= new (session->mem_root) Item_func_tan(arg1);
1578.6.7 by Brian Aker
Removed current_session for use to find out current session divide value.
1286
  return new (session->mem_root) Item_func_div(session, i1, i2);
1 by brian
clean slate
1287
}
1288
1289
Create_func_date_format Create_func_date_format::s_singleton;
1290
1291
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1292
Create_func_date_format::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1293
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1294
  return new (session->mem_root) Item_func_date_format(arg1, arg2, 0);
1 by brian
clean slate
1295
}
1296
1297
1298
Create_func_datediff Create_func_datediff::s_singleton;
1299
1300
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1301
Create_func_datediff::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1302
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1303
  Item *i1= new (session->mem_root) Item_func_to_days(arg1);
1304
  Item *i2= new (session->mem_root) Item_func_to_days(arg2);
1 by brian
clean slate
1305
520.1.22 by Brian Aker
Second pass of thd cleanup
1306
  return new (session->mem_root) Item_func_minus(i1, i2);
1 by brian
clean slate
1307
}
1308
1309
1310
Create_func_dayname Create_func_dayname::s_singleton;
1311
1312
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1313
Create_func_dayname::create(Session *session, Item *arg1)
1 by brian
clean slate
1314
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1315
  return new (session->mem_root) Item_func_dayname(arg1);
1 by brian
clean slate
1316
}
1317
1318
1319
Create_func_dayofmonth Create_func_dayofmonth::s_singleton;
1320
1321
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1322
Create_func_dayofmonth::create(Session *session, Item *arg1)
1 by brian
clean slate
1323
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1324
  return new (session->mem_root) Item_func_dayofmonth(arg1);
1 by brian
clean slate
1325
}
1326
1327
1328
Create_func_dayofweek Create_func_dayofweek::s_singleton;
1329
1330
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1331
Create_func_dayofweek::create(Session *session, Item *arg1)
1 by brian
clean slate
1332
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1333
  return new (session->mem_root) Item_func_weekday(arg1, 1);
1 by brian
clean slate
1334
}
1335
1336
1337
Create_func_dayofyear Create_func_dayofyear::s_singleton;
1338
1339
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1340
Create_func_dayofyear::create(Session *session, Item *arg1)
1 by brian
clean slate
1341
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1342
  return new (session->mem_root) Item_func_dayofyear(arg1);
1 by brian
clean slate
1343
}
1344
1345
1346
Create_func_degrees Create_func_degrees::s_singleton;
1347
1348
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1349
Create_func_degrees::create(Session *session, Item *arg1)
1 by brian
clean slate
1350
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1351
  return new (session->mem_root) Item_func_units((char*) "degrees", arg1,
1 by brian
clean slate
1352
                                             180/M_PI, 0.0);
1353
}
1354
1355
Create_func_export_set Create_func_export_set::s_singleton;
1356
1357
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1358
Create_func_export_set::create_native(Session *session, LEX_STRING name,
1 by brian
clean slate
1359
                                      List<Item> *item_list)
1360
{
1361
  Item *func= NULL;
1362
  int arg_count= 0;
1363
1364
  if (item_list != NULL)
2183.2.17 by Olaf van der Spek
Use List::size()
1365
    arg_count= item_list->size();
1 by brian
clean slate
1366
1367
  switch (arg_count) {
1368
  case 3:
1369
  {
1370
    Item *param_1= item_list->pop();
1371
    Item *param_2= item_list->pop();
1372
    Item *param_3= item_list->pop();
520.1.22 by Brian Aker
Second pass of thd cleanup
1373
    func= new (session->mem_root) Item_func_export_set(param_1, param_2, param_3);
1 by brian
clean slate
1374
    break;
1375
  }
1376
  case 4:
1377
  {
1378
    Item *param_1= item_list->pop();
1379
    Item *param_2= item_list->pop();
1380
    Item *param_3= item_list->pop();
1381
    Item *param_4= item_list->pop();
520.1.22 by Brian Aker
Second pass of thd cleanup
1382
    func= new (session->mem_root) Item_func_export_set(param_1, param_2, param_3,
1 by brian
clean slate
1383
                                                   param_4);
1384
    break;
1385
  }
1386
  case 5:
1387
  {
1388
    Item *param_1= item_list->pop();
1389
    Item *param_2= item_list->pop();
1390
    Item *param_3= item_list->pop();
1391
    Item *param_4= item_list->pop();
1392
    Item *param_5= item_list->pop();
520.1.22 by Brian Aker
Second pass of thd cleanup
1393
    func= new (session->mem_root) Item_func_export_set(param_1, param_2, param_3,
1 by brian
clean slate
1394
                                                   param_4, param_5);
1395
    break;
1396
  }
1397
  default:
1398
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1399
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1400
    break;
1401
  }
1402
  }
1403
1404
  return func;
1405
}
1406
1407
1408
Create_func_field Create_func_field::s_singleton;
1409
1410
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1411
Create_func_field::create_native(Session *session, LEX_STRING name,
1 by brian
clean slate
1412
                                 List<Item> *item_list)
1413
{
1414
  int arg_count= 0;
1415
1416
  if (item_list != NULL)
2183.2.17 by Olaf van der Spek
Use List::size()
1417
    arg_count= item_list->size();
1 by brian
clean slate
1418
1419
  if (arg_count < 2)
1420
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1421
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1422
    return NULL;
1423
  }
1424
520.1.22 by Brian Aker
Second pass of thd cleanup
1425
  return new (session->mem_root) Item_func_field(*item_list);
1 by brian
clean slate
1426
}
1427
1428
1429
Create_func_find_in_set Create_func_find_in_set::s_singleton;
1430
1431
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1432
Create_func_find_in_set::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1433
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1434
  return new (session->mem_root) Item_func_find_in_set(arg1, arg2);
1 by brian
clean slate
1435
}
1436
1437
Create_func_found_rows Create_func_found_rows::s_singleton;
1438
1439
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1440
Create_func_found_rows::create(Session *session)
1 by brian
clean slate
1441
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1442
  return new (session->mem_root) Item_func_found_rows();
1 by brian
clean slate
1443
}
1444
1445
1446
Create_func_from_days Create_func_from_days::s_singleton;
1447
1448
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1449
Create_func_from_days::create(Session *session, Item *arg1)
1 by brian
clean slate
1450
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1451
  return new (session->mem_root) Item_func_from_days(arg1);
1 by brian
clean slate
1452
}
1453
1454
1455
Create_func_from_unixtime Create_func_from_unixtime::s_singleton;
1456
1457
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1458
Create_func_from_unixtime::create_native(Session *session, LEX_STRING name,
1 by brian
clean slate
1459
                                         List<Item> *item_list)
1460
{
1461
  Item *func= NULL;
1462
  int arg_count= 0;
1463
1464
  if (item_list != NULL)
2183.2.17 by Olaf van der Spek
Use List::size()
1465
    arg_count= item_list->size();
1 by brian
clean slate
1466
1467
  switch (arg_count) {
1468
  case 1:
1469
  {
1470
    Item *param_1= item_list->pop();
520.1.22 by Brian Aker
Second pass of thd cleanup
1471
    func= new (session->mem_root) Item_func_from_unixtime(param_1);
1 by brian
clean slate
1472
    break;
1473
  }
1474
  case 2:
1475
  {
1476
    Item *param_1= item_list->pop();
1477
    Item *param_2= item_list->pop();
520.1.22 by Brian Aker
Second pass of thd cleanup
1478
    Item *ut= new (session->mem_root) Item_func_from_unixtime(param_1);
1479
    func= new (session->mem_root) Item_func_date_format(ut, param_2, 0);
1 by brian
clean slate
1480
    break;
1481
  }
1482
  default:
1483
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1484
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1485
    break;
1486
  }
1487
  }
1488
1489
  return func;
1490
}
1491
1492
1493
Create_func_greatest Create_func_greatest::s_singleton;
1494
1495
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1496
Create_func_greatest::create_native(Session *session, LEX_STRING name,
1 by brian
clean slate
1497
                                    List<Item> *item_list)
1498
{
1499
  int arg_count= 0;
1500
1501
  if (item_list != NULL)
2183.2.17 by Olaf van der Spek
Use List::size()
1502
    arg_count= item_list->size();
1 by brian
clean slate
1503
1504
  if (arg_count < 2)
1505
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1506
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1507
    return NULL;
1508
  }
1509
520.1.22 by Brian Aker
Second pass of thd cleanup
1510
  return new (session->mem_root) Item_func_max(*item_list);
1 by brian
clean slate
1511
}
1512
1513
Create_func_ifnull Create_func_ifnull::s_singleton;
1514
1515
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1516
Create_func_ifnull::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1517
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1518
  return new (session->mem_root) Item_func_ifnull(arg1, arg2);
1 by brian
clean slate
1519
}
1520
1521
1522
Create_func_instr Create_func_instr::s_singleton;
1523
1524
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1525
Create_func_instr::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1526
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1527
  return new (session->mem_root) Item_func_locate(arg1, arg2);
1 by brian
clean slate
1528
}
1529
1530
1531
Create_func_isnull Create_func_isnull::s_singleton;
1532
1533
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1534
Create_func_isnull::create(Session *session, Item *arg1)
1 by brian
clean slate
1535
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1536
  return new (session->mem_root) Item_func_isnull(arg1);
1 by brian
clean slate
1537
}
1538
1539
1540
Create_func_last_day Create_func_last_day::s_singleton;
1541
1542
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1543
Create_func_last_day::create(Session *session, Item *arg1)
1 by brian
clean slate
1544
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1545
  return new (session->mem_root) Item_func_last_day(arg1);
1 by brian
clean slate
1546
}
1547
1548
1549
Create_func_last_insert_id Create_func_last_insert_id::s_singleton;
1550
1551
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1552
Create_func_last_insert_id::create_native(Session *session, LEX_STRING name,
1 by brian
clean slate
1553
                                          List<Item> *item_list)
1554
{
1555
  Item *func= NULL;
1556
  int arg_count= 0;
1557
1558
  if (item_list != NULL)
2183.2.17 by Olaf van der Spek
Use List::size()
1559
    arg_count= item_list->size();
1 by brian
clean slate
1560
1561
  switch (arg_count) {
1562
  case 0:
1563
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
1564
    func= new (session->mem_root) Item_func_last_insert_id();
1 by brian
clean slate
1565
    break;
1566
  }
1567
  case 1:
1568
  {
1569
    Item *param_1= item_list->pop();
520.1.22 by Brian Aker
Second pass of thd cleanup
1570
    func= new (session->mem_root) Item_func_last_insert_id(param_1);
1 by brian
clean slate
1571
    break;
1572
  }
1573
  default:
1574
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1575
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1576
    break;
1577
  }
1578
  }
1579
1580
  return func;
1581
}
1582
1583
1584
Create_func_lcase Create_func_lcase::s_singleton;
1585
1586
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1587
Create_func_lcase::create(Session *session, Item *arg1)
1 by brian
clean slate
1588
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1589
  return new (session->mem_root) Item_func_lcase(arg1);
1 by brian
clean slate
1590
}
1591
1592
1593
Create_func_least Create_func_least::s_singleton;
1594
1595
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1596
Create_func_least::create_native(Session *session, LEX_STRING name,
1 by brian
clean slate
1597
                                 List<Item> *item_list)
1598
{
1599
  int arg_count= 0;
1600
1601
  if (item_list != NULL)
2183.2.17 by Olaf van der Spek
Use List::size()
1602
    arg_count= item_list->size();
1 by brian
clean slate
1603
1604
  if (arg_count < 2)
1605
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1606
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1607
    return NULL;
1608
  }
1609
520.1.22 by Brian Aker
Second pass of thd cleanup
1610
  return new (session->mem_root) Item_func_min(*item_list);
1 by brian
clean slate
1611
}
1612
1613
Create_func_load_file Create_func_load_file::s_singleton;
1614
1615
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1616
Create_func_load_file::create(Session *session, Item *arg1)
1 by brian
clean slate
1617
{
1633.4.6 by Brian Aker
More current_session issues.
1618
  return new (session->mem_root) Item_load_file(*session, arg1);
1 by brian
clean slate
1619
}
1620
1621
1622
Create_func_locate Create_func_locate::s_singleton;
1623
1624
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1625
Create_func_locate::create_native(Session *session, LEX_STRING name,
1 by brian
clean slate
1626
                                  List<Item> *item_list)
1627
{
1628
  Item *func= NULL;
1629
  int arg_count= 0;
1630
1631
  if (item_list != NULL)
2183.2.17 by Olaf van der Spek
Use List::size()
1632
    arg_count= item_list->size();
1 by brian
clean slate
1633
1634
  switch (arg_count) {
1635
  case 2:
1636
  {
1637
    Item *param_1= item_list->pop();
1638
    Item *param_2= item_list->pop();
1639
    /* Yes, parameters in that order : 2, 1 */
520.1.22 by Brian Aker
Second pass of thd cleanup
1640
    func= new (session->mem_root) Item_func_locate(param_2, param_1);
1 by brian
clean slate
1641
    break;
1642
  }
1643
  case 3:
1644
  {
1645
    Item *param_1= item_list->pop();
1646
    Item *param_2= item_list->pop();
1647
    Item *param_3= item_list->pop();
1648
    /* Yes, parameters in that order : 2, 1, 3 */
520.1.22 by Brian Aker
Second pass of thd cleanup
1649
    func= new (session->mem_root) Item_func_locate(param_2, param_1, param_3);
1 by brian
clean slate
1650
    break;
1651
  }
1652
  default:
1653
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1654
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1655
    break;
1656
  }
1657
  }
1658
1659
  return func;
1660
}
1661
1662
Create_func_lpad Create_func_lpad::s_singleton;
1663
1664
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1665
Create_func_lpad::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
1 by brian
clean slate
1666
{
1633.4.6 by Brian Aker
More current_session issues.
1667
  return new (session->mem_root) Item_func_lpad(*session, arg1, arg2, arg3);
1 by brian
clean slate
1668
}
1669
1670
1671
Create_func_ltrim Create_func_ltrim::s_singleton;
1672
1673
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1674
Create_func_ltrim::create(Session *session, Item *arg1)
1 by brian
clean slate
1675
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1676
  return new (session->mem_root) Item_func_ltrim(arg1);
1 by brian
clean slate
1677
}
1678
1679
1680
Create_func_makedate Create_func_makedate::s_singleton;
1681
1682
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1683
Create_func_makedate::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1684
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1685
  return new (session->mem_root) Item_func_makedate(arg1, arg2);
1 by brian
clean slate
1686
}
1687
1688
1689
Create_func_make_set Create_func_make_set::s_singleton;
1690
1691
Item*
1633.4.6 by Brian Aker
More current_session issues.
1692
Create_func_make_set::create_native(Session *session_arg, LEX_STRING name,
1 by brian
clean slate
1693
                                    List<Item> *item_list)
1694
{
1695
  int arg_count= 0;
1696
1697
  if (item_list != NULL)
2183.2.17 by Olaf van der Spek
Use List::size()
1698
    arg_count= item_list->size();
1 by brian
clean slate
1699
1700
  if (arg_count < 2)
1701
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1702
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1703
    return NULL;
1704
  }
1705
1706
  Item *param_1= item_list->pop();
1633.4.6 by Brian Aker
More current_session issues.
1707
  return new (session_arg->mem_root) Item_func_make_set(*session_arg, param_1, *item_list);
1 by brian
clean slate
1708
}
1709
1710
1711
Create_func_monthname Create_func_monthname::s_singleton;
1712
1713
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1714
Create_func_monthname::create(Session *session, Item *arg1)
1 by brian
clean slate
1715
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1716
  return new (session->mem_root) Item_func_monthname(arg1);
1 by brian
clean slate
1717
}
1718
1719
1720
Create_func_nullif Create_func_nullif::s_singleton;
1721
1722
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1723
Create_func_nullif::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1724
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1725
  return new (session->mem_root) Item_func_nullif(arg1, arg2);
1 by brian
clean slate
1726
}
1727
1728
1729
Create_func_oct Create_func_oct::s_singleton;
1730
1731
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1732
Create_func_oct::create(Session *session, Item *arg1)
1 by brian
clean slate
1733
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1734
  Item *i10= new (session->mem_root) Item_int((int32_t) 10,2);
1735
  Item *i8= new (session->mem_root) Item_int((int32_t) 8,1);
1736
  return new (session->mem_root) Item_func_conv(arg1, i10, i8);
1 by brian
clean slate
1737
}
1738
1739
Create_func_period_add Create_func_period_add::s_singleton;
1740
1741
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1742
Create_func_period_add::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1743
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1744
  return new (session->mem_root) Item_func_period_add(arg1, arg2);
1 by brian
clean slate
1745
}
1746
1747
1748
Create_func_period_diff Create_func_period_diff::s_singleton;
1749
1750
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1751
Create_func_period_diff::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1752
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1753
  return new (session->mem_root) Item_func_period_diff(arg1, arg2);
1 by brian
clean slate
1754
}
1755
1756
1757
Create_func_pi Create_func_pi::s_singleton;
1758
1759
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1760
Create_func_pi::create(Session *session)
1 by brian
clean slate
1761
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1762
  return new (session->mem_root) Item_static_float_func("pi()", M_PI, 6, 8);
1 by brian
clean slate
1763
}
1764
1765
Create_func_radians Create_func_radians::s_singleton;
1766
1767
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1768
Create_func_radians::create(Session *session, Item *arg1)
1 by brian
clean slate
1769
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1770
  return new (session->mem_root) Item_func_units((char*) "radians", arg1,
1 by brian
clean slate
1771
                                             M_PI/180, 0.0);
1772
}
1773
1774
Create_func_round Create_func_round::s_singleton;
1775
1776
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1777
Create_func_round::create_native(Session *session, LEX_STRING name,
1 by brian
clean slate
1778
                                 List<Item> *item_list)
1779
{
1780
  Item *func= NULL;
1781
  int arg_count= 0;
1782
1783
  if (item_list != NULL)
2183.2.17 by Olaf van der Spek
Use List::size()
1784
    arg_count= item_list->size();
1 by brian
clean slate
1785
1786
  switch (arg_count) {
1787
  case 1:
1788
  {
1789
    Item *param_1= item_list->pop();
520.1.22 by Brian Aker
Second pass of thd cleanup
1790
    Item *i0 = new (session->mem_root) Item_int((char*)"0", 0, 1);
1791
    func= new (session->mem_root) Item_func_round(param_1, i0, 0);
1 by brian
clean slate
1792
    break;
1793
  }
1794
  case 2:
1795
  {
1796
    Item *param_1= item_list->pop();
1797
    Item *param_2= item_list->pop();
520.1.22 by Brian Aker
Second pass of thd cleanup
1798
    func= new (session->mem_root) Item_func_round(param_1, param_2, 0);
1 by brian
clean slate
1799
    break;
1800
  }
1801
  default:
1802
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1803
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1804
    break;
1805
  }
1806
  }
1807
1808
  return func;
1809
}
1810
1811
1812
Create_func_row_count Create_func_row_count::s_singleton;
1813
1814
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1815
Create_func_row_count::create(Session *session)
1 by brian
clean slate
1816
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1817
  return new (session->mem_root) Item_func_row_count();
1 by brian
clean slate
1818
}
1819
1820
1821
Create_func_rpad Create_func_rpad::s_singleton;
1822
1823
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1824
Create_func_rpad::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
1 by brian
clean slate
1825
{
1633.4.6 by Brian Aker
More current_session issues.
1826
  return new (session->mem_root) Item_func_rpad(*session, arg1, arg2, arg3);
1 by brian
clean slate
1827
}
1828
1829
1830
Create_func_rtrim Create_func_rtrim::s_singleton;
1831
1832
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1833
Create_func_rtrim::create(Session *session, Item *arg1)
1 by brian
clean slate
1834
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1835
  return new (session->mem_root) Item_func_rtrim(arg1);
1 by brian
clean slate
1836
}
1837
1838
1839
Create_func_sign Create_func_sign::s_singleton;
1840
1841
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1842
Create_func_sign::create(Session *session, Item *arg1)
1 by brian
clean slate
1843
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1844
  return new (session->mem_root) Item_func_sign(arg1);
1 by brian
clean slate
1845
}
1846
1847
Create_func_space Create_func_space::s_singleton;
1848
1849
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1850
Create_func_space::create(Session *session, Item *arg1)
1 by brian
clean slate
1851
{
1852
  /**
1853
    TODO: Fix Bug#23637
1854
    The parsed item tree should not depend on
520.1.22 by Brian Aker
Second pass of thd cleanup
1855
    <code>session->variables.collation_connection</code>.
1 by brian
clean slate
1856
  */
748 by Brian Aker
Removal of client side collation.
1857
  const CHARSET_INFO * const cs= session->variables.getCollation();
1 by brian
clean slate
1858
  Item *sp;
1859
1860
  if (cs->mbminlen > 1)
1861
  {
1816.3.1 by Brian Aker
Convert sql_string to use size_t (this should clean up ICC warnings).
1862
    size_t dummy_errors;
1022.1.3 by Brian Aker
Force UTF8 (remove the bits for looking for ascii).
1863
    sp= new (session->mem_root) Item_string("", 0, cs, DERIVATION_COERCIBLE);
383.1.12 by Brian Aker
Much closer toward UTF8 being around all the time...
1864
    sp->str_value.copy(" ", 1, &my_charset_utf8_general_ci, cs, &dummy_errors);
1 by brian
clean slate
1865
  }
1866
  else
1867
  {
1022.1.3 by Brian Aker
Force UTF8 (remove the bits for looking for ascii).
1868
    sp= new (session->mem_root) Item_string(" ", 1, cs, DERIVATION_COERCIBLE);
1 by brian
clean slate
1869
  }
1870
1633.4.5 by Brian Aker
More current_session.
1871
  return new (session->mem_root) Item_func_repeat(*session, sp, arg1);
1 by brian
clean slate
1872
}
1873
1874
Create_func_strcmp Create_func_strcmp::s_singleton;
1875
1876
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1877
Create_func_strcmp::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1878
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1879
  return new (session->mem_root) Item_func_strcmp(arg1, arg2);
1 by brian
clean slate
1880
}
1881
1882
1883
Create_func_tan Create_func_tan::s_singleton;
1884
1885
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1886
Create_func_tan::create(Session *session, Item *arg1)
1 by brian
clean slate
1887
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1888
  return new (session->mem_root) Item_func_tan(arg1);
1 by brian
clean slate
1889
}
1890
1891
1892
Create_func_time_format Create_func_time_format::s_singleton;
1893
1894
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1895
Create_func_time_format::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1896
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1897
  return new (session->mem_root) Item_func_date_format(arg1, arg2, 1);
1 by brian
clean slate
1898
}
1899
1900
Create_func_to_days Create_func_to_days::s_singleton;
1901
1902
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1903
Create_func_to_days::create(Session *session, Item *arg1)
1 by brian
clean slate
1904
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1905
  return new (session->mem_root) Item_func_to_days(arg1);
1 by brian
clean slate
1906
}
1907
1908
1909
Create_func_ucase Create_func_ucase::s_singleton;
1910
1911
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1912
Create_func_ucase::create(Session *session, Item *arg1)
1 by brian
clean slate
1913
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1914
  return new (session->mem_root) Item_func_ucase(arg1);
1 by brian
clean slate
1915
}
1916
1917
Create_func_unix_timestamp Create_func_unix_timestamp::s_singleton;
1918
1919
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1920
Create_func_unix_timestamp::create_native(Session *session, LEX_STRING name,
1 by brian
clean slate
1921
                                          List<Item> *item_list)
1922
{
1923
  Item *func= NULL;
1924
  int arg_count= 0;
1925
1926
  if (item_list != NULL)
2183.2.17 by Olaf van der Spek
Use List::size()
1927
    arg_count= item_list->size();
1 by brian
clean slate
1928
1929
  switch (arg_count) {
1930
  case 0:
1931
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
1932
    func= new (session->mem_root) Item_func_unix_timestamp();
1 by brian
clean slate
1933
    break;
1934
  }
1935
  case 1:
1936
  {
1937
    Item *param_1= item_list->pop();
520.1.22 by Brian Aker
Second pass of thd cleanup
1938
    func= new (session->mem_root) Item_func_unix_timestamp(param_1);
1 by brian
clean slate
1939
    break;
1940
  }
1941
  default:
1942
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1943
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1944
    break;
1945
  }
1946
  }
1947
1948
  return func;
1949
}
1950
1951
1952
Create_func_weekday Create_func_weekday::s_singleton;
1953
1954
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1955
Create_func_weekday::create(Session *session, Item *arg1)
1 by brian
clean slate
1956
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1957
  return new (session->mem_root) Item_func_weekday(arg1, 0);
1 by brian
clean slate
1958
}
1959
1960
struct Native_func_registry
1961
{
1962
  LEX_STRING name;
1963
  Create_func *builder;
1964
};
1965
1966
#define BUILDER(F) & F::s_singleton
1967
1968
/*
1969
  MySQL native functions.
1970
  MAINTAINER:
1971
  - Keep sorted for human lookup. At runtime, a hash table is used.
1972
  - keep 1 line per entry, it makes grep | sort easier
1973
*/
1974
1975
static Native_func_registry func_array[] =
1976
{
1977
  { { C_STRING_WITH_LEN("BIN") }, BUILDER(Create_func_bin)},
1978
  { { C_STRING_WITH_LEN("CONCAT") }, BUILDER(Create_func_concat)},
1979
  { { C_STRING_WITH_LEN("CONCAT_WS") }, BUILDER(Create_func_concat_ws)},
1980
  { { C_STRING_WITH_LEN("CONV") }, BUILDER(Create_func_conv)},
1981
  { { C_STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)},
1982
  { { C_STRING_WITH_LEN("DATEDIFF") }, BUILDER(Create_func_datediff)},
1983
  { { C_STRING_WITH_LEN("DATE_FORMAT") }, BUILDER(Create_func_date_format)},
1984
  { { C_STRING_WITH_LEN("DAYNAME") }, BUILDER(Create_func_dayname)},
1985
  { { C_STRING_WITH_LEN("DAYOFMONTH") }, BUILDER(Create_func_dayofmonth)},
1986
  { { C_STRING_WITH_LEN("DAYOFWEEK") }, BUILDER(Create_func_dayofweek)},
1987
  { { C_STRING_WITH_LEN("DAYOFYEAR") }, BUILDER(Create_func_dayofyear)},
1988
  { { C_STRING_WITH_LEN("DEGREES") }, BUILDER(Create_func_degrees)},
1989
  { { C_STRING_WITH_LEN("EXPORT_SET") }, BUILDER(Create_func_export_set)},
1990
  { { C_STRING_WITH_LEN("FIELD") }, BUILDER(Create_func_field)},
1991
  { { C_STRING_WITH_LEN("FIND_IN_SET") }, BUILDER(Create_func_find_in_set)},
1992
  { { C_STRING_WITH_LEN("FOUND_ROWS") }, BUILDER(Create_func_found_rows)},
1993
  { { C_STRING_WITH_LEN("FROM_DAYS") }, BUILDER(Create_func_from_days)},
1994
  { { C_STRING_WITH_LEN("FROM_UNIXTIME") }, BUILDER(Create_func_from_unixtime)},
1995
  { { C_STRING_WITH_LEN("GREATEST") }, BUILDER(Create_func_greatest)},
1996
  { { C_STRING_WITH_LEN("IFNULL") }, BUILDER(Create_func_ifnull)},
1997
  { { C_STRING_WITH_LEN("INSTR") }, BUILDER(Create_func_instr)},
1998
  { { C_STRING_WITH_LEN("ISNULL") }, BUILDER(Create_func_isnull)},
1999
  { { C_STRING_WITH_LEN("LAST_DAY") }, BUILDER(Create_func_last_day)},
2000
  { { C_STRING_WITH_LEN("LAST_INSERT_ID") }, BUILDER(Create_func_last_insert_id)},
2001
  { { C_STRING_WITH_LEN("LCASE") }, BUILDER(Create_func_lcase)},
2002
  { { C_STRING_WITH_LEN("LEAST") }, BUILDER(Create_func_least)},
2003
  { { C_STRING_WITH_LEN("LOAD_FILE") }, BUILDER(Create_func_load_file)},
2004
  { { C_STRING_WITH_LEN("LOCATE") }, BUILDER(Create_func_locate)},
2005
  { { C_STRING_WITH_LEN("LOWER") }, BUILDER(Create_func_lcase)},
2006
  { { C_STRING_WITH_LEN("LPAD") }, BUILDER(Create_func_lpad)},
2007
  { { C_STRING_WITH_LEN("LTRIM") }, BUILDER(Create_func_ltrim)},
2008
  { { C_STRING_WITH_LEN("MAKEDATE") }, BUILDER(Create_func_makedate)},
2009
  { { C_STRING_WITH_LEN("MAKE_SET") }, BUILDER(Create_func_make_set)},
2010
  { { C_STRING_WITH_LEN("MONTHNAME") }, BUILDER(Create_func_monthname)},
2011
  { { C_STRING_WITH_LEN("NULLIF") }, BUILDER(Create_func_nullif)},
2012
  { { C_STRING_WITH_LEN("OCT") }, BUILDER(Create_func_oct)},
2013
  { { C_STRING_WITH_LEN("PERIOD_ADD") }, BUILDER(Create_func_period_add)},
2014
  { { C_STRING_WITH_LEN("PERIOD_DIFF") }, BUILDER(Create_func_period_diff)},
2015
  { { C_STRING_WITH_LEN("PI") }, BUILDER(Create_func_pi)},
2016
  { { C_STRING_WITH_LEN("RADIANS") }, BUILDER(Create_func_radians)},
2017
  { { C_STRING_WITH_LEN("ROUND") }, BUILDER(Create_func_round)},
2018
  { { C_STRING_WITH_LEN("ROW_COUNT") }, BUILDER(Create_func_row_count)},
2019
  { { C_STRING_WITH_LEN("RPAD") }, BUILDER(Create_func_rpad)},
2020
  { { C_STRING_WITH_LEN("RTRIM") }, BUILDER(Create_func_rtrim)},
2021
  { { C_STRING_WITH_LEN("SIGN") }, BUILDER(Create_func_sign)},
2022
  { { C_STRING_WITH_LEN("SPACE") }, BUILDER(Create_func_space)},
2023
  { { C_STRING_WITH_LEN("STRCMP") }, BUILDER(Create_func_strcmp)},
2024
  { { C_STRING_WITH_LEN("TAN") }, BUILDER(Create_func_tan)},
2025
  { { C_STRING_WITH_LEN("TIME_FORMAT") }, BUILDER(Create_func_time_format)},
2026
  { { C_STRING_WITH_LEN("TO_DAYS") }, BUILDER(Create_func_to_days)},
2027
  { { C_STRING_WITH_LEN("UCASE") }, BUILDER(Create_func_ucase)},
2028
  { { C_STRING_WITH_LEN("UNIX_TIMESTAMP") }, BUILDER(Create_func_unix_timestamp)},
2029
  { { C_STRING_WITH_LEN("UPPER") }, BUILDER(Create_func_ucase)},
2030
  { { C_STRING_WITH_LEN("WEEKDAY") }, BUILDER(Create_func_weekday)},
2031
2032
  { {0, 0}, NULL}
2033
};
2034
2035
/*
2036
  Load the hash table for native functions.
2037
  Note: this code is not thread safe, and is intended to be used at server
2038
  startup only (before going multi-threaded)
2039
*/
2040
2041
int item_create_init()
2042
{
873.2.19 by Monty Taylor
Removed another HASH and another set of useless utf8 hashing.
2043
  string func_name;
2044
1 by brian
clean slate
2045
  Native_func_registry *func;
2046
  for (func= func_array; func->builder != NULL; func++)
2047
  {
873.2.19 by Monty Taylor
Removed another HASH and another set of useless utf8 hashing.
2048
    func_name.assign(func->name.str, func->name.length);
2049
2060 by Brian Aker
Added native functions into the function table.
2050
    FunctionContainer::getMap()[func_name]= func->builder;
51.1.19 by Jay Pipes
Removed/replace DBUG symbols
2051
  }
2052
873.2.19 by Monty Taylor
Removed another HASH and another set of useless utf8 hashing.
2053
  return 0;
2054
}
2055
1 by brian
clean slate
2056
2057
Create_func *
873.2.19 by Monty Taylor
Removed another HASH and another set of useless utf8 hashing.
2058
find_native_function_builder(LEX_STRING name)
1 by brian
clean slate
2059
{
2060
  Create_func *builder= NULL;
2061
873.2.19 by Monty Taylor
Removed another HASH and another set of useless utf8 hashing.
2062
  string func_name(name.str, name.length);
2063
2060 by Brian Aker
Added native functions into the function table.
2064
  FunctionContainer::Map::iterator func_iter=
1751.3.3 by Brian Aker
Shuffle native functions over to hash such that we have a specific container
2065
    FunctionContainer::getMap().find(func_name);
873.2.19 by Monty Taylor
Removed another HASH and another set of useless utf8 hashing.
2066
1751.3.3 by Brian Aker
Shuffle native functions over to hash such that we have a specific container
2067
  if (func_iter != FunctionContainer::getMap().end())
1 by brian
clean slate
2068
  {
2060 by Brian Aker
Added native functions into the function table.
2069
    builder= (*func_iter).second;
1 by brian
clean slate
2070
  }
2071
2072
  return builder;
2073
}
2074
2075
2076
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
2077
create_func_char_cast(Session *session, Item *a, int len, const CHARSET_INFO * const cs)
1 by brian
clean slate
2078
{
748 by Brian Aker
Removal of client side collation.
2079
  const CHARSET_INFO * const real_cs= (cs ? cs : session->variables.getCollation());
520.1.22 by Brian Aker
Second pass of thd cleanup
2080
  return new (session->mem_root) Item_char_typecast(a, len, real_cs);
1 by brian
clean slate
2081
}
2082
2083
2084
Item *
520.1.22 by Brian Aker
Second pass of thd cleanup
2085
create_func_cast(Session *session, Item *a, Cast_target cast_type,
1 by brian
clean slate
2086
                 const char *c_len, const char *c_dec,
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
2087
                 const CHARSET_INFO * const cs)
1 by brian
clean slate
2088
{
1999.4.8 by Brian Aker
Adding in time type.
2089
  Item *res= NULL;
290 by Brian Aker
Update for ulong change over.
2090
  uint32_t len;
482 by Brian Aker
Remove uint.
2091
  uint32_t dec;
1 by brian
clean slate
2092
2093
  switch (cast_type) {
2015.1.3 by Brian Aker
Merge in CAST operators for SIGNED/UNSIGNED
2094
  case ITEM_CAST_SIGNED:
2095
    res= new (session->mem_root) function::cast::Signed(a);
2096
    break;
2097
2098
  case ITEM_CAST_UNSIGNED:
2099
    res= new (session->mem_root) function::cast::Unsigned(a);
2100
    break;
2101
1 by brian
clean slate
2102
  case ITEM_CAST_BINARY:
520.1.22 by Brian Aker
Second pass of thd cleanup
2103
    res= new (session->mem_root) Item_func_binary(a);
1 by brian
clean slate
2104
    break;
1999.4.8 by Brian Aker
Adding in time type.
2105
2023.2.4 by Brian Aker
Merge in cast() for BOOLEAN.
2106
  case ITEM_CAST_BOOLEAN:
2107
    res= new (session->mem_root) function::cast::Boolean(a);
2108
    break;
2109
1999.4.8 by Brian Aker
Adding in time type.
2110
  case ITEM_CAST_TIME:
2111
    res= new (session->mem_root) function::cast::Time(a);
2112
    break;
2113
1 by brian
clean slate
2114
  case ITEM_CAST_DATE:
520.1.22 by Brian Aker
Second pass of thd cleanup
2115
    res= new (session->mem_root) Item_date_typecast(a);
1 by brian
clean slate
2116
    break;
1999.4.8 by Brian Aker
Adding in time type.
2117
1 by brian
clean slate
2118
  case ITEM_CAST_DATETIME:
520.1.22 by Brian Aker
Second pass of thd cleanup
2119
    res= new (session->mem_root) Item_datetime_typecast(a);
1 by brian
clean slate
2120
    break;
1999.4.8 by Brian Aker
Adding in time type.
2121
1 by brian
clean slate
2122
  case ITEM_CAST_DECIMAL:
1999.4.8 by Brian Aker
Adding in time type.
2123
    {
2124
      len= c_len ? atoi(c_len) : 0;
2125
      dec= c_dec ? atoi(c_dec) : 0;
2030.1.2 by Brian Aker
First pass in refactoring of the name of my_decimal.
2126
      class_decimal_trim(&len, &dec);
1999.4.8 by Brian Aker
Adding in time type.
2127
      if (len < dec)
2128
      {
2129
        my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
2130
        return 0;
2131
      }
2132
      if (len > DECIMAL_MAX_PRECISION)
2133
      {
2134
        my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name,
2135
                 DECIMAL_MAX_PRECISION);
2136
        return 0;
2137
      }
2138
      if (dec > DECIMAL_MAX_SCALE)
2139
      {
2140
        my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name,
2141
                 DECIMAL_MAX_SCALE);
2142
        return 0;
2143
      }
2144
      res= new (session->mem_root) Item_decimal_typecast(a, len, dec);
2145
      break;
2146
    }
1 by brian
clean slate
2147
  case ITEM_CAST_CHAR:
1999.4.8 by Brian Aker
Adding in time type.
2148
    {
2149
      len= c_len ? atoi(c_len) : -1;
2150
      res= create_func_char_cast(session, a, len, cs);
2151
      break;
2152
    }
2153
  }
2154
1 by brian
clean slate
2155
  return res;
2156
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2157
2158
} /* namespace drizzled */