1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2006 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
||
17 |
/* Function items used by mysql */
|
|
18 |
||
19 |
#ifdef USE_PRAGMA_INTERFACE
|
|
20 |
#pragma interface /* gcc class implementation */ |
|
21 |
#endif
|
|
22 |
||
23 |
enum date_time_format_types |
|
24 |
{
|
|
25 |
TIME_ONLY= 0, TIME_MICROSECOND, DATE_ONLY, DATE_TIME, DATE_TIME_MICROSECOND |
|
26 |
};
|
|
27 |
||
28 |
bool get_interval_value(Item *args,interval_type int_type, |
|
29 |
String *str_value, INTERVAL *interval); |
|
30 |
||
31 |
class Item_func_period_add :public Item_int_func |
|
32 |
{
|
|
33 |
public: |
|
34 |
Item_func_period_add(Item *a,Item *b) :Item_int_func(a,b) {} |
|
35 |
longlong val_int(); |
|
36 |
const char *func_name() const { return "period_add"; } |
|
37 |
void fix_length_and_dec() |
|
38 |
{
|
|
39 |
max_length=6*MY_CHARSET_BIN_MB_MAXLEN; |
|
40 |
}
|
|
41 |
};
|
|
42 |
||
43 |
||
44 |
class Item_func_period_diff :public Item_int_func |
|
45 |
{
|
|
46 |
public: |
|
47 |
Item_func_period_diff(Item *a,Item *b) :Item_int_func(a,b) {} |
|
48 |
longlong val_int(); |
|
49 |
const char *func_name() const { return "period_diff"; } |
|
50 |
void fix_length_and_dec() |
|
51 |
{
|
|
52 |
decimals=0; |
|
53 |
max_length=6*MY_CHARSET_BIN_MB_MAXLEN; |
|
54 |
}
|
|
55 |
};
|
|
56 |
||
57 |
||
58 |
class Item_func_to_days :public Item_int_func |
|
59 |
{
|
|
60 |
public: |
|
61 |
Item_func_to_days(Item *a) :Item_int_func(a) {} |
|
62 |
longlong val_int(); |
|
63 |
const char *func_name() const { return "to_days"; } |
|
64 |
void fix_length_and_dec() |
|
65 |
{
|
|
66 |
decimals=0; |
|
67 |
max_length=6*MY_CHARSET_BIN_MB_MAXLEN; |
|
68 |
maybe_null=1; |
|
69 |
}
|
|
70 |
enum_monotonicity_info get_monotonicity_info() const; |
|
71 |
longlong val_int_endpoint(bool left_endp, bool *incl_endp); |
|
72 |
};
|
|
73 |
||
74 |
||
75 |
class Item_func_dayofmonth :public Item_int_func |
|
76 |
{
|
|
77 |
public: |
|
78 |
Item_func_dayofmonth(Item *a) :Item_int_func(a) {} |
|
79 |
longlong val_int(); |
|
80 |
const char *func_name() const { return "dayofmonth"; } |
|
81 |
void fix_length_and_dec() |
|
82 |
{
|
|
83 |
decimals=0; |
|
84 |
max_length=2*MY_CHARSET_BIN_MB_MAXLEN; |
|
85 |
maybe_null=1; |
|
86 |
}
|
|
87 |
};
|
|
88 |
||
89 |
||
90 |
class Item_func_month :public Item_func |
|
91 |
{
|
|
92 |
public: |
|
93 |
Item_func_month(Item *a) :Item_func(a) {} |
|
94 |
longlong val_int(); |
|
95 |
double val_real() |
|
96 |
{ DBUG_ASSERT(fixed == 1); return (double) Item_func_month::val_int(); } |
|
97 |
String *val_str(String *str) |
|
98 |
{
|
|
99 |
str->set(val_int(), &my_charset_bin); |
|
100 |
return null_value ? 0 : str; |
|
101 |
}
|
|
102 |
const char *func_name() const { return "month"; } |
|
103 |
enum Item_result result_type () const { return INT_RESULT; } |
|
104 |
void fix_length_and_dec() |
|
105 |
{
|
|
106 |
collation.set(&my_charset_bin); |
|
107 |
decimals=0; |
|
108 |
max_length=2*MY_CHARSET_BIN_MB_MAXLEN; |
|
109 |
maybe_null=1; |
|
110 |
}
|
|
111 |
};
|
|
112 |
||
113 |
||
114 |
class Item_func_monthname :public Item_func_month |
|
115 |
{
|
|
116 |
public: |
|
117 |
Item_func_monthname(Item *a) :Item_func_month(a) {} |
|
118 |
const char *func_name() const { return "monthname"; } |
|
119 |
String *val_str(String *str); |
|
120 |
enum Item_result result_type () const { return STRING_RESULT; } |
|
121 |
void fix_length_and_dec() |
|
122 |
{
|
|
123 |
collation.set(&my_charset_bin); |
|
124 |
decimals=0; |
|
125 |
max_length=10*my_charset_bin.mbmaxlen; |
|
126 |
maybe_null=1; |
|
127 |
}
|
|
128 |
};
|
|
129 |
||
130 |
||
131 |
class Item_func_dayofyear :public Item_int_func |
|
132 |
{
|
|
133 |
public: |
|
134 |
Item_func_dayofyear(Item *a) :Item_int_func(a) {} |
|
135 |
longlong val_int(); |
|
136 |
const char *func_name() const { return "dayofyear"; } |
|
137 |
void fix_length_and_dec() |
|
138 |
{
|
|
139 |
decimals=0; |
|
140 |
max_length=3*MY_CHARSET_BIN_MB_MAXLEN; |
|
141 |
maybe_null=1; |
|
142 |
}
|
|
143 |
};
|
|
144 |
||
145 |
||
146 |
class Item_func_hour :public Item_int_func |
|
147 |
{
|
|
148 |
public: |
|
149 |
Item_func_hour(Item *a) :Item_int_func(a) {} |
|
150 |
longlong val_int(); |
|
151 |
const char *func_name() const { return "hour"; } |
|
152 |
void fix_length_and_dec() |
|
153 |
{
|
|
154 |
decimals=0; |
|
155 |
max_length=2*MY_CHARSET_BIN_MB_MAXLEN; |
|
156 |
maybe_null=1; |
|
157 |
}
|
|
158 |
};
|
|
159 |
||
160 |
||
161 |
class Item_func_minute :public Item_int_func |
|
162 |
{
|
|
163 |
public: |
|
164 |
Item_func_minute(Item *a) :Item_int_func(a) {} |
|
165 |
longlong val_int(); |
|
166 |
const char *func_name() const { return "minute"; } |
|
167 |
void fix_length_and_dec() |
|
168 |
{
|
|
169 |
decimals=0; |
|
170 |
max_length=2*MY_CHARSET_BIN_MB_MAXLEN; |
|
171 |
maybe_null=1; |
|
172 |
}
|
|
173 |
};
|
|
174 |
||
175 |
||
176 |
class Item_func_quarter :public Item_int_func |
|
177 |
{
|
|
178 |
public: |
|
179 |
Item_func_quarter(Item *a) :Item_int_func(a) {} |
|
180 |
longlong val_int(); |
|
181 |
const char *func_name() const { return "quarter"; } |
|
182 |
void fix_length_and_dec() |
|
183 |
{
|
|
184 |
decimals=0; |
|
185 |
max_length=1*MY_CHARSET_BIN_MB_MAXLEN; |
|
186 |
maybe_null=1; |
|
187 |
}
|
|
188 |
};
|
|
189 |
||
190 |
||
191 |
class Item_func_second :public Item_int_func |
|
192 |
{
|
|
193 |
public: |
|
194 |
Item_func_second(Item *a) :Item_int_func(a) {} |
|
195 |
longlong val_int(); |
|
196 |
const char *func_name() const { return "second"; } |
|
197 |
void fix_length_and_dec() |
|
198 |
{
|
|
199 |
decimals=0; |
|
200 |
max_length=2*MY_CHARSET_BIN_MB_MAXLEN; |
|
201 |
maybe_null=1; |
|
202 |
}
|
|
203 |
};
|
|
204 |
||
205 |
||
206 |
class Item_func_week :public Item_int_func |
|
207 |
{
|
|
208 |
public: |
|
209 |
Item_func_week(Item *a,Item *b) :Item_int_func(a,b) {} |
|
210 |
longlong val_int(); |
|
211 |
const char *func_name() const { return "week"; } |
|
212 |
void fix_length_and_dec() |
|
213 |
{
|
|
214 |
decimals=0; |
|
215 |
max_length=2*MY_CHARSET_BIN_MB_MAXLEN; |
|
216 |
maybe_null=1; |
|
217 |
}
|
|
218 |
};
|
|
219 |
||
220 |
class Item_func_yearweek :public Item_int_func |
|
221 |
{
|
|
222 |
public: |
|
223 |
Item_func_yearweek(Item *a,Item *b) :Item_int_func(a,b) {} |
|
224 |
longlong val_int(); |
|
225 |
const char *func_name() const { return "yearweek"; } |
|
226 |
void fix_length_and_dec() |
|
227 |
{
|
|
228 |
decimals=0; |
|
229 |
max_length=6*MY_CHARSET_BIN_MB_MAXLEN; |
|
230 |
maybe_null=1; |
|
231 |
}
|
|
232 |
};
|
|
233 |
||
234 |
||
235 |
class Item_func_year :public Item_int_func |
|
236 |
{
|
|
237 |
public: |
|
238 |
Item_func_year(Item *a) :Item_int_func(a) {} |
|
239 |
longlong val_int(); |
|
240 |
const char *func_name() const { return "year"; } |
|
241 |
enum_monotonicity_info get_monotonicity_info() const; |
|
242 |
longlong val_int_endpoint(bool left_endp, bool *incl_endp); |
|
243 |
void fix_length_and_dec() |
|
244 |
{
|
|
245 |
decimals=0; |
|
246 |
max_length=4*MY_CHARSET_BIN_MB_MAXLEN; |
|
247 |
maybe_null=1; |
|
248 |
}
|
|
249 |
};
|
|
250 |
||
251 |
||
252 |
class Item_func_weekday :public Item_func |
|
253 |
{
|
|
254 |
bool odbc_type; |
|
255 |
public: |
|
256 |
Item_func_weekday(Item *a,bool type_arg) |
|
257 |
:Item_func(a), odbc_type(type_arg) {} |
|
258 |
longlong val_int(); |
|
259 |
double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); } |
|
260 |
String *val_str(String *str) |
|
261 |
{
|
|
262 |
DBUG_ASSERT(fixed == 1); |
|
263 |
str->set(val_int(), &my_charset_bin); |
|
264 |
return null_value ? 0 : str; |
|
265 |
}
|
|
266 |
const char *func_name() const |
|
267 |
{
|
|
268 |
return (odbc_type ? "dayofweek" : "weekday"); |
|
269 |
}
|
|
270 |
enum Item_result result_type () const { return INT_RESULT; } |
|
271 |
void fix_length_and_dec() |
|
272 |
{
|
|
273 |
collation.set(&my_charset_bin); |
|
274 |
decimals=0; |
|
275 |
max_length=1*MY_CHARSET_BIN_MB_MAXLEN; |
|
276 |
maybe_null=1; |
|
277 |
}
|
|
278 |
};
|
|
279 |
||
280 |
class Item_func_dayname :public Item_func_weekday |
|
281 |
{
|
|
282 |
public: |
|
283 |
Item_func_dayname(Item *a) :Item_func_weekday(a,0) {} |
|
284 |
const char *func_name() const { return "dayname"; } |
|
285 |
String *val_str(String *str); |
|
286 |
enum Item_result result_type () const { return STRING_RESULT; } |
|
287 |
void fix_length_and_dec() |
|
288 |
{
|
|
289 |
collation.set(&my_charset_bin); |
|
290 |
decimals=0; |
|
291 |
max_length=9*MY_CHARSET_BIN_MB_MAXLEN; |
|
292 |
maybe_null=1; |
|
293 |
}
|
|
294 |
};
|
|
295 |
||
296 |
||
297 |
class Item_func_unix_timestamp :public Item_int_func |
|
298 |
{
|
|
299 |
String value; |
|
300 |
public: |
|
301 |
Item_func_unix_timestamp() :Item_int_func() {} |
|
302 |
Item_func_unix_timestamp(Item *a) :Item_int_func(a) {} |
|
303 |
longlong val_int(); |
|
304 |
const char *func_name() const { return "unix_timestamp"; } |
|
305 |
void fix_length_and_dec() |
|
306 |
{
|
|
307 |
decimals=0; |
|
308 |
max_length=10*MY_CHARSET_BIN_MB_MAXLEN; |
|
309 |
}
|
|
310 |
};
|
|
311 |
||
312 |
||
313 |
class Item_func_time_to_sec :public Item_int_func |
|
314 |
{
|
|
315 |
public: |
|
316 |
Item_func_time_to_sec(Item *item) :Item_int_func(item) {} |
|
317 |
longlong val_int(); |
|
318 |
const char *func_name() const { return "time_to_sec"; } |
|
319 |
void fix_length_and_dec() |
|
320 |
{
|
|
321 |
decimals=0; |
|
322 |
max_length=10*MY_CHARSET_BIN_MB_MAXLEN; |
|
323 |
}
|
|
324 |
};
|
|
325 |
||
326 |
||
327 |
/*
|
|
328 |
This can't be a Item_str_func, because the val_real() functions are special
|
|
329 |
*/
|
|
330 |
||
331 |
class Item_date :public Item_func |
|
332 |
{
|
|
333 |
public: |
|
334 |
Item_date() :Item_func() {} |
|
335 |
Item_date(Item *a) :Item_func(a) {} |
|
336 |
enum Item_result result_type () const { return STRING_RESULT; } |
|
337 |
enum_field_types field_type() const { return MYSQL_TYPE_DATE; } |
|
338 |
String *val_str(String *str); |
|
339 |
longlong val_int(); |
|
340 |
double val_real() { return val_real_from_decimal(); } |
|
341 |
const char *func_name() const { return "date"; } |
|
342 |
void fix_length_and_dec() |
|
343 |
{
|
|
344 |
collation.set(&my_charset_bin); |
|
345 |
decimals=0; |
|
346 |
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; |
|
347 |
}
|
|
348 |
Field *tmp_table_field(TABLE *table) |
|
349 |
{
|
|
350 |
return tmp_table_field_from_field_type(table, 0); |
|
351 |
}
|
|
352 |
bool result_as_longlong() { return TRUE; } |
|
353 |
my_decimal *val_decimal(my_decimal *decimal_value) |
|
354 |
{
|
|
355 |
DBUG_ASSERT(fixed == 1); |
|
356 |
return val_decimal_from_date(decimal_value); |
|
357 |
}
|
|
358 |
int save_in_field(Field *field, bool no_conversions) |
|
359 |
{
|
|
360 |
return save_date_in_field(field); |
|
361 |
}
|
|
362 |
};
|
|
363 |
||
364 |
||
365 |
class Item_date_func :public Item_str_func |
|
366 |
{
|
|
367 |
public: |
|
368 |
Item_date_func() :Item_str_func() {} |
|
369 |
Item_date_func(Item *a) :Item_str_func(a) {} |
|
370 |
Item_date_func(Item *a,Item *b) :Item_str_func(a,b) {} |
|
371 |
Item_date_func(Item *a,Item *b, Item *c) :Item_str_func(a,b,c) {} |
|
372 |
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } |
|
373 |
Field *tmp_table_field(TABLE *table) |
|
374 |
{
|
|
375 |
return tmp_table_field_from_field_type(table, 0); |
|
376 |
}
|
|
377 |
bool result_as_longlong() { return TRUE; } |
|
378 |
double val_real() { return (double) val_int(); } |
|
379 |
my_decimal *val_decimal(my_decimal *decimal_value) |
|
380 |
{
|
|
381 |
DBUG_ASSERT(fixed == 1); |
|
382 |
return val_decimal_from_date(decimal_value); |
|
383 |
}
|
|
384 |
int save_in_field(Field *field, bool no_conversions) |
|
385 |
{
|
|
386 |
return save_date_in_field(field); |
|
387 |
}
|
|
388 |
};
|
|
389 |
||
390 |
||
391 |
class Item_str_timefunc :public Item_str_func |
|
392 |
{
|
|
393 |
public: |
|
394 |
Item_str_timefunc() :Item_str_func() {} |
|
395 |
Item_str_timefunc(Item *a) :Item_str_func(a) {} |
|
396 |
Item_str_timefunc(Item *a,Item *b) :Item_str_func(a,b) {} |
|
397 |
Item_str_timefunc(Item *a, Item *b, Item *c) :Item_str_func(a, b ,c) {} |
|
398 |
enum_field_types field_type() const { return MYSQL_TYPE_TIME; } |
|
399 |
void fix_length_and_dec() |
|
400 |
{
|
|
401 |
decimals= DATETIME_DEC; |
|
402 |
max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; |
|
403 |
}
|
|
404 |
Field *tmp_table_field(TABLE *table) |
|
405 |
{
|
|
406 |
return tmp_table_field_from_field_type(table, 0); |
|
407 |
}
|
|
408 |
double val_real() { return val_real_from_decimal(); } |
|
409 |
my_decimal *val_decimal(my_decimal *decimal_value) |
|
410 |
{
|
|
411 |
DBUG_ASSERT(fixed == 1); |
|
412 |
return val_decimal_from_time(decimal_value); |
|
413 |
}
|
|
414 |
int save_in_field(Field *field, bool no_conversions) |
|
415 |
{
|
|
416 |
return save_time_in_field(field); |
|
417 |
}
|
|
418 |
};
|
|
419 |
||
420 |
||
421 |
/* Abstract CURTIME function. Children should define what time zone is used */
|
|
422 |
||
423 |
class Item_func_curtime :public Item_str_timefunc |
|
424 |
{
|
|
425 |
longlong value; |
|
426 |
char buff[9*2+32]; |
|
427 |
uint buff_length; |
|
428 |
public: |
|
429 |
Item_func_curtime() :Item_str_timefunc() {} |
|
430 |
Item_func_curtime(Item *a) :Item_str_timefunc(a) {} |
|
431 |
double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; } |
|
432 |
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; } |
|
433 |
String *val_str(String *str); |
|
434 |
void fix_length_and_dec(); |
|
435 |
/*
|
|
436 |
Abstract method that defines which time zone is used for conversion.
|
|
437 |
Converts time current time in my_time_t representation to broken-down
|
|
438 |
MYSQL_TIME representation using UTC-SYSTEM or per-thread time zone.
|
|
439 |
*/
|
|
440 |
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0; |
|
441 |
bool result_as_longlong() { return TRUE; } |
|
442 |
};
|
|
443 |
||
444 |
||
445 |
class Item_func_curtime_local :public Item_func_curtime |
|
446 |
{
|
|
447 |
public: |
|
448 |
Item_func_curtime_local() :Item_func_curtime() {} |
|
449 |
Item_func_curtime_local(Item *a) :Item_func_curtime(a) {} |
|
450 |
const char *func_name() const { return "curtime"; } |
|
451 |
virtual void store_now_in_TIME(MYSQL_TIME *now_time); |
|
452 |
};
|
|
453 |
||
454 |
||
455 |
class Item_func_curtime_utc :public Item_func_curtime |
|
456 |
{
|
|
457 |
public: |
|
458 |
Item_func_curtime_utc() :Item_func_curtime() {} |
|
459 |
Item_func_curtime_utc(Item *a) :Item_func_curtime(a) {} |
|
460 |
const char *func_name() const { return "utc_time"; } |
|
461 |
virtual void store_now_in_TIME(MYSQL_TIME *now_time); |
|
462 |
};
|
|
463 |
||
464 |
||
465 |
/* Abstract CURDATE function. See also Item_func_curtime. */
|
|
466 |
||
467 |
class Item_func_curdate :public Item_date |
|
468 |
{
|
|
469 |
longlong value; |
|
470 |
MYSQL_TIME ltime; |
|
471 |
public: |
|
472 |
Item_func_curdate() :Item_date() {} |
|
473 |
longlong val_int() { DBUG_ASSERT(fixed == 1); return (value) ; } |
|
474 |
String *val_str(String *str); |
|
475 |
void fix_length_and_dec(); |
|
476 |
bool get_date(MYSQL_TIME *res, uint fuzzy_date); |
|
477 |
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0; |
|
478 |
};
|
|
479 |
||
480 |
||
481 |
class Item_func_curdate_local :public Item_func_curdate |
|
482 |
{
|
|
483 |
public: |
|
484 |
Item_func_curdate_local() :Item_func_curdate() {} |
|
485 |
const char *func_name() const { return "curdate"; } |
|
486 |
void store_now_in_TIME(MYSQL_TIME *now_time); |
|
487 |
};
|
|
488 |
||
489 |
||
490 |
class Item_func_curdate_utc :public Item_func_curdate |
|
491 |
{
|
|
492 |
public: |
|
493 |
Item_func_curdate_utc() :Item_func_curdate() {} |
|
494 |
const char *func_name() const { return "utc_date"; } |
|
495 |
void store_now_in_TIME(MYSQL_TIME *now_time); |
|
496 |
};
|
|
497 |
||
498 |
||
499 |
/* Abstract CURRENT_TIMESTAMP function. See also Item_func_curtime */
|
|
500 |
||
501 |
class Item_func_now :public Item_date_func |
|
502 |
{
|
|
503 |
protected: |
|
504 |
longlong value; |
|
505 |
char buff[20*2+32]; // +32 to make my_snprintf_{8bit|ucs2} happy |
|
506 |
uint buff_length; |
|
507 |
MYSQL_TIME ltime; |
|
508 |
public: |
|
509 |
Item_func_now() :Item_date_func() {} |
|
510 |
Item_func_now(Item *a) :Item_date_func(a) {} |
|
511 |
enum Item_result result_type () const { return STRING_RESULT; } |
|
512 |
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; } |
|
513 |
int save_in_field(Field *to, bool no_conversions); |
|
514 |
String *val_str(String *str); |
|
515 |
void fix_length_and_dec(); |
|
516 |
bool get_date(MYSQL_TIME *res, uint fuzzy_date); |
|
517 |
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0; |
|
518 |
};
|
|
519 |
||
520 |
||
521 |
class Item_func_now_local :public Item_func_now |
|
522 |
{
|
|
523 |
public: |
|
524 |
Item_func_now_local() :Item_func_now() {} |
|
525 |
Item_func_now_local(Item *a) :Item_func_now(a) {} |
|
526 |
const char *func_name() const { return "now"; } |
|
527 |
virtual void store_now_in_TIME(MYSQL_TIME *now_time); |
|
528 |
virtual enum Functype functype() const { return NOW_FUNC; } |
|
529 |
};
|
|
530 |
||
531 |
||
532 |
class Item_func_now_utc :public Item_func_now |
|
533 |
{
|
|
534 |
public: |
|
535 |
Item_func_now_utc() :Item_func_now() {} |
|
536 |
Item_func_now_utc(Item *a) :Item_func_now(a) {} |
|
537 |
const char *func_name() const { return "utc_timestamp"; } |
|
538 |
virtual void store_now_in_TIME(MYSQL_TIME *now_time); |
|
539 |
};
|
|
540 |
||
541 |
||
542 |
/*
|
|
543 |
This is like NOW(), but always uses the real current time, not the
|
|
544 |
query_start(). This matches the Oracle behavior.
|
|
545 |
*/
|
|
546 |
class Item_func_sysdate_local :public Item_func_now |
|
547 |
{
|
|
548 |
public: |
|
549 |
Item_func_sysdate_local() :Item_func_now() {} |
|
550 |
Item_func_sysdate_local(Item *a) :Item_func_now(a) {} |
|
551 |
bool const_item() const { return 0; } |
|
552 |
const char *func_name() const { return "sysdate"; } |
|
553 |
void store_now_in_TIME(MYSQL_TIME *now_time); |
|
554 |
double val_real(); |
|
555 |
longlong val_int(); |
|
556 |
int save_in_field(Field *to, bool no_conversions); |
|
557 |
String *val_str(String *str); |
|
558 |
void fix_length_and_dec(); |
|
559 |
bool get_date(MYSQL_TIME *res, uint fuzzy_date); |
|
560 |
void update_used_tables() |
|
561 |
{
|
|
562 |
Item_func_now::update_used_tables(); |
|
563 |
used_tables_cache|= RAND_TABLE_BIT; |
|
564 |
}
|
|
565 |
};
|
|
566 |
||
567 |
||
568 |
class Item_func_from_days :public Item_date |
|
569 |
{
|
|
570 |
public: |
|
571 |
Item_func_from_days(Item *a) :Item_date(a) {} |
|
572 |
const char *func_name() const { return "from_days"; } |
|
573 |
bool get_date(MYSQL_TIME *res, uint fuzzy_date); |
|
574 |
};
|
|
575 |
||
576 |
||
577 |
class Item_func_date_format :public Item_str_func |
|
578 |
{
|
|
579 |
int fixed_length; |
|
580 |
const bool is_time_format; |
|
581 |
String value; |
|
582 |
public: |
|
583 |
Item_func_date_format(Item *a,Item *b,bool is_time_format_arg) |
|
584 |
:Item_str_func(a,b),is_time_format(is_time_format_arg) {} |
|
585 |
String *val_str(String *str); |
|
586 |
const char *func_name() const |
|
587 |
{ return is_time_format ? "time_format" : "date_format"; } |
|
588 |
void fix_length_and_dec(); |
|
589 |
uint format_length(const String *format); |
|
590 |
bool eq(const Item *item, bool binary_cmp) const; |
|
591 |
};
|
|
592 |
||
593 |
||
594 |
class Item_func_from_unixtime :public Item_date_func |
|
595 |
{
|
|
596 |
THD *thd; |
|
597 |
public: |
|
598 |
Item_func_from_unixtime(Item *a) :Item_date_func(a) {} |
|
599 |
longlong val_int(); |
|
600 |
String *val_str(String *str); |
|
601 |
const char *func_name() const { return "from_unixtime"; } |
|
602 |
void fix_length_and_dec(); |
|
603 |
bool get_date(MYSQL_TIME *res, uint fuzzy_date); |
|
604 |
};
|
|
605 |
||
606 |
||
607 |
/*
|
|
608 |
We need Time_zone class declaration for storing pointers in
|
|
609 |
Item_func_convert_tz.
|
|
610 |
*/
|
|
611 |
class Time_zone; |
|
612 |
||
613 |
/*
|
|
614 |
This class represents CONVERT_TZ() function.
|
|
615 |
The important fact about this function that it is handled in special way.
|
|
616 |
When such function is met in expression time_zone system tables are added
|
|
617 |
to global list of tables to open, so later those already opened and locked
|
|
618 |
tables can be used during this function calculation for loading time zone
|
|
619 |
descriptions.
|
|
620 |
*/
|
|
621 |
class Item_func_convert_tz :public Item_date_func |
|
622 |
{
|
|
623 |
/*
|
|
624 |
If time zone parameters are constants we are caching objects that
|
|
625 |
represent them (we use separate from_tz_cached/to_tz_cached members
|
|
626 |
to indicate this fact, since NULL is legal value for from_tz/to_tz
|
|
627 |
members.
|
|
628 |
*/
|
|
629 |
bool from_tz_cached, to_tz_cached; |
|
630 |
Time_zone *from_tz, *to_tz; |
|
631 |
public: |
|
632 |
Item_func_convert_tz(Item *a, Item *b, Item *c): |
|
633 |
Item_date_func(a, b, c), from_tz_cached(0), to_tz_cached(0) {} |
|
634 |
longlong val_int(); |
|
635 |
String *val_str(String *str); |
|
636 |
const char *func_name() const { return "convert_tz"; } |
|
637 |
void fix_length_and_dec(); |
|
638 |
bool get_date(MYSQL_TIME *res, uint fuzzy_date); |
|
639 |
void cleanup(); |
|
640 |
};
|
|
641 |
||
642 |
||
643 |
class Item_func_sec_to_time :public Item_str_timefunc |
|
644 |
{
|
|
645 |
public: |
|
646 |
Item_func_sec_to_time(Item *item) :Item_str_timefunc(item) {} |
|
647 |
double val_real() |
|
648 |
{
|
|
649 |
DBUG_ASSERT(fixed == 1); |
|
650 |
return (double) Item_func_sec_to_time::val_int(); |
|
651 |
}
|
|
652 |
longlong val_int(); |
|
653 |
String *val_str(String *); |
|
654 |
void fix_length_and_dec() |
|
655 |
{
|
|
656 |
Item_str_timefunc::fix_length_and_dec(); |
|
657 |
collation.set(&my_charset_bin); |
|
658 |
maybe_null=1; |
|
659 |
}
|
|
660 |
const char *func_name() const { return "sec_to_time"; } |
|
661 |
bool result_as_longlong() { return TRUE; } |
|
662 |
};
|
|
663 |
||
664 |
||
665 |
class Item_date_add_interval :public Item_date_func |
|
666 |
{
|
|
667 |
String value; |
|
668 |
enum_field_types cached_field_type; |
|
669 |
||
670 |
public: |
|
671 |
const interval_type int_type; // keep it public |
|
672 |
const bool date_sub_interval; // keep it public |
|
673 |
Item_date_add_interval(Item *a,Item *b,interval_type type_arg,bool neg_arg) |
|
674 |
:Item_date_func(a,b),int_type(type_arg), date_sub_interval(neg_arg) {} |
|
675 |
String *val_str(String *); |
|
676 |
const char *func_name() const { return "date_add_interval"; } |
|
677 |
void fix_length_and_dec(); |
|
678 |
enum_field_types field_type() const { return cached_field_type; } |
|
679 |
longlong val_int(); |
|
680 |
bool get_date(MYSQL_TIME *res, uint fuzzy_date); |
|
681 |
bool eq(const Item *item, bool binary_cmp) const; |
|
682 |
virtual void print(String *str, enum_query_type query_type); |
|
683 |
};
|
|
684 |
||
685 |
||
686 |
class Item_extract :public Item_int_func |
|
687 |
{
|
|
688 |
String value; |
|
689 |
bool date_value; |
|
690 |
public: |
|
691 |
const interval_type int_type; // keep it public |
|
692 |
Item_extract(interval_type type_arg, Item *a) |
|
693 |
:Item_int_func(a), int_type(type_arg) {} |
|
694 |
longlong val_int(); |
|
695 |
enum Functype functype() const { return EXTRACT_FUNC; } |
|
696 |
const char *func_name() const { return "extract"; } |
|
697 |
void fix_length_and_dec(); |
|
698 |
bool eq(const Item *item, bool binary_cmp) const; |
|
699 |
virtual void print(String *str, enum_query_type query_type); |
|
700 |
};
|
|
701 |
||
702 |
||
703 |
class Item_typecast :public Item_str_func |
|
704 |
{
|
|
705 |
public: |
|
706 |
Item_typecast(Item *a) :Item_str_func(a) {} |
|
707 |
String *val_str(String *a) |
|
708 |
{
|
|
709 |
DBUG_ASSERT(fixed == 1); |
|
710 |
String *tmp=args[0]->val_str(a); |
|
711 |
null_value=args[0]->null_value; |
|
712 |
if (tmp) |
|
713 |
tmp->set_charset(collation.collation); |
|
714 |
return tmp; |
|
715 |
}
|
|
716 |
void fix_length_and_dec() |
|
717 |
{
|
|
718 |
collation.set(&my_charset_bin); |
|
719 |
max_length=args[0]->max_length; |
|
720 |
}
|
|
721 |
virtual const char* cast_type() const= 0; |
|
722 |
virtual void print(String *str, enum_query_type query_type); |
|
723 |
};
|
|
724 |
||
725 |
||
726 |
class Item_typecast_maybe_null :public Item_typecast |
|
727 |
{
|
|
728 |
public: |
|
729 |
Item_typecast_maybe_null(Item *a) :Item_typecast(a) {} |
|
730 |
void fix_length_and_dec() |
|
731 |
{
|
|
732 |
collation.set(&my_charset_bin); |
|
733 |
max_length=args[0]->max_length; |
|
734 |
maybe_null= 1; |
|
735 |
}
|
|
736 |
};
|
|
737 |
||
738 |
||
739 |
class Item_char_typecast :public Item_typecast |
|
740 |
{
|
|
741 |
int cast_length; |
|
742 |
CHARSET_INFO *cast_cs, *from_cs; |
|
743 |
bool charset_conversion; |
|
744 |
String tmp_value; |
|
745 |
public: |
|
746 |
Item_char_typecast(Item *a, int length_arg, CHARSET_INFO *cs_arg) |
|
747 |
:Item_typecast(a), cast_length(length_arg), cast_cs(cs_arg) {} |
|
748 |
enum Functype functype() const { return CHAR_TYPECAST_FUNC; } |
|
749 |
bool eq(const Item *item, bool binary_cmp) const; |
|
750 |
const char *func_name() const { return "cast_as_char"; } |
|
751 |
const char* cast_type() const { return "char"; }; |
|
752 |
String *val_str(String *a); |
|
753 |
void fix_length_and_dec(); |
|
754 |
virtual void print(String *str, enum_query_type query_type); |
|
755 |
};
|
|
756 |
||
757 |
||
758 |
class Item_date_typecast :public Item_typecast_maybe_null |
|
759 |
{
|
|
760 |
public: |
|
761 |
Item_date_typecast(Item *a) :Item_typecast_maybe_null(a) {} |
|
762 |
const char *func_name() const { return "cast_as_date"; } |
|
763 |
String *val_str(String *str); |
|
764 |
bool get_date(MYSQL_TIME *ltime, uint fuzzy_date); |
|
765 |
bool get_time(MYSQL_TIME *ltime); |
|
766 |
const char *cast_type() const { return "date"; } |
|
767 |
enum_field_types field_type() const { return MYSQL_TYPE_DATE; } |
|
768 |
Field *tmp_table_field(TABLE *table) |
|
769 |
{
|
|
770 |
return tmp_table_field_from_field_type(table, 0); |
|
771 |
}
|
|
772 |
void fix_length_and_dec() |
|
773 |
{
|
|
774 |
collation.set(&my_charset_bin); |
|
775 |
max_length= 10; |
|
776 |
maybe_null= 1; |
|
777 |
}
|
|
778 |
bool result_as_longlong() { return TRUE; } |
|
779 |
longlong val_int(); |
|
780 |
double val_real() { return (double) val_int(); } |
|
781 |
my_decimal *val_decimal(my_decimal *decimal_value) |
|
782 |
{
|
|
783 |
DBUG_ASSERT(fixed == 1); |
|
784 |
return val_decimal_from_date(decimal_value); |
|
785 |
}
|
|
786 |
int save_in_field(Field *field, bool no_conversions) |
|
787 |
{
|
|
788 |
return save_date_in_field(field); |
|
789 |
}
|
|
790 |
};
|
|
791 |
||
792 |
||
793 |
class Item_time_typecast :public Item_typecast_maybe_null |
|
794 |
{
|
|
795 |
public: |
|
796 |
Item_time_typecast(Item *a) :Item_typecast_maybe_null(a) {} |
|
797 |
const char *func_name() const { return "cast_as_time"; } |
|
798 |
String *val_str(String *str); |
|
799 |
bool get_time(MYSQL_TIME *ltime); |
|
800 |
const char *cast_type() const { return "time"; } |
|
801 |
enum_field_types field_type() const { return MYSQL_TYPE_TIME; } |
|
802 |
Field *tmp_table_field(TABLE *table) |
|
803 |
{
|
|
804 |
return tmp_table_field_from_field_type(table, 0); |
|
805 |
}
|
|
806 |
bool result_as_longlong() { return TRUE; } |
|
807 |
longlong val_int(); |
|
808 |
double val_real() { return val_real_from_decimal(); } |
|
809 |
my_decimal *val_decimal(my_decimal *decimal_value) |
|
810 |
{
|
|
811 |
DBUG_ASSERT(fixed == 1); |
|
812 |
return val_decimal_from_time(decimal_value); |
|
813 |
}
|
|
814 |
int save_in_field(Field *field, bool no_conversions) |
|
815 |
{
|
|
816 |
return save_time_in_field(field); |
|
817 |
}
|
|
818 |
};
|
|
819 |
||
820 |
||
821 |
class Item_datetime_typecast :public Item_typecast_maybe_null |
|
822 |
{
|
|
823 |
public: |
|
824 |
Item_datetime_typecast(Item *a) :Item_typecast_maybe_null(a) {} |
|
825 |
const char *func_name() const { return "cast_as_datetime"; } |
|
826 |
String *val_str(String *str); |
|
827 |
const char *cast_type() const { return "datetime"; } |
|
828 |
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } |
|
829 |
Field *tmp_table_field(TABLE *table) |
|
830 |
{
|
|
831 |
return tmp_table_field_from_field_type(table, 0); |
|
832 |
}
|
|
833 |
void fix_length_and_dec() |
|
834 |
{
|
|
835 |
collation.set(&my_charset_bin); |
|
836 |
maybe_null= 1; |
|
837 |
max_length= MAX_DATETIME_FULL_WIDTH * MY_CHARSET_BIN_MB_MAXLEN; |
|
838 |
decimals= DATETIME_DEC; |
|
839 |
}
|
|
840 |
bool result_as_longlong() { return TRUE; } |
|
841 |
longlong val_int(); |
|
842 |
double val_real() { return val_real_from_decimal(); } |
|
843 |
double val() { return (double) val_int(); } |
|
844 |
my_decimal *val_decimal(my_decimal *decimal_value) |
|
845 |
{
|
|
846 |
DBUG_ASSERT(fixed == 1); |
|
847 |
return val_decimal_from_date(decimal_value); |
|
848 |
}
|
|
849 |
int save_in_field(Field *field, bool no_conversions) |
|
850 |
{
|
|
851 |
return save_date_in_field(field); |
|
852 |
}
|
|
853 |
};
|
|
854 |
||
855 |
class Item_func_makedate :public Item_date_func |
|
856 |
{
|
|
857 |
public: |
|
858 |
Item_func_makedate(Item *a,Item *b) :Item_date_func(a,b) {} |
|
859 |
String *val_str(String *str); |
|
860 |
const char *func_name() const { return "makedate"; } |
|
861 |
enum_field_types field_type() const { return MYSQL_TYPE_DATE; } |
|
862 |
void fix_length_and_dec() |
|
863 |
{
|
|
864 |
decimals=0; |
|
865 |
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; |
|
866 |
}
|
|
867 |
longlong val_int(); |
|
868 |
};
|
|
869 |
||
870 |
||
871 |
class Item_func_add_time :public Item_str_func |
|
872 |
{
|
|
873 |
const bool is_date; |
|
874 |
int sign; |
|
875 |
enum_field_types cached_field_type; |
|
876 |
||
877 |
public: |
|
878 |
Item_func_add_time(Item *a, Item *b, bool type_arg, bool neg_arg) |
|
879 |
:Item_str_func(a, b), is_date(type_arg) { sign= neg_arg ? -1 : 1; } |
|
880 |
String *val_str(String *str); |
|
881 |
enum_field_types field_type() const { return cached_field_type; } |
|
882 |
void fix_length_and_dec(); |
|
883 |
||
884 |
Field *tmp_table_field(TABLE *table) |
|
885 |
{
|
|
886 |
return tmp_table_field_from_field_type(table, 0); |
|
887 |
}
|
|
888 |
virtual void print(String *str, enum_query_type query_type); |
|
889 |
const char *func_name() const { return "add_time"; } |
|
890 |
double val_real() { return val_real_from_decimal(); } |
|
891 |
my_decimal *val_decimal(my_decimal *decimal_value) |
|
892 |
{
|
|
893 |
DBUG_ASSERT(fixed == 1); |
|
894 |
if (cached_field_type == MYSQL_TYPE_TIME) |
|
895 |
return val_decimal_from_time(decimal_value); |
|
896 |
if (cached_field_type == MYSQL_TYPE_DATETIME) |
|
897 |
return val_decimal_from_date(decimal_value); |
|
898 |
return Item_str_func::val_decimal(decimal_value); |
|
899 |
}
|
|
900 |
int save_in_field(Field *field, bool no_conversions) |
|
901 |
{
|
|
902 |
if (cached_field_type == MYSQL_TYPE_TIME) |
|
903 |
return save_time_in_field(field); |
|
904 |
if (cached_field_type == MYSQL_TYPE_DATETIME) |
|
905 |
return save_date_in_field(field); |
|
906 |
return Item_str_func::save_in_field(field, no_conversions); |
|
907 |
}
|
|
908 |
};
|
|
909 |
||
910 |
class Item_func_timediff :public Item_str_timefunc |
|
911 |
{
|
|
912 |
public: |
|
913 |
Item_func_timediff(Item *a, Item *b) |
|
914 |
:Item_str_timefunc(a, b) {} |
|
915 |
String *val_str(String *str); |
|
916 |
const char *func_name() const { return "timediff"; } |
|
917 |
void fix_length_and_dec() |
|
918 |
{
|
|
919 |
Item_str_timefunc::fix_length_and_dec(); |
|
920 |
maybe_null= 1; |
|
921 |
}
|
|
922 |
};
|
|
923 |
||
924 |
class Item_func_maketime :public Item_str_timefunc |
|
925 |
{
|
|
926 |
public: |
|
927 |
Item_func_maketime(Item *a, Item *b, Item *c) |
|
928 |
:Item_str_timefunc(a, b, c) |
|
929 |
{
|
|
930 |
maybe_null= TRUE; |
|
931 |
}
|
|
932 |
String *val_str(String *str); |
|
933 |
const char *func_name() const { return "maketime"; } |
|
934 |
};
|
|
935 |
||
936 |
class Item_func_microsecond :public Item_int_func |
|
937 |
{
|
|
938 |
public: |
|
939 |
Item_func_microsecond(Item *a) :Item_int_func(a) {} |
|
940 |
longlong val_int(); |
|
941 |
const char *func_name() const { return "microsecond"; } |
|
942 |
void fix_length_and_dec() |
|
943 |
{
|
|
944 |
decimals=0; |
|
945 |
maybe_null=1; |
|
946 |
}
|
|
947 |
};
|
|
948 |
||
949 |
||
950 |
class Item_func_timestamp_diff :public Item_int_func |
|
951 |
{
|
|
952 |
const interval_type int_type; |
|
953 |
public: |
|
954 |
Item_func_timestamp_diff(Item *a,Item *b,interval_type type_arg) |
|
955 |
:Item_int_func(a,b), int_type(type_arg) {} |
|
956 |
const char *func_name() const { return "timestampdiff"; } |
|
957 |
longlong val_int(); |
|
958 |
void fix_length_and_dec() |
|
959 |
{
|
|
960 |
decimals=0; |
|
961 |
maybe_null=1; |
|
962 |
}
|
|
963 |
virtual void print(String *str, enum_query_type query_type); |
|
964 |
};
|
|
965 |
||
966 |
||
967 |
enum date_time_format |
|
968 |
{
|
|
969 |
USA_FORMAT, JIS_FORMAT, ISO_FORMAT, EUR_FORMAT, INTERNAL_FORMAT |
|
970 |
};
|
|
971 |
||
972 |
class Item_func_get_format :public Item_str_func |
|
973 |
{
|
|
974 |
public: |
|
975 |
const timestamp_type type; // keep it public |
|
976 |
Item_func_get_format(timestamp_type type_arg, Item *a) |
|
977 |
:Item_str_func(a), type(type_arg) |
|
978 |
{}
|
|
979 |
String *val_str(String *str); |
|
980 |
const char *func_name() const { return "get_format"; } |
|
981 |
void fix_length_and_dec() |
|
982 |
{
|
|
983 |
maybe_null= 1; |
|
984 |
decimals=0; |
|
985 |
max_length=17*MY_CHARSET_BIN_MB_MAXLEN; |
|
986 |
}
|
|
987 |
virtual void print(String *str, enum_query_type query_type); |
|
988 |
};
|
|
989 |
||
990 |
||
991 |
class Item_func_str_to_date :public Item_str_func |
|
992 |
{
|
|
993 |
enum_field_types cached_field_type; |
|
994 |
date_time_format_types cached_format_type; |
|
995 |
timestamp_type cached_timestamp_type; |
|
996 |
bool const_item; |
|
997 |
public: |
|
998 |
Item_func_str_to_date(Item *a, Item *b) |
|
999 |
:Item_str_func(a, b), const_item(false) |
|
1000 |
{}
|
|
1001 |
String *val_str(String *str); |
|
1002 |
bool get_date(MYSQL_TIME *ltime, uint fuzzy_date); |
|
1003 |
const char *func_name() const { return "str_to_date"; } |
|
1004 |
enum_field_types field_type() const { return cached_field_type; } |
|
1005 |
void fix_length_and_dec(); |
|
1006 |
Field *tmp_table_field(TABLE *table) |
|
1007 |
{
|
|
1008 |
return tmp_table_field_from_field_type(table, 1); |
|
1009 |
}
|
|
1010 |
};
|
|
1011 |
||
1012 |
||
1013 |
class Item_func_last_day :public Item_date |
|
1014 |
{
|
|
1015 |
public: |
|
1016 |
Item_func_last_day(Item *a) :Item_date(a) {} |
|
1017 |
const char *func_name() const { return "last_day"; } |
|
1018 |
bool get_date(MYSQL_TIME *res, uint fuzzy_date); |
|
1019 |
};
|