~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>
2241.3.2 by Olaf van der Spek
Refactor Session::variables
27
#include <drizzled/system_variables.h>
1 by brian
clean slate
28
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
29
#include <drizzled/function_container.h>
1751.3.3 by Brian Aker
Shuffle native functions over to hash such that we have a specific container
30
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
31
#include <drizzled/function/str/binary.h>
32
#include <drizzled/function/str/concat.h>
33
#include <drizzled/function/str/conv.h>
34
#include <drizzled/function/str/export_set.h>
35
#include <drizzled/function/str/load_file.h>
36
#include <drizzled/function/str/make_set.h>
37
#include <drizzled/function/str/pad.h>
38
#include <drizzled/function/str/repeat.h>
39
#include <drizzled/function/str/str_conv.h>
40
#include <drizzled/function/str/trim.h>
642.1.12 by Lee
remove drizzled/item/strfunc.h, no longer needed
41
670.1.22 by Monty Taylor
Merged from Lee.
42
#include <drizzled/function/time/date_format.h>
43
#include <drizzled/function/time/dayname.h>
44
#include <drizzled/function/time/dayofmonth.h>
45
#include <drizzled/function/time/dayofyear.h>
46
#include <drizzled/function/time/from_unixtime.h>
47
#include <drizzled/function/time/from_days.h>
48
#include <drizzled/function/time/last_day.h>
49
#include <drizzled/function/time/makedate.h>
50
#include <drizzled/function/time/month.h>
51
#include <drizzled/function/time/period_add.h>
52
#include <drizzled/function/time/period_diff.h>
53
#include <drizzled/function/time/to_days.h>
54
#include <drizzled/function/time/typecast.h>
55
#include <drizzled/function/time/unix_timestamp.h>
56
#include <drizzled/function/time/weekday.h>
642.1.13 by Lee
remove drizzled/item/timefunc.h, no longer needed
57
584.4.7 by Monty Taylor
Removed a big bank of includes from item.h.
58
#include <drizzled/item/cmpfunc.h>
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
59
#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.
60
#include <drizzled/session.h>
584.4.7 by Monty Taylor
Removed a big bank of includes from item.h.
61
648 by Brian Aker
Fix for create to keep its include files (which speeds up recompiles).
62
/* Function declarations */
63
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
64
#include <drizzled/function/func.h>
65
#include <drizzled/function/additive_op.h>
642.1.30 by Lee
move math functions to drizzled/function/math directory
66
#include <drizzled/function/math/dec.h>
67
#include <drizzled/function/math/decimal_typecast.h>
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
68
#include <drizzled/function/field.h>
69
#include <drizzled/function/find_in_set.h>
70
#include <drizzled/function/found_rows.h>
71
#include <drizzled/function/get_system_var.h>
642.1.30 by Lee
move math functions to drizzled/function/math directory
72
#include <drizzled/function/math/int_val.h>
73
#include <drizzled/function/math/integer.h>
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
74
#include <drizzled/function/last_insert.h>
75
#include <drizzled/function/locate.h>
76
#include <drizzled/function/min_max.h>
77
#include <drizzled/function/num1.h>
78
#include <drizzled/function/num_op.h>
79
#include <drizzled/function/numhybrid.h>
642.1.30 by Lee
move math functions to drizzled/function/math directory
80
#include <drizzled/function/math/real.h>
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
81
#include <drizzled/function/row_count.h>
82
#include <drizzled/function/set_user_var.h>
83
#include <drizzled/function/sign.h>
642.1.30 by Lee
move math functions to drizzled/function/math directory
84
#include <drizzled/function/math/tan.h>
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
85
#include <drizzled/function/units.h>
648 by Brian Aker
Fix for create to keep its include files (which speeds up recompiles).
86
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
87
#include <drizzled/function/cast/boolean.h>
88
#include <drizzled/function/cast/signed.h>
89
#include <drizzled/function/cast/time.h>
90
#include <drizzled/function/cast/unsigned.h>
1999.4.8 by Brian Aker
Adding in time type.
91
873.2.19 by Monty Taylor
Removed another HASH and another set of useless utf8 hashing.
92
using namespace std;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
93
2241.3.2 by Olaf van der Spek
Refactor Session::variables
94
namespace drizzled {
648 by Brian Aker
Fix for create to keep its include files (which speeds up recompiles).
95
1 by brian
clean slate
96
/*
97
=============================================================================
98
  LOCAL DECLARATIONS
99
=============================================================================
100
*/
101
102
/**
103
  Adapter for native functions with a variable number of arguments.
104
  The main use of this class is to discard the following calls:
105
  <code>foo(expr1 AS name1, expr2 AS name2, ...)</code>
106
  which are syntactically correct (the syntax can refer to a UDF),
107
  but semantically invalid for native functions.
108
*/
109
2318.6.87 by Olaf van der Spek
Refactor
110
/**
111
  Checks if there are named parameters in a parameter list.
112
  The syntax to name parameters in a function call is as follow:
113
  <code>foo(expr AS named, expr named, expr AS "named", expr "named")</code>
114
  @param params The parameter list, can be null
115
  @return true if one or more parameter is named
116
*/
117
static bool has_named_parameters(List<Item>& params)
118
{
119
  List<Item>::iterator it(params.begin());
120
  while (Item* param= it++)
121
  {
122
    if (not param->is_autogenerated_name)
123
      return true;
124
  }
125
  return false;
126
}
127
1 by brian
clean slate
128
class Create_native_func : public Create_func
129
{
130
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
131
  virtual Item* create(Session* session, lex_string_t name, List<Item>* item_list)
2318.6.87 by Olaf van der Spek
Refactor
132
  {
133
    if (item_list && has_named_parameters(*item_list))
134
    {
135
      my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
136
      return NULL;
137
    }
138
    return create_native(session, name, item_list);
139
  }
1 by brian
clean slate
140
141
  /**
142
    Builder method, with no arguments.
520.1.22 by Brian Aker
Second pass of thd cleanup
143
    @param session The current thread
1 by brian
clean slate
144
    @param name The native function name
145
    @param item_list The function parameters, none of which are named
146
    @return An item representing the function call
147
  */
2371.1.2 by Brian Aker
Remove the typedef on lexkey
148
  virtual Item* create_native(Session*, lex_string_t name, List<Item>*) = 0;
1 by brian
clean slate
149
};
150
151
152
/**
153
  Adapter for functions that takes exactly zero arguments.
154
*/
155
156
class Create_func_arg0 : public Create_func
157
{
158
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
159
  virtual Item* create(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
160
161
  /**
162
    Builder method, with no arguments.
520.1.22 by Brian Aker
Second pass of thd cleanup
163
    @param session The current thread
1 by brian
clean slate
164
    @return An item representing the function call
165
  */
2318.6.83 by Olaf van der Spek
Refactor
166
  virtual Item* create(Session *session) = 0;
1 by brian
clean slate
167
};
168
169
170
/**
171
  Adapter for functions that takes exactly one argument.
172
*/
173
174
class Create_func_arg1 : public Create_func
175
{
176
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
177
  virtual Item* create(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
178
179
  /**
180
    Builder method, with one argument.
520.1.22 by Brian Aker
Second pass of thd cleanup
181
    @param session The current thread
1 by brian
clean slate
182
    @param arg1 The first argument of the function
183
    @return An item representing the function call
184
  */
2318.6.83 by Olaf van der Spek
Refactor
185
  virtual Item* create(Session *session, Item *arg1) = 0;
1 by brian
clean slate
186
};
187
188
189
/**
190
  Adapter for functions that takes exactly two arguments.
191
*/
192
193
class Create_func_arg2 : public Create_func
194
{
195
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
196
  virtual Item* create(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
197
198
  /**
199
    Builder method, with two arguments.
520.1.22 by Brian Aker
Second pass of thd cleanup
200
    @param session The current thread
1 by brian
clean slate
201
    @param arg1 The first argument of the function
202
    @param arg2 The second argument of the function
203
    @return An item representing the function call
204
  */
2318.6.83 by Olaf van der Spek
Refactor
205
  virtual Item* create(Session *session, Item *arg1, Item *arg2) = 0;
1 by brian
clean slate
206
};
207
208
209
/**
210
  Adapter for functions that takes exactly three arguments.
211
*/
212
213
class Create_func_arg3 : public Create_func
214
{
215
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
216
  virtual Item* create(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
217
218
  /**
219
    Builder method, with three arguments.
520.1.22 by Brian Aker
Second pass of thd cleanup
220
    @param session The current thread
1 by brian
clean slate
221
    @param arg1 The first argument of the function
222
    @param arg2 The second argument of the function
223
    @param arg3 The third argument of the function
224
    @return An item representing the function call
225
  */
2318.6.83 by Olaf van der Spek
Refactor
226
  virtual Item* create(Session *session, Item *arg1, Item *arg2, Item *arg3) = 0;
1 by brian
clean slate
227
};
228
229
230
/**
231
  Function builder for Stored Functions.
232
*/
233
234
/*
235
  Concrete functions builders (native functions).
236
  Please keep this list sorted in alphabetical order,
237
  it helps to compare code between versions, and helps with merges conflicts.
238
*/
239
240
241
class Create_func_bin : public Create_func_arg1
242
{
243
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
244
  using Create_func_arg1::create;
245
2318.6.83 by Olaf van der Spek
Refactor
246
  virtual Item* create(Session *session, Item *arg1);
1 by brian
clean slate
247
248
  static Create_func_bin s_singleton;
249
250
protected:
251
  Create_func_bin() {}
252
};
253
254
class Create_func_concat : public Create_native_func
255
{
256
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
257
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
258
259
  static Create_func_concat s_singleton;
260
261
protected:
262
  Create_func_concat() {}
263
};
264
265
266
class Create_func_concat_ws : public Create_native_func
267
{
268
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
269
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
270
271
  static Create_func_concat_ws s_singleton;
272
273
protected:
274
  Create_func_concat_ws() {}
275
};
276
277
278
class Create_func_conv : public Create_func_arg3
279
{
280
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
281
  using Create_func_arg3::create;
282
2318.6.84 by Olaf van der Spek
Refactor
283
  virtual Item* create(Session *session, Item *arg1, Item *arg2, Item *arg3)
284
  {
285
    return new (session->mem) Item_func_conv(arg1, arg2, arg3);
286
  }
1 by brian
clean slate
287
288
  static Create_func_conv s_singleton;
289
protected:
290
  Create_func_conv() {}
291
};
292
2318.6.84 by Olaf van der Spek
Refactor
293
Create_func_conv Create_func_conv::s_singleton;
294
1 by brian
clean slate
295
class Create_func_cot : public Create_func_arg1
296
{
297
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
298
  using Create_func_arg1::create;
299
2318.6.83 by Olaf van der Spek
Refactor
300
  virtual Item* create(Session *session, Item *arg1);
1 by brian
clean slate
301
302
  static Create_func_cot s_singleton;
303
304
protected:
305
  Create_func_cot() {}
306
};
307
308
class Create_func_date_format : public Create_func_arg2
309
{
310
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
311
  using Create_func_arg2::create;
312
2318.6.83 by Olaf van der Spek
Refactor
313
  virtual Item* create(Session *session, Item *arg1, Item *arg2)
314
  {
315
    return new (session->mem) Item_func_date_format(arg1, arg2, 0);
316
  }
1 by brian
clean slate
317
318
  static Create_func_date_format s_singleton;
319
protected:
320
  Create_func_date_format() {}
321
};
322
2318.6.83 by Olaf van der Spek
Refactor
323
Create_func_date_format Create_func_date_format::s_singleton;
1 by brian
clean slate
324
325
class Create_func_datediff : public Create_func_arg2
326
{
327
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
328
  using Create_func_arg2::create;
329
2318.6.83 by Olaf van der Spek
Refactor
330
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
331
332
  static Create_func_datediff s_singleton;
333
334
protected:
335
  Create_func_datediff() {}
336
};
337
338
339
class Create_func_dayname : public Create_func_arg1
340
{
341
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
342
  using Create_func_arg1::create;
343
2318.6.83 by Olaf van der Spek
Refactor
344
  virtual Item* create(Session *session, Item *arg1)
345
  {
346
    return new (session->mem) Item_func_dayname(arg1);
347
  }
1 by brian
clean slate
348
349
  static Create_func_dayname s_singleton;
350
351
protected:
352
  Create_func_dayname() {}
353
};
354
2318.6.83 by Olaf van der Spek
Refactor
355
Create_func_dayname Create_func_dayname::s_singleton;
1 by brian
clean slate
356
357
class Create_func_dayofmonth : public Create_func_arg1
358
{
359
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
360
  using Create_func_arg1::create;
361
2318.6.87 by Olaf van der Spek
Refactor
362
  virtual Item* create(Session *session, Item *arg1)
363
  {
364
    return new (session->mem) Item_func_dayofmonth(arg1);
365
  }
1 by brian
clean slate
366
367
  static Create_func_dayofmonth s_singleton;
368
protected:
369
  Create_func_dayofmonth() {}
370
};
371
2318.6.87 by Olaf van der Spek
Refactor
372
Create_func_dayofmonth Create_func_dayofmonth::s_singleton;
1 by brian
clean slate
373
374
class Create_func_dayofweek : public Create_func_arg1
375
{
376
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
377
  using Create_func_arg1::create;
378
2318.6.87 by Olaf van der Spek
Refactor
379
  virtual Item* create(Session *session, Item *arg1)
380
  {
381
    return new (session->mem) Item_func_weekday(arg1, 1);
382
  }
1 by brian
clean slate
383
384
  static Create_func_dayofweek s_singleton;
385
protected:
386
  Create_func_dayofweek() {}
387
};
388
2318.6.87 by Olaf van der Spek
Refactor
389
Create_func_dayofweek Create_func_dayofweek::s_singleton;
1 by brian
clean slate
390
391
class Create_func_dayofyear : public Create_func_arg1
392
{
393
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
394
  using Create_func_arg1::create;
395
2318.6.87 by Olaf van der Spek
Refactor
396
  virtual Item* create(Session *session, Item *arg1)
397
  {
398
    return new (session->mem) Item_func_dayofyear(arg1);
399
  }
1 by brian
clean slate
400
401
  static Create_func_dayofyear s_singleton;
402
protected:
403
  Create_func_dayofyear() {}
404
};
405
2318.6.87 by Olaf van der Spek
Refactor
406
Create_func_dayofyear Create_func_dayofyear::s_singleton;
1 by brian
clean slate
407
408
class Create_func_decode : public Create_func_arg2
409
{
410
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
411
  using Create_func_arg2::create;
412
2318.6.83 by Olaf van der Spek
Refactor
413
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
414
415
  static Create_func_decode s_singleton;
416
417
protected:
418
  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
2318.6.87 by Olaf van der Spek
Refactor
427
  virtual Item* create(Session *session, Item *arg1)
428
  {
429
    return new (session->mem) Item_func_units("degrees", arg1, 180/M_PI, 0.0);
430
  }
1 by brian
clean slate
431
432
  static Create_func_degrees s_singleton;
433
protected:
434
  Create_func_degrees() {}
435
};
436
2318.6.87 by Olaf van der Spek
Refactor
437
Create_func_degrees Create_func_degrees::s_singleton;
438
1 by brian
clean slate
439
class Create_func_export_set : public Create_native_func
440
{
1759.3.15 by Stewart Smith
move SQRT() function into math_functions plugin
441
1 by brian
clean slate
442
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
443
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
444
445
  static Create_func_export_set s_singleton;
446
447
protected:
448
  Create_func_export_set() {}
449
};
450
451
452
class Create_func_field : public Create_native_func
453
{
454
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
455
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
456
457
  static Create_func_field s_singleton;
458
459
protected:
460
  Create_func_field() {}
461
};
462
463
464
class Create_func_find_in_set : public Create_func_arg2
465
{
466
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
467
  using Create_func_arg2::create;
468
2318.6.83 by Olaf van der Spek
Refactor
469
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
470
471
  static Create_func_find_in_set s_singleton;
472
473
protected:
474
  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
2318.6.83 by Olaf van der Spek
Refactor
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
};
489
490
491
class Create_func_from_days : public Create_func_arg1
492
{
493
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
494
  using Create_func_arg1::create;
495
2318.6.83 by Olaf van der Spek
Refactor
496
  virtual Item* create(Session *session, Item *arg1);
1 by brian
clean slate
497
498
  static Create_func_from_days s_singleton;
499
500
protected:
501
  Create_func_from_days() {}
502
};
503
504
505
class Create_func_from_unixtime : public Create_native_func
506
{
507
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
508
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
509
510
  static Create_func_from_unixtime s_singleton;
511
512
protected:
513
  Create_func_from_unixtime() {}
514
};
515
516
517
class Create_func_greatest : public Create_native_func
518
{
519
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
520
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
521
522
  static Create_func_greatest s_singleton;
523
524
protected:
525
  Create_func_greatest() {}
526
};
527
528
529
class Create_func_ifnull : public Create_func_arg2
530
{
531
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
532
  using Create_func_arg2::create;
533
2318.6.83 by Olaf van der Spek
Refactor
534
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
535
536
  static Create_func_ifnull s_singleton;
537
538
protected:
539
  Create_func_ifnull() {}
540
};
541
542
543
class Create_func_instr : public Create_func_arg2
544
{
545
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
546
  using Create_func_arg2::create;
547
2318.6.83 by Olaf van der Spek
Refactor
548
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
549
550
  static Create_func_instr s_singleton;
551
552
protected:
553
  Create_func_instr() {}
554
};
555
556
557
class Create_func_isnull : public Create_func_arg1
558
{
559
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
560
  using Create_func_arg1::create;
561
2318.6.83 by Olaf van der Spek
Refactor
562
  virtual Item* create(Session *session, Item *arg1);
1 by brian
clean slate
563
564
  static Create_func_isnull s_singleton;
565
566
protected:
567
  Create_func_isnull() {}
568
};
569
570
571
class Create_func_last_day : public Create_func_arg1
572
{
573
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
574
  using Create_func_arg1::create;
575
2318.6.83 by Olaf van der Spek
Refactor
576
  virtual Item* create(Session *session, Item *arg1);
1 by brian
clean slate
577
578
  static Create_func_last_day s_singleton;
579
580
protected:
581
  Create_func_last_day() {}
582
};
583
584
585
class Create_func_last_insert_id : public Create_native_func
586
{
587
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
588
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
589
590
  static Create_func_last_insert_id s_singleton;
591
592
protected:
593
  Create_func_last_insert_id() {}
594
};
595
596
597
class Create_func_lcase : public Create_func_arg1
598
{
599
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
600
  using Create_func_arg1::create;
601
2318.6.83 by Olaf van der Spek
Refactor
602
  virtual Item* create(Session *session, Item *arg1);
1 by brian
clean slate
603
604
  static Create_func_lcase s_singleton;
605
606
protected:
607
  Create_func_lcase() {}
608
};
609
610
611
class Create_func_least : public Create_native_func
612
{
613
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
614
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
615
616
  static Create_func_least s_singleton;
617
618
protected:
619
  Create_func_least() {}
620
};
621
622
class Create_func_load_file : public Create_func_arg1
623
{
624
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
625
  using Create_func_arg1::create;
626
2318.6.83 by Olaf van der Spek
Refactor
627
  virtual Item* create(Session *session, Item *arg1);
1 by brian
clean slate
628
629
  static Create_func_load_file s_singleton;
630
631
protected:
632
  Create_func_load_file() {}
633
};
634
635
636
class Create_func_locate : public Create_native_func
637
{
638
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
639
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
640
641
  static Create_func_locate s_singleton;
642
643
protected:
644
  Create_func_locate() {}
645
};
646
647
648
class Create_func_lpad : public Create_func_arg3
649
{
650
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
651
  using Create_func_arg3::create;
652
2318.6.86 by Olaf van der Spek
Refactor
653
  virtual Item* create(Session *session, Item *arg1, Item *arg2, Item *arg3)
654
  {
655
    return new (session->mem) Item_func_lpad(*session, arg1, arg2, arg3);
656
  }
1 by brian
clean slate
657
658
  static Create_func_lpad s_singleton;
659
protected:
660
  Create_func_lpad() {}
661
};
662
2318.6.86 by Olaf van der Spek
Refactor
663
Create_func_lpad Create_func_lpad::s_singleton;
1 by brian
clean slate
664
665
class Create_func_ltrim : public Create_func_arg1
666
{
667
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
668
  using Create_func_arg1::create;
669
2318.6.86 by Olaf van der Spek
Refactor
670
  virtual Item* create(Session *session, Item *arg1)
671
  {
672
    return new (session->mem) Item_func_ltrim(arg1);
673
  }
1 by brian
clean slate
674
675
  static Create_func_ltrim s_singleton;
676
protected:
677
  Create_func_ltrim() {}
678
};
679
2318.6.86 by Olaf van der Spek
Refactor
680
Create_func_ltrim Create_func_ltrim::s_singleton;
1 by brian
clean slate
681
682
class Create_func_makedate : public Create_func_arg2
683
{
684
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
685
  using Create_func_arg2::create;
686
2318.6.86 by Olaf van der Spek
Refactor
687
  virtual Item* create(Session *session, Item *arg1, Item *arg2)
688
  {
689
    return new (session->mem) Item_func_makedate(arg1, arg2);
690
  }
1 by brian
clean slate
691
692
  static Create_func_makedate s_singleton;
693
protected:
694
  Create_func_makedate() {}
695
};
696
2318.6.86 by Olaf van der Spek
Refactor
697
Create_func_makedate Create_func_makedate::s_singleton;
698
1 by brian
clean slate
699
class Create_func_make_set : public Create_native_func
700
{
701
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
702
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
703
704
  static Create_func_make_set s_singleton;
705
706
protected:
707
  Create_func_make_set() {}
708
};
709
710
711
class Create_func_monthname : public Create_func_arg1
712
{
713
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
714
  using Create_func_arg1::create;
715
2318.6.89 by Olaf van der Spek
Refactor
716
  virtual Item* create(Session *session, Item *arg1)
717
  {
718
    return new (session->mem) Item_func_monthname(arg1);
719
  }
1 by brian
clean slate
720
721
  static Create_func_monthname s_singleton;
722
protected:
723
  Create_func_monthname() {}
724
};
725
2318.6.89 by Olaf van der Spek
Refactor
726
Create_func_monthname Create_func_monthname::s_singleton;
1 by brian
clean slate
727
728
class Create_func_name_const : public Create_func_arg2
729
{
730
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
731
  using Create_func_arg2::create;
732
2318.6.83 by Olaf van der Spek
Refactor
733
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
734
735
  static Create_func_name_const s_singleton;
736
737
protected:
738
  Create_func_name_const() {}
739
};
740
741
742
class Create_func_nullif : public Create_func_arg2
743
{
744
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
745
  using Create_func_arg2::create;
746
2318.6.89 by Olaf van der Spek
Refactor
747
  virtual Item* create(Session *session, Item *arg1, Item *arg2)
748
  {
749
    return new (session->mem) Item_func_nullif(arg1, arg2);
750
  }
1 by brian
clean slate
751
752
  static Create_func_nullif s_singleton;
753
protected:
754
  Create_func_nullif() {}
755
};
756
2318.6.89 by Olaf van der Spek
Refactor
757
Create_func_nullif Create_func_nullif::s_singleton;
1 by brian
clean slate
758
759
class Create_func_oct : public Create_func_arg1
760
{
761
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
762
  using Create_func_arg1::create;
763
2318.6.83 by Olaf van der Spek
Refactor
764
  virtual Item* create(Session *session, Item *arg1);
1 by brian
clean slate
765
766
  static Create_func_oct s_singleton;
767
768
protected:
769
  Create_func_oct() {}
770
};
771
772
class Create_func_period_add : public Create_func_arg2
773
{
774
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
775
  using Create_func_arg2::create;
776
2318.6.83 by Olaf van der Spek
Refactor
777
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
778
779
  static Create_func_period_add s_singleton;
780
781
protected:
782
  Create_func_period_add() {}
783
};
784
785
786
class Create_func_period_diff : public Create_func_arg2
787
{
788
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
789
  using Create_func_arg2::create;
790
2318.6.83 by Olaf van der Spek
Refactor
791
  virtual Item* create(Session *session, Item *arg1, Item *arg2);
1 by brian
clean slate
792
793
  static Create_func_period_diff s_singleton;
794
795
protected:
796
  Create_func_period_diff() {}
797
};
798
799
800
class Create_func_pi : public Create_func_arg0
801
{
802
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
803
  using Create_func_arg0::create;
804
2318.6.83 by Olaf van der Spek
Refactor
805
  virtual Item* create(Session *session);
1 by brian
clean slate
806
807
  static Create_func_pi s_singleton;
808
809
protected:
810
  Create_func_pi() {}
811
};
812
813
class Create_func_radians : public Create_func_arg1
814
{
815
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
816
  using Create_func_arg1::create;
817
2318.6.83 by Olaf van der Spek
Refactor
818
  virtual Item* create(Session *session, Item *arg1);
1 by brian
clean slate
819
820
  static Create_func_radians s_singleton;
821
protected:
822
  Create_func_radians() {}
823
};
824
825
826
class Create_func_round : public Create_native_func
827
{
828
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
829
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
830
831
  static Create_func_round s_singleton;
832
protected:
833
  Create_func_round() {}
834
};
835
836
837
class Create_func_row_count : public Create_func_arg0
838
{
839
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
840
  using Create_func_arg0::create;
841
2318.6.88 by Olaf van der Spek
Refactor
842
  virtual Item* create(Session *session)
843
  {
844
    return new (session->mem) Item_func_row_count();
845
  }
1 by brian
clean slate
846
847
  static Create_func_row_count s_singleton;
848
protected:
849
  Create_func_row_count() {}
850
};
851
2318.6.88 by Olaf van der Spek
Refactor
852
Create_func_row_count Create_func_row_count::s_singleton;
1 by brian
clean slate
853
854
class Create_func_rpad : public Create_func_arg3
855
{
856
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
857
  using Create_func_arg3::create;
858
2318.6.88 by Olaf van der Spek
Refactor
859
  virtual Item* create(Session *session, Item *arg1, Item *arg2, Item *arg3)
860
  {
861
    return new (session->mem) Item_func_rpad(*session, arg1, arg2, arg3);
862
  }
1 by brian
clean slate
863
864
  static Create_func_rpad s_singleton;
865
protected:
866
  Create_func_rpad() {}
867
};
868
2318.6.88 by Olaf van der Spek
Refactor
869
Create_func_rpad Create_func_rpad::s_singleton;
1 by brian
clean slate
870
871
class Create_func_rtrim : public Create_func_arg1
872
{
873
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
874
  using Create_func_arg1::create;
875
2318.6.88 by Olaf van der Spek
Refactor
876
  virtual Item* create(Session *session, Item *arg1)
877
  {
878
    return new (session->mem) Item_func_rtrim(arg1);
879
  }
1 by brian
clean slate
880
881
  static Create_func_rtrim s_singleton;
882
883
protected:
884
  Create_func_rtrim() {}
885
};
886
2318.6.89 by Olaf van der Spek
Refactor
887
Create_func_rtrim Create_func_rtrim::s_singleton;
888
1 by brian
clean slate
889
class Create_func_sign : public Create_func_arg1
890
{
891
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
892
  using Create_func_arg1::create;
893
2318.6.88 by Olaf van der Spek
Refactor
894
  virtual Item* create(Session *session, Item *arg1)
895
  {
896
    return new (session->mem) Item_func_sign(arg1);
897
  }
1 by brian
clean slate
898
899
  static Create_func_sign s_singleton;
900
protected:
901
  Create_func_sign() {}
902
};
903
2318.6.88 by Olaf van der Spek
Refactor
904
Create_func_sign Create_func_sign::s_singleton;
905
1 by brian
clean slate
906
class Create_func_space : public Create_func_arg1
907
{
908
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
909
  using Create_func_arg1::create;
910
2318.6.83 by Olaf van der Spek
Refactor
911
  virtual Item* create(Session *session, Item *arg1);
1 by brian
clean slate
912
913
  static Create_func_space s_singleton;
914
protected:
915
  Create_func_space() {}
916
};
917
918
class Create_func_strcmp : public Create_func_arg2
919
{
920
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
921
  using Create_func_arg2::create;
922
2318.6.89 by Olaf van der Spek
Refactor
923
  virtual Item* create(Session *session, Item *arg1, Item *arg2)
924
  {
925
    return new (session->mem) Item_func_strcmp(arg1, arg2);
926
  }
927
  
1 by brian
clean slate
928
  static Create_func_strcmp s_singleton;
929
protected:
930
  Create_func_strcmp() {}
931
};
932
2318.6.89 by Olaf van der Spek
Refactor
933
Create_func_strcmp Create_func_strcmp::s_singleton;
1 by brian
clean slate
934
935
class Create_func_tan : public Create_func_arg1
936
{
937
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
938
  using Create_func_arg1::create;
939
2318.6.89 by Olaf van der Spek
Refactor
940
  virtual Item* create(Session *session, Item *arg1)
941
  {
942
    return new (session->mem) Item_func_tan(arg1);
943
  }
1 by brian
clean slate
944
945
  static Create_func_tan s_singleton;
946
protected:
947
  Create_func_tan() {}
948
};
949
2318.6.89 by Olaf van der Spek
Refactor
950
Create_func_tan Create_func_tan::s_singleton;
1 by brian
clean slate
951
952
class Create_func_time_format : public Create_func_arg2
953
{
954
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
955
  using Create_func_arg2::create;
956
2318.6.89 by Olaf van der Spek
Refactor
957
  virtual Item* create(Session *session, Item *arg1, Item *arg2)
958
  {
959
    return new (session->mem) Item_func_date_format(arg1, arg2, 1);
960
  }
1 by brian
clean slate
961
962
  static Create_func_time_format s_singleton;
963
protected:
964
  Create_func_time_format() {}
965
};
966
2318.6.89 by Olaf van der Spek
Refactor
967
Create_func_time_format Create_func_time_format::s_singleton;
1 by brian
clean slate
968
969
class Create_func_to_days : public Create_func_arg1
970
{
971
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
972
  using Create_func_arg1::create;
973
2318.6.89 by Olaf van der Spek
Refactor
974
  virtual Item* create(Session *session, Item *arg1)
975
  {
976
    return new (session->mem) Item_func_to_days(arg1);
977
  }
1 by brian
clean slate
978
979
  static Create_func_to_days s_singleton;
980
protected:
981
  Create_func_to_days() {}
982
};
983
2318.6.89 by Olaf van der Spek
Refactor
984
Create_func_to_days Create_func_to_days::s_singleton;
1 by brian
clean slate
985
986
class Create_func_ucase : public Create_func_arg1
987
{
988
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
989
  using Create_func_arg1::create;
990
2318.6.89 by Olaf van der Spek
Refactor
991
  virtual Item* create(Session *session, Item *arg1)
992
  {
993
    return new (session->mem) Item_func_ucase(arg1);
994
  }
1 by brian
clean slate
995
996
  static Create_func_ucase s_singleton;
997
protected:
998
  Create_func_ucase() {}
999
};
1000
2318.6.89 by Olaf van der Spek
Refactor
1001
Create_func_ucase Create_func_ucase::s_singleton;
1 by brian
clean slate
1002
1003
class Create_func_unix_timestamp : public Create_native_func
1004
{
1005
public:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1006
  virtual Item* create_native(Session *session, lex_string_t name, List<Item> *item_list);
1 by brian
clean slate
1007
1008
  static Create_func_unix_timestamp s_singleton;
1009
protected:
1010
  Create_func_unix_timestamp() {}
1011
};
1012
1013
1014
class Create_func_weekday : public Create_func_arg1
1015
{
1016
public:
892.1.1 by Monty Taylor
Fixed virtual overload warnings.
1017
  using Create_func_arg1::create;
1018
2318.6.86 by Olaf van der Spek
Refactor
1019
  virtual Item* create(Session *session, Item *arg1)
1020
  {
1021
    return new (session->mem) Item_func_weekday(arg1, 0);
1022
  }
1 by brian
clean slate
1023
1024
  static Create_func_weekday s_singleton;
1025
protected:
1026
  Create_func_weekday() {}
1027
};
1028
2318.6.86 by Olaf van der Spek
Refactor
1029
Create_func_weekday Create_func_weekday::s_singleton;
1030
1 by brian
clean slate
1031
/*
1032
=============================================================================
1033
  IMPLEMENTATION
1034
=============================================================================
1035
*/
1036
1037
Create_udf_func Create_udf_func::s_singleton;
1038
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1039
Item* Create_udf_func::create(Session *session, lex_string_t name, List<Item> *item_list)
1 by brian
clean slate
1040
{
2318.6.86 by Olaf van der Spek
Refactor
1041
  return create(session, plugin::Function::get(std::string(name.str, name.length)), item_list);
1042
}
1043
2318.6.87 by Olaf van der Spek
Refactor
1044
Item* Create_udf_func::create(Session *session, const plugin::Function *udf, List<Item> *item_list)
2318.6.86 by Olaf van der Spek
Refactor
1045
{
51.1.19 by Jay Pipes
Removed/replace DBUG symbols
1046
  assert(udf);
2318.6.83 by Olaf van der Spek
Refactor
1047
  int arg_count= item_list ? item_list->size() : 0;
2318.6.85 by Olaf van der Spek
Refactor
1048
  Item_func* func= (*udf)(&session->mem);
2318.6.86 by Olaf van der Spek
Refactor
1049
  if (!func->check_argument_count(arg_count))
997.8.1 by Stewart Smith
Add check for argument numbers for UDFs. Fix crc32 and md5
1050
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1051
    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
1052
    return NULL;
1053
  }
2318.6.85 by Olaf van der Spek
Refactor
1054
  if (item_list)
997.8.1 by Stewart Smith
Add check for argument numbers for UDFs. Fix crc32 and md5
1055
    func->set_arguments(*item_list);
1 by brian
clean slate
1056
  return func;
1057
}
1058
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1059
Item* Create_func_arg0::create(Session *session, lex_string_t name, List<Item> *item_list)
2318.6.87 by Olaf van der Spek
Refactor
1060
{
1061
  if (item_list && item_list->size())
1 by brian
clean slate
1062
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1063
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1064
    return NULL;
1065
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
1066
  return create(session);
1 by brian
clean slate
1067
}
1068
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1069
Item* Create_func_arg1::create(Session *session, lex_string_t name, List<Item> *item_list)
1 by brian
clean slate
1070
{
2318.6.83 by Olaf van der Spek
Refactor
1071
  int arg_count= item_list ? item_list->size() : 0;
1 by brian
clean slate
1072
  if (arg_count != 1)
1073
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1074
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1075
    return NULL;
1076
  }
1077
1078
  Item *param_1= item_list->pop();
1079
1080
  if (! param_1->is_autogenerated_name)
1081
  {
1082
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1083
    return NULL;
1084
  }
1085
520.1.22 by Brian Aker
Second pass of thd cleanup
1086
  return create(session, param_1);
1 by brian
clean slate
1087
}
1088
1089
1090
Item*
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1091
Create_func_arg2::create(Session *session, lex_string_t name, List<Item> *item_list)
1 by brian
clean slate
1092
{
2318.6.83 by Olaf van der Spek
Refactor
1093
  int arg_count= item_list ? item_list->size() : 0;
1 by brian
clean slate
1094
  if (arg_count != 2)
1095
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1096
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1097
    return NULL;
1098
  }
1099
1100
  Item *param_1= item_list->pop();
1101
  Item *param_2= item_list->pop();
1102
1103
  if (   (! param_1->is_autogenerated_name)
1104
      || (! param_2->is_autogenerated_name))
1105
  {
1106
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1107
    return NULL;
1108
  }
1109
520.1.22 by Brian Aker
Second pass of thd cleanup
1110
  return create(session, param_1, param_2);
1 by brian
clean slate
1111
}
1112
1113
1114
Item*
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1115
Create_func_arg3::create(Session *session, lex_string_t name, List<Item> *item_list)
1 by brian
clean slate
1116
{
2318.6.83 by Olaf van der Spek
Refactor
1117
  int arg_count= item_list ? item_list->size() : 0;
1 by brian
clean slate
1118
  if (arg_count != 3)
1119
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1120
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1121
    return NULL;
1122
  }
1123
1124
  Item *param_1= item_list->pop();
1125
  Item *param_2= item_list->pop();
1126
  Item *param_3= item_list->pop();
1127
1128
  if (   (! param_1->is_autogenerated_name)
1129
      || (! param_2->is_autogenerated_name)
1130
      || (! param_3->is_autogenerated_name))
1131
  {
1132
    my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
1133
    return NULL;
1134
  }
1135
520.1.22 by Brian Aker
Second pass of thd cleanup
1136
  return create(session, param_1, param_2, param_3);
1 by brian
clean slate
1137
}
1138
1139
Create_func_bin Create_func_bin::s_singleton;
1140
1141
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1142
Create_func_bin::create(Session *session, Item *arg1)
1 by brian
clean slate
1143
{
2318.6.82 by Olaf van der Spek
Refactor
1144
  Item *i10= new (session->mem) Item_int(10, 2);
1145
  Item *i2= new (session->mem) Item_int(2, 1);
2318.6.81 by Olaf van der Spek
Refactor
1146
  return new (session->mem) Item_func_conv(arg1, i10, i2);
1 by brian
clean slate
1147
}
1148
1149
Create_func_concat Create_func_concat::s_singleton;
1150
1151
Item*
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1152
Create_func_concat::create_native(Session *session, lex_string_t name, List<Item> *item_list)
1 by brian
clean slate
1153
{
2318.6.83 by Olaf van der Spek
Refactor
1154
  int arg_count= item_list ? item_list->size() : 0;
1 by brian
clean slate
1155
  if (arg_count < 1)
1156
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1157
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1158
    return NULL;
1159
  }
1160
2318.6.81 by Olaf van der Spek
Refactor
1161
  return new (session->mem) Item_func_concat(*session, *item_list);
1 by brian
clean slate
1162
}
1163
1164
1165
Create_func_concat_ws Create_func_concat_ws::s_singleton;
1166
1167
Item*
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1168
Create_func_concat_ws::create_native(Session *session, lex_string_t name,
1 by brian
clean slate
1169
                                     List<Item> *item_list)
1170
{
2318.6.83 by Olaf van der Spek
Refactor
1171
  int arg_count= item_list ? item_list->size() : 0;
1 by brian
clean slate
1172
  /* "WS" stands for "With Separator": this function takes 2+ arguments */
1173
  if (arg_count < 2)
1174
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1175
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1176
    return NULL;
1177
  }
1178
2318.6.81 by Olaf van der Spek
Refactor
1179
  return new (session->mem) Item_func_concat_ws(*session, *item_list);
1 by brian
clean slate
1180
}
1181
1182
Create_func_cot Create_func_cot::s_singleton;
1183
1184
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1185
Create_func_cot::create(Session *session, Item *arg1)
1 by brian
clean slate
1186
{
2318.6.82 by Olaf van der Spek
Refactor
1187
  Item *i1= new (session->mem) Item_int("1", 1, 1);
2318.6.81 by Olaf van der Spek
Refactor
1188
  Item *i2= new (session->mem) Item_func_tan(arg1);
1189
  return new (session->mem) Item_func_div(session, i1, i2);
1 by brian
clean slate
1190
}
1191
1192
Create_func_datediff Create_func_datediff::s_singleton;
1193
1194
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1195
Create_func_datediff::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1196
{
2318.6.81 by Olaf van der Spek
Refactor
1197
  Item *i1= new (session->mem) Item_func_to_days(arg1);
1198
  Item *i2= new (session->mem) Item_func_to_days(arg2);
1199
  return new (session->mem) Item_func_minus(i1, i2);
1 by brian
clean slate
1200
}
1201
1202
Create_func_export_set Create_func_export_set::s_singleton;
1203
1204
Item*
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1205
Create_func_export_set::create_native(Session *session, lex_string_t name, List<Item> *item_list)
1 by brian
clean slate
1206
{
2318.6.86 by Olaf van der Spek
Refactor
1207
  switch (item_list ? item_list->size() : 0) 
2318.6.85 by Olaf van der Spek
Refactor
1208
  {
1 by brian
clean slate
1209
  case 3:
2318.6.85 by Olaf van der Spek
Refactor
1210
    {
1211
      Item *param_1= item_list->pop();
1212
      Item *param_2= item_list->pop();
1213
      Item *param_3= item_list->pop();
1214
      return new (session->mem) Item_func_export_set(param_1, param_2, param_3);
1215
    }
1 by brian
clean slate
1216
  case 4:
2318.6.85 by Olaf van der Spek
Refactor
1217
    {
1218
      Item *param_1= item_list->pop();
1219
      Item *param_2= item_list->pop();
1220
      Item *param_3= item_list->pop();
1221
      Item *param_4= item_list->pop();
1222
      return new (session->mem) Item_func_export_set(param_1, param_2, param_3, param_4);
1223
    }
1 by brian
clean slate
1224
  case 5:
2318.6.85 by Olaf van der Spek
Refactor
1225
    {
1226
      Item *param_1= item_list->pop();
1227
      Item *param_2= item_list->pop();
1228
      Item *param_3= item_list->pop();
1229
      Item *param_4= item_list->pop();
1230
      Item *param_5= item_list->pop();
1231
      return new (session->mem) Item_func_export_set(param_1, param_2, param_3, param_4, param_5);
1232
    }
1 by brian
clean slate
1233
  default:
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1234
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2318.6.85 by Olaf van der Spek
Refactor
1235
  }
1236
  return NULL;
1 by brian
clean slate
1237
}
1238
1239
1240
Create_func_field Create_func_field::s_singleton;
1241
1242
Item*
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1243
Create_func_field::create_native(Session *session, lex_string_t name,
1 by brian
clean slate
1244
                                 List<Item> *item_list)
1245
{
2318.6.83 by Olaf van der Spek
Refactor
1246
  int arg_count= item_list ? item_list->size() : 0;
1 by brian
clean slate
1247
  if (arg_count < 2)
1248
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1249
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1250
    return NULL;
1251
  }
1252
2318.6.81 by Olaf van der Spek
Refactor
1253
  return new (session->mem) Item_func_field(*item_list);
1 by brian
clean slate
1254
}
1255
1256
1257
Create_func_find_in_set Create_func_find_in_set::s_singleton;
1258
1259
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1260
Create_func_find_in_set::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1261
{
2318.6.81 by Olaf van der Spek
Refactor
1262
  return new (session->mem) Item_func_find_in_set(arg1, arg2);
1 by brian
clean slate
1263
}
1264
1265
Create_func_found_rows Create_func_found_rows::s_singleton;
1266
1267
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1268
Create_func_found_rows::create(Session *session)
1 by brian
clean slate
1269
{
2318.6.81 by Olaf van der Spek
Refactor
1270
  return new (session->mem) Item_func_found_rows();
1 by brian
clean slate
1271
}
1272
1273
1274
Create_func_from_days Create_func_from_days::s_singleton;
1275
1276
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1277
Create_func_from_days::create(Session *session, Item *arg1)
1 by brian
clean slate
1278
{
2318.6.81 by Olaf van der Spek
Refactor
1279
  return new (session->mem) Item_func_from_days(arg1);
1 by brian
clean slate
1280
}
1281
1282
1283
Create_func_from_unixtime Create_func_from_unixtime::s_singleton;
1284
1285
Item*
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1286
Create_func_from_unixtime::create_native(Session *session, lex_string_t name,
1 by brian
clean slate
1287
                                         List<Item> *item_list)
1288
{
2318.6.86 by Olaf van der Spek
Refactor
1289
  switch (item_list ? item_list->size() : 0) 
2318.6.85 by Olaf van der Spek
Refactor
1290
  {
1 by brian
clean slate
1291
  case 1:
2318.6.85 by Olaf van der Spek
Refactor
1292
    {
1293
      Item *param_1= item_list->pop();
1294
      return new (session->mem) Item_func_from_unixtime(param_1);
1295
    }
1 by brian
clean slate
1296
  case 2:
2318.6.85 by Olaf van der Spek
Refactor
1297
    {
1298
      Item *param_1= item_list->pop();
1299
      Item *param_2= item_list->pop();
1300
      Item *ut= new (session->mem) Item_func_from_unixtime(param_1);
1301
      return new (session->mem) Item_func_date_format(ut, param_2, 0);
1302
    }
1 by brian
clean slate
1303
  default:
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1304
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1305
  }
2318.6.85 by Olaf van der Spek
Refactor
1306
  return NULL;
1 by brian
clean slate
1307
}
1308
1309
1310
Create_func_greatest Create_func_greatest::s_singleton;
1311
1312
Item*
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1313
Create_func_greatest::create_native(Session *session, lex_string_t name,
1 by brian
clean slate
1314
                                    List<Item> *item_list)
1315
{
2318.6.83 by Olaf van der Spek
Refactor
1316
  int arg_count= item_list ? item_list->size() : 0;
1 by brian
clean slate
1317
  if (arg_count < 2)
1318
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1319
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1320
    return NULL;
1321
  }
1322
2318.6.81 by Olaf van der Spek
Refactor
1323
  return new (session->mem) Item_func_max(*item_list);
1 by brian
clean slate
1324
}
1325
1326
Create_func_ifnull Create_func_ifnull::s_singleton;
1327
1328
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1329
Create_func_ifnull::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1330
{
2318.6.81 by Olaf van der Spek
Refactor
1331
  return new (session->mem) Item_func_ifnull(arg1, arg2);
1 by brian
clean slate
1332
}
1333
1334
1335
Create_func_instr Create_func_instr::s_singleton;
1336
1337
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1338
Create_func_instr::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1339
{
2318.6.81 by Olaf van der Spek
Refactor
1340
  return new (session->mem) Item_func_locate(arg1, arg2);
1 by brian
clean slate
1341
}
1342
1343
1344
Create_func_isnull Create_func_isnull::s_singleton;
1345
1346
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1347
Create_func_isnull::create(Session *session, Item *arg1)
1 by brian
clean slate
1348
{
2318.6.81 by Olaf van der Spek
Refactor
1349
  return new (session->mem) Item_func_isnull(arg1);
1 by brian
clean slate
1350
}
1351
1352
1353
Create_func_last_day Create_func_last_day::s_singleton;
1354
1355
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1356
Create_func_last_day::create(Session *session, Item *arg1)
1 by brian
clean slate
1357
{
2318.6.81 by Olaf van der Spek
Refactor
1358
  return new (session->mem) Item_func_last_day(arg1);
1 by brian
clean slate
1359
}
1360
1361
1362
Create_func_last_insert_id Create_func_last_insert_id::s_singleton;
1363
1364
Item*
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1365
Create_func_last_insert_id::create_native(Session *session, lex_string_t name,
1 by brian
clean slate
1366
                                          List<Item> *item_list)
1367
{
2318.6.83 by Olaf van der Spek
Refactor
1368
  int arg_count= item_list ? item_list->size() : 0;
1 by brian
clean slate
1369
  switch (arg_count) {
1370
  case 0:
2318.6.85 by Olaf van der Spek
Refactor
1371
    {
1372
      return new (session->mem) Item_func_last_insert_id();
1373
    }
1 by brian
clean slate
1374
  case 1:
2318.6.85 by Olaf van der Spek
Refactor
1375
    {
1376
      Item *param_1= item_list->pop();
1377
      return new (session->mem) Item_func_last_insert_id(param_1);
1378
    }
1 by brian
clean slate
1379
  default:
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1380
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2318.6.85 by Olaf van der Spek
Refactor
1381
  }
1382
  return NULL;
1 by brian
clean slate
1383
}
1384
1385
1386
Create_func_lcase Create_func_lcase::s_singleton;
1387
1388
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1389
Create_func_lcase::create(Session *session, Item *arg1)
1 by brian
clean slate
1390
{
2318.6.81 by Olaf van der Spek
Refactor
1391
  return new (session->mem) Item_func_lcase(arg1);
1 by brian
clean slate
1392
}
1393
1394
1395
Create_func_least Create_func_least::s_singleton;
1396
1397
Item*
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1398
Create_func_least::create_native(Session *session, lex_string_t name,
1 by brian
clean slate
1399
                                 List<Item> *item_list)
1400
{
2318.6.83 by Olaf van der Spek
Refactor
1401
  int arg_count= item_list ? item_list->size() : 0;
1 by brian
clean slate
1402
  if (arg_count < 2)
1403
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1404
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1405
    return NULL;
1406
  }
1407
2318.6.81 by Olaf van der Spek
Refactor
1408
  return new (session->mem) Item_func_min(*item_list);
1 by brian
clean slate
1409
}
1410
1411
Create_func_load_file Create_func_load_file::s_singleton;
1412
1413
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1414
Create_func_load_file::create(Session *session, Item *arg1)
1 by brian
clean slate
1415
{
2318.6.81 by Olaf van der Spek
Refactor
1416
  return new (session->mem) Item_load_file(*session, arg1);
1 by brian
clean slate
1417
}
1418
1419
1420
Create_func_locate Create_func_locate::s_singleton;
1421
1422
Item*
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1423
Create_func_locate::create_native(Session *session, lex_string_t name,
1 by brian
clean slate
1424
                                  List<Item> *item_list)
1425
{
2318.6.83 by Olaf van der Spek
Refactor
1426
  int arg_count= item_list ? item_list->size() : 0;
2318.6.85 by Olaf van der Spek
Refactor
1427
  switch (arg_count) 
1428
  {
1 by brian
clean slate
1429
  case 2:
2318.6.85 by Olaf van der Spek
Refactor
1430
    {
1431
      Item *param_1= item_list->pop();
1432
      Item *param_2= item_list->pop();
1433
      /* Yes, parameters in that order : 2, 1 */
1434
      return new (session->mem) Item_func_locate(param_2, param_1);
1435
    }
1 by brian
clean slate
1436
  case 3:
2318.6.85 by Olaf van der Spek
Refactor
1437
    {
1438
      Item *param_1= item_list->pop();
1439
      Item *param_2= item_list->pop();
1440
      Item *param_3= item_list->pop();
1441
      /* Yes, parameters in that order : 2, 1, 3 */
1442
      return new (session->mem) Item_func_locate(param_2, param_1, param_3);
1443
    }
1 by brian
clean slate
1444
  default:
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1445
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2318.6.85 by Olaf van der Spek
Refactor
1446
  }
1447
  return NULL;
1 by brian
clean slate
1448
}
1449
1450
Create_func_make_set Create_func_make_set::s_singleton;
1451
1452
Item*
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1453
Create_func_make_set::create_native(Session *session_arg, lex_string_t name,
1 by brian
clean slate
1454
                                    List<Item> *item_list)
1455
{
2318.6.83 by Olaf van der Spek
Refactor
1456
  int arg_count= item_list ? item_list->size() : 0;
1 by brian
clean slate
1457
  if (arg_count < 2)
1458
  {
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1459
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
1 by brian
clean slate
1460
    return NULL;
1461
  }
1462
1463
  Item *param_1= item_list->pop();
2318.6.81 by Olaf van der Spek
Refactor
1464
  return new (session_arg->mem) Item_func_make_set(*session_arg, param_1, *item_list);
1 by brian
clean slate
1465
}
1466
1467
Create_func_oct Create_func_oct::s_singleton;
1468
1469
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1470
Create_func_oct::create(Session *session, Item *arg1)
1 by brian
clean slate
1471
{
2318.6.81 by Olaf van der Spek
Refactor
1472
  Item *i10= new (session->mem) Item_int((int32_t) 10,2);
1473
  Item *i8= new (session->mem) Item_int((int32_t) 8,1);
1474
  return new (session->mem) Item_func_conv(arg1, i10, i8);
1 by brian
clean slate
1475
}
1476
1477
Create_func_period_add Create_func_period_add::s_singleton;
1478
1479
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1480
Create_func_period_add::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1481
{
2318.6.81 by Olaf van der Spek
Refactor
1482
  return new (session->mem) Item_func_period_add(arg1, arg2);
1 by brian
clean slate
1483
}
1484
1485
1486
Create_func_period_diff Create_func_period_diff::s_singleton;
1487
1488
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1489
Create_func_period_diff::create(Session *session, Item *arg1, Item *arg2)
1 by brian
clean slate
1490
{
2318.6.81 by Olaf van der Spek
Refactor
1491
  return new (session->mem) Item_func_period_diff(arg1, arg2);
1 by brian
clean slate
1492
}
1493
1494
1495
Create_func_pi Create_func_pi::s_singleton;
1496
1497
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1498
Create_func_pi::create(Session *session)
1 by brian
clean slate
1499
{
2318.6.81 by Olaf van der Spek
Refactor
1500
  return new (session->mem) Item_static_float_func("pi()", M_PI, 6, 8);
1 by brian
clean slate
1501
}
1502
1503
Create_func_radians Create_func_radians::s_singleton;
1504
1505
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1506
Create_func_radians::create(Session *session, Item *arg1)
1 by brian
clean slate
1507
{
2318.6.82 by Olaf van der Spek
Refactor
1508
  return new (session->mem) Item_func_units("radians", arg1,
1 by brian
clean slate
1509
                                             M_PI/180, 0.0);
1510
}
1511
1512
Create_func_round Create_func_round::s_singleton;
1513
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1514
Item* Create_func_round::create_native(Session *session, lex_string_t name, List<Item> *item_list)
1 by brian
clean slate
1515
{
2318.6.88 by Olaf van der Spek
Refactor
1516
  switch (item_list ? item_list->size() : 0) 
1517
  {
1 by brian
clean slate
1518
  case 1:
1519
  {
1520
    Item *param_1= item_list->pop();
2318.6.82 by Olaf van der Spek
Refactor
1521
    Item *i0 = new (session->mem) Item_int("0", 0, 1);
2318.6.88 by Olaf van der Spek
Refactor
1522
    return new (session->mem) Item_func_round(param_1, i0, 0);
1 by brian
clean slate
1523
  }
1524
  case 2:
1525
  {
1526
    Item *param_1= item_list->pop();
1527
    Item *param_2= item_list->pop();
2318.6.88 by Olaf van der Spek
Refactor
1528
    return new (session->mem) Item_func_round(param_1, param_2, 0);
1 by brian
clean slate
1529
  }
1530
  default:
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
1531
    my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
2318.6.88 by Olaf van der Spek
Refactor
1532
  }
1533
  return NULL;
1 by brian
clean slate
1534
}
1535
1536
Create_func_space Create_func_space::s_singleton;
1537
1538
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
1539
Create_func_space::create(Session *session, Item *arg1)
1 by brian
clean slate
1540
{
1541
  /**
1542
    TODO: Fix Bug#23637
1543
    The parsed item tree should not depend on
520.1.22 by Brian Aker
Second pass of thd cleanup
1544
    <code>session->variables.collation_connection</code>.
1 by brian
clean slate
1545
  */
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
1546
  const charset_info_st * const cs= session->variables.getCollation();
1 by brian
clean slate
1547
  Item *sp;
1548
1549
  if (cs->mbminlen > 1)
1550
  {
2318.6.81 by Olaf van der Spek
Refactor
1551
    sp= new (session->mem) Item_string("", 0, cs, DERIVATION_COERCIBLE);
2281.6.2 by Olaf van der Spek
Return void
1552
    sp->str_value.copy(" ", 1, cs);
1 by brian
clean slate
1553
  }
1554
  else
1555
  {
2318.6.81 by Olaf van der Spek
Refactor
1556
    sp= new (session->mem) Item_string(" ", 1, cs, DERIVATION_COERCIBLE);
1 by brian
clean slate
1557
  }
1558
2318.6.81 by Olaf van der Spek
Refactor
1559
  return new (session->mem) Item_func_repeat(*session, sp, arg1);
1 by brian
clean slate
1560
}
1561
1562
Create_func_unix_timestamp Create_func_unix_timestamp::s_singleton;
1563
1564
Item*
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1565
Create_func_unix_timestamp::create_native(Session *session, lex_string_t name,
1 by brian
clean slate
1566
                                          List<Item> *item_list)
1567
{
2318.6.86 by Olaf van der Spek
Refactor
1568
  switch (item_list ? item_list->size() : 0) 
1569
  {
1 by brian
clean slate
1570
  case 0:
2318.6.86 by Olaf van der Spek
Refactor
1571
    return new (session->mem) Item_func_unix_timestamp();
1 by brian
clean slate
1572
  case 1:
2318.6.86 by Olaf van der Spek
Refactor
1573
    return new (session->mem) Item_func_unix_timestamp(item_list->pop());
1 by brian
clean slate
1574
  default:
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);
2318.6.86 by Olaf van der Spek
Refactor
1576
  }
1577
  return NULL;
1578
}
1579
1 by brian
clean slate
1580
1581
struct Native_func_registry
1582
{
2385.2.12 by Olaf van der Spek
Refactor
1583
  const char* name;
1 by brian
clean slate
1584
  Create_func *builder;
1585
};
1586
1587
#define BUILDER(F) & F::s_singleton
1588
1589
/*
1590
  MySQL native functions.
1591
  MAINTAINER:
1592
  - Keep sorted for human lookup. At runtime, a hash table is used.
1593
  - keep 1 line per entry, it makes grep | sort easier
1594
*/
1595
1596
static Native_func_registry func_array[] =
1597
{
2385.2.12 by Olaf van der Spek
Refactor
1598
  { "BIN", BUILDER(Create_func_bin)},
1599
  { "CONCAT", BUILDER(Create_func_concat)},
1600
  { "CONCAT_WS", BUILDER(Create_func_concat_ws)},
1601
  { "CONV", BUILDER(Create_func_conv)},
1602
  { "COT", BUILDER(Create_func_cot)},
1603
  { "DATEDIFF", BUILDER(Create_func_datediff)},
1604
  { "DATE_FORMAT", BUILDER(Create_func_date_format)},
1605
  { "DAYNAME", BUILDER(Create_func_dayname)},
1606
  { "DAYOFMONTH", BUILDER(Create_func_dayofmonth)},
1607
  { "DAYOFWEEK", BUILDER(Create_func_dayofweek)},
1608
  { "DAYOFYEAR", BUILDER(Create_func_dayofyear)},
1609
  { "DEGREES", BUILDER(Create_func_degrees)},
1610
  { "EXPORT_SET", BUILDER(Create_func_export_set)},
1611
  { "FIELD", BUILDER(Create_func_field)},
1612
  { "FIND_IN_SET", BUILDER(Create_func_find_in_set)},
1613
  { "FOUND_ROWS", BUILDER(Create_func_found_rows)},
1614
  { "FROM_DAYS", BUILDER(Create_func_from_days)},
1615
  { "FROM_UNIXTIME", BUILDER(Create_func_from_unixtime)},
1616
  { "GREATEST", BUILDER(Create_func_greatest)},
1617
  { "IFNULL", BUILDER(Create_func_ifnull)},
1618
  { "INSTR", BUILDER(Create_func_instr)},
1619
  { "ISNULL", BUILDER(Create_func_isnull)},
1620
  { "LAST_DAY", BUILDER(Create_func_last_day)},
1621
  { "LAST_INSERT_ID", BUILDER(Create_func_last_insert_id)},
1622
  { "LCASE", BUILDER(Create_func_lcase)},
1623
  { "LEAST", BUILDER(Create_func_least)},
1624
  { "LOAD_FILE", BUILDER(Create_func_load_file)},
1625
  { "LOCATE", BUILDER(Create_func_locate)},
1626
  { "LOWER", BUILDER(Create_func_lcase)},
1627
  { "LPAD", BUILDER(Create_func_lpad)},
1628
  { "LTRIM", BUILDER(Create_func_ltrim)},
1629
  { "MAKEDATE", BUILDER(Create_func_makedate)},
1630
  { "MAKE_SET", BUILDER(Create_func_make_set)},
1631
  { "MONTHNAME", BUILDER(Create_func_monthname)},
1632
  { "NULLIF", BUILDER(Create_func_nullif)},
1633
  { "OCT", BUILDER(Create_func_oct)},
1634
  { "PERIOD_ADD", BUILDER(Create_func_period_add)},
1635
  { "PERIOD_DIFF", BUILDER(Create_func_period_diff)},
1636
  { "PI", BUILDER(Create_func_pi)},
1637
  { "RADIANS", BUILDER(Create_func_radians)},
1638
  { "ROUND", BUILDER(Create_func_round)},
1639
  { "ROW_COUNT", BUILDER(Create_func_row_count)},
1640
  { "RPAD", BUILDER(Create_func_rpad)},
1641
  { "RTRIM", BUILDER(Create_func_rtrim)},
1642
  { "SIGN", BUILDER(Create_func_sign)},
1643
  { "SPACE", BUILDER(Create_func_space)},
1644
  { "STRCMP", BUILDER(Create_func_strcmp)},
1645
  { "TAN", BUILDER(Create_func_tan)},
1646
  { "TIME_FORMAT", BUILDER(Create_func_time_format)},
1647
  { "TO_DAYS", BUILDER(Create_func_to_days)},
1648
  { "UCASE", BUILDER(Create_func_ucase)},
1649
  { "UNIX_TIMESTAMP", BUILDER(Create_func_unix_timestamp)},
1650
  { "UPPER", BUILDER(Create_func_ucase)},
1651
  { "WEEKDAY", BUILDER(Create_func_weekday)},
1652
  { NULL, NULL}
1 by brian
clean slate
1653
};
1654
1655
/*
1656
  Load the hash table for native functions.
1657
  Note: this code is not thread safe, and is intended to be used at server
1658
  startup only (before going multi-threaded)
1659
*/
1660
2318.6.77 by Olaf van der Spek
Refactor
1661
void item_create_init()
1662
{
1663
  for (Native_func_registry* func= func_array; func->builder; func++)
2385.2.12 by Olaf van der Spek
Refactor
1664
    FunctionContainer::getMutableMap()[func->name]= func->builder;
2318.6.77 by Olaf van der Spek
Refactor
1665
}
1666
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1667
Create_func* find_native_function_builder(lex_string_t name)
2318.6.77 by Olaf van der Spek
Refactor
1668
{
2385.2.12 by Olaf van der Spek
Refactor
1669
  return find_ptr2(FunctionContainer::getMap(), name.str);
2318.6.77 by Olaf van der Spek
Refactor
1670
}
1671
2385.2.12 by Olaf van der Spek
Refactor
1672
Item* create_func_char_cast(Session *session, Item *a, int len, const charset_info_st* cs)
2318.6.77 by Olaf van der Spek
Refactor
1673
{
2318.6.81 by Olaf van der Spek
Refactor
1674
  return new (session->mem) Item_char_typecast(a, len, cs ? cs : session->variables.getCollation());
2318.6.77 by Olaf van der Spek
Refactor
1675
}
1676
2318.6.86 by Olaf van der Spek
Refactor
1677
Item* create_func_cast(Session *session, Item *a, Cast_target cast_type, const char *c_len, const char *c_dec, const charset_info_st * const cs)
1 by brian
clean slate
1678
{
2318.6.86 by Olaf van der Spek
Refactor
1679
  switch (cast_type) 
1680
  {
2015.1.3 by Brian Aker
Merge in CAST operators for SIGNED/UNSIGNED
1681
  case ITEM_CAST_SIGNED:
2318.6.86 by Olaf van der Spek
Refactor
1682
    return new (session->mem) function::cast::Signed(a);
2015.1.3 by Brian Aker
Merge in CAST operators for SIGNED/UNSIGNED
1683
  case ITEM_CAST_UNSIGNED:
2318.6.86 by Olaf van der Spek
Refactor
1684
    return new (session->mem) function::cast::Unsigned(a);
1 by brian
clean slate
1685
  case ITEM_CAST_BINARY:
2318.6.86 by Olaf van der Spek
Refactor
1686
    return new (session->mem) Item_func_binary(a);
2023.2.4 by Brian Aker
Merge in cast() for BOOLEAN.
1687
  case ITEM_CAST_BOOLEAN:
2318.6.86 by Olaf van der Spek
Refactor
1688
    return new (session->mem) function::cast::Boolean(a);
1999.4.8 by Brian Aker
Adding in time type.
1689
  case ITEM_CAST_TIME:
2318.6.86 by Olaf van der Spek
Refactor
1690
    return new (session->mem) function::cast::Time(a);
1 by brian
clean slate
1691
  case ITEM_CAST_DATE:
2318.6.86 by Olaf van der Spek
Refactor
1692
    return new (session->mem) Item_date_typecast(a);
1 by brian
clean slate
1693
  case ITEM_CAST_DATETIME:
2318.6.86 by Olaf van der Spek
Refactor
1694
    return new (session->mem) Item_datetime_typecast(a);
1 by brian
clean slate
1695
  case ITEM_CAST_DECIMAL:
1999.4.8 by Brian Aker
Adding in time type.
1696
    {
2318.6.86 by Olaf van der Spek
Refactor
1697
      uint32_t len= c_len ? atoi(c_len) : 0;
1698
      uint32_t dec= c_dec ? atoi(c_dec) : 0;
2030.1.2 by Brian Aker
First pass in refactoring of the name of my_decimal.
1699
      class_decimal_trim(&len, &dec);
1999.4.8 by Brian Aker
Adding in time type.
1700
      if (len < dec)
1701
      {
1702
        my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
1703
        return 0;
1704
      }
1705
      if (len > DECIMAL_MAX_PRECISION)
1706
      {
2318.6.86 by Olaf van der Spek
Refactor
1707
        my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name, DECIMAL_MAX_PRECISION);
1999.4.8 by Brian Aker
Adding in time type.
1708
        return 0;
1709
      }
1710
      if (dec > DECIMAL_MAX_SCALE)
1711
      {
2318.6.86 by Olaf van der Spek
Refactor
1712
        my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name, DECIMAL_MAX_SCALE);
1999.4.8 by Brian Aker
Adding in time type.
1713
        return 0;
1714
      }
2318.6.86 by Olaf van der Spek
Refactor
1715
      return new (session->mem) Item_decimal_typecast(a, len, dec);
1999.4.8 by Brian Aker
Adding in time type.
1716
    }
1 by brian
clean slate
1717
  case ITEM_CAST_CHAR:
2318.6.86 by Olaf van der Spek
Refactor
1718
    return create_func_char_cast(session, a, c_len ? atoi(c_len) : -1, cs);
1999.4.8 by Brian Aker
Adding in time type.
1719
  }
2318.6.86 by Olaf van der Spek
Refactor
1720
  return NULL;
1 by brian
clean slate
1721
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1722
1723
} /* namespace drizzled */