17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include <drizzled/sql_select.h>
22
#include <drizzled/error.h>
23
#include <drizzled/show.h>
24
#include <drizzled/item/cmpfunc.h>
25
#include <drizzled/item/cache_row.h>
26
#include <drizzled/item/type_holder.h>
27
#include <drizzled/item/sum.h>
28
#include <drizzled/item/copy_string.h>
29
#include <drizzled/function/str/conv_charset.h>
30
#include <drizzled/sql_base.h>
31
#include <drizzled/util/convert.h>
32
#include <drizzled/plugin/client.h>
33
#include <drizzled/time_functions.h>
35
#include <drizzled/field/str.h>
36
#include <drizzled/field/num.h>
38
#include <drizzled/field/blob.h>
39
#include <drizzled/field/date.h>
40
#include <drizzled/field/datetime.h>
41
#include <drizzled/field/decimal.h>
42
#include <drizzled/field/double.h>
43
#include <drizzled/field/enum.h>
44
#include <drizzled/field/epoch.h>
45
#include <drizzled/field/int32.h>
46
#include <drizzled/field/int64.h>
47
#include <drizzled/field/microtime.h>
48
#include <drizzled/field/null.h>
49
#include <drizzled/field/real.h>
50
#include <drizzled/field/size.h>
51
#include <drizzled/field/time.h>
52
#include <drizzled/field/varstring.h>
54
#include <drizzled/current_session.h>
55
#include <drizzled/session.h>
57
#include <drizzled/internal/m_string.h>
21
#include "drizzled/sql_select.h"
22
#include "drizzled/error.h"
23
#include "drizzled/show.h"
24
#include "drizzled/item/cmpfunc.h"
25
#include "drizzled/item/cache_row.h"
26
#include "drizzled/item/type_holder.h"
27
#include "drizzled/item/sum.h"
28
#include "drizzled/item/copy_string.h"
29
#include "drizzled/function/str/conv_charset.h"
30
#include "drizzled/sql_base.h"
31
#include "drizzled/util/convert.h"
32
#include "drizzled/plugin/client.h"
33
#include "drizzled/time_functions.h"
35
#include "drizzled/field/str.h"
36
#include "drizzled/field/num.h"
38
#include "drizzled/field/blob.h"
39
#include "drizzled/field/date.h"
40
#include "drizzled/field/datetime.h"
41
#include "drizzled/field/decimal.h"
42
#include "drizzled/field/double.h"
43
#include "drizzled/field/enum.h"
44
#include "drizzled/field/epoch.h"
45
#include "drizzled/field/int32.h"
46
#include "drizzled/field/int64.h"
47
#include "drizzled/field/microtime.h"
48
#include "drizzled/field/null.h"
49
#include "drizzled/field/real.h"
50
#include "drizzled/field/size.h"
51
#include "drizzled/field/time.h"
52
#include "drizzled/field/varstring.h"
54
#include "drizzled/internal/m_string.h"
236
233
/* Note that fix_fields may not be called for Item_avg_field items */
238
235
type::Decimal value, *dec_val= val_decimal(&value);
242
238
dec_val->val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
247
bool Item::save_time_in_field(Field *field)
242
int Item::save_time_in_field(Field *field)
249
244
type::Time ltime;
245
if (get_time(<ime))
252
246
return set_field_to_null(field);
254
247
field->set_notnull();
256
return field->store_time(ltime, type::DRIZZLE_TIMESTAMP_TIME);
248
return field->store_time(<ime, DRIZZLE_TIMESTAMP_TIME);
259
bool Item::save_date_in_field(Field *field)
251
int Item::save_date_in_field(Field *field)
261
253
type::Time ltime;
263
if (get_date(ltime, TIME_FUZZY_DATE))
254
if (get_date(<ime, TIME_FUZZY_DATE))
264
255
return set_field_to_null(field);
266
256
field->set_notnull();
268
return field->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
257
return field->store_time(<ime, DRIZZLE_TIMESTAMP_DATETIME);
297
284
with_sum_func(false),
298
285
is_autogenerated_name(true),
299
286
with_subselect(false),
300
collation(&my_charset_bin, DERIVATION_COERCIBLE),
301
_session(*current_session)
287
collation(&my_charset_bin, DERIVATION_COERCIBLE)
303
289
cmp_context= (Item_result)-1;
305
291
/* Put item in free list so that we can free all items at end */
306
next= getSession().free_list;
307
getSession().free_list= this;
292
Session *session= current_session;
293
next= session->free_list;
294
session->free_list= this;
310
297
Item constructor can be called during execution other then SQL_COM
311
command => we should check session->getLex()->current_select on zero (session->lex
298
command => we should check session->lex->current_select on zero (session->lex
312
299
can be uninitialised)
314
if (getSession().getLex()->current_select)
301
if (session->lex->current_select)
316
enum_parsing_place place= getSession().getLex()->current_select->parsing_place;
303
enum_parsing_place place= session->lex->current_select->parsing_place;
317
304
if (place == SELECT_LIST || place == IN_HAVING)
318
getSession().getLex()->current_select->select_n_having_items++;
305
session->lex->current_select->select_n_having_items++;
336
323
is_autogenerated_name(item->is_autogenerated_name),
337
324
with_subselect(item->with_subselect),
338
325
collation(item->collation),
339
cmp_context(item->cmp_context),
326
cmp_context(item->cmp_context)
342
328
/* Put this item in the session's free list */
343
next= getSession().free_list;
344
getSession().free_list= this;
329
next= session->free_list;
330
session->free_list= this;
347
333
uint32_t Item::float_length(uint32_t decimals_par) const
439
425
if (orig_len != length && ! is_autogenerated_name)
442
push_warning_printf(&getSession(),
428
push_warning_printf(current_session,
443
429
DRIZZLE_ERROR::WARN_LEVEL_WARN,
444
430
ER_NAME_BECOMES_EMPTY,
445
431
ER(ER_NAME_BECOMES_EMPTY),
446
432
str + length - orig_len);
448
push_warning_printf(&getSession(),
434
push_warning_printf(current_session,
449
435
DRIZZLE_ERROR::WARN_LEVEL_WARN,
450
436
ER_REMOVED_SPACES,
451
437
ER(ER_REMOVED_SPACES),
474
460
return conv->safe ? conv : NULL;
477
bool Item::get_date(type::Time <ime,uint32_t fuzzydate)
463
bool Item::get_date(type::Time *ltime,uint32_t fuzzydate)
485
else if (result_type() == STRING_RESULT)
487
char buff[type::Time::MAX_STRING_LENGTH];
488
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
489
if (!(res=val_str(&tmp)) ||
490
str_to_datetime_with_warn(&getSession(), res->ptr(), res->length(),
491
<ime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
498
int64_t value= val_int();
499
type::datetime_t date_value;
501
ltime.convert(date_value, value, fuzzydate);
503
if (not type::is_valid(date_value))
505
char buff[DECIMAL_LONGLONG_DIGITS], *end;
506
end= internal::int64_t10_to_str(value, buff, -10);
507
make_truncated_value_warning(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN,
508
buff, (int) (end-buff), type::DRIZZLE_TIMESTAMP_NONE, NULL);
465
if (result_type() == STRING_RESULT)
468
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
469
if (!(res=val_str(&tmp)) ||
470
str_to_datetime_with_warn(res->ptr(), res->length(),
471
ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
476
int64_t value= val_int();
478
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
481
end= internal::int64_t10_to_str(value, buff, -10);
482
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
483
buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
491
memset(ltime, 0, sizeof(*ltime));
521
bool Item::get_time(type::Time <ime)
495
bool Item::get_time(type::Time *ltime)
523
char buff[type::Time::MAX_STRING_LENGTH];
524
498
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
525
if (!(res=val_str(&tmp)) or
526
str_to_time_with_warn(&getSession(), res->ptr(), res->length(), <ime))
499
if (!(res=val_str(&tmp)) ||
500
str_to_time_with_warn(res->ptr(), res->length(), ltime))
502
memset(ltime, 0, sizeof(*ltime));
536
bool Item::get_date_result(type::Time <ime,uint32_t fuzzydate)
508
bool Item::get_date_result(type::Time *ltime,uint32_t fuzzydate)
538
return get_date(ltime, fuzzydate);
510
return get_date(ltime,fuzzydate);
541
513
bool Item::is_null()
1091
1063
bool Item::is_datetime()
1093
return field::isDateTime(field_type());
1065
switch (field_type())
1067
case DRIZZLE_TYPE_TIME:
1068
case DRIZZLE_TYPE_DATE:
1069
case DRIZZLE_TYPE_DATETIME:
1070
case DRIZZLE_TYPE_TIMESTAMP:
1071
case DRIZZLE_TYPE_MICROTIME:
1073
case DRIZZLE_TYPE_BLOB:
1074
case DRIZZLE_TYPE_VARCHAR:
1075
case DRIZZLE_TYPE_DOUBLE:
1076
case DRIZZLE_TYPE_DECIMAL:
1077
case DRIZZLE_TYPE_ENUM:
1078
case DRIZZLE_TYPE_LONG:
1079
case DRIZZLE_TYPE_LONGLONG:
1080
case DRIZZLE_TYPE_NULL:
1081
case DRIZZLE_TYPE_UUID:
1082
case DRIZZLE_TYPE_BOOLEAN:
1096
1090
String *Item::check_well_formed_result(String *str, bool send_error)
1197
1194
name, decimals, 0, unsigned_flag);
1199
1196
case DRIZZLE_TYPE_NULL:
1200
field= new Field_null((unsigned char*) 0, max_length, name);
1197
field= new Field_null((unsigned char*) 0, max_length, name, &my_charset_bin);
1202
1199
case DRIZZLE_TYPE_DATE:
1203
field= new Field_date(maybe_null, name);
1200
field= new Field_date(maybe_null, name, &my_charset_bin);
1206
1203
case DRIZZLE_TYPE_MICROTIME:
1211
1208
field= new field::Epoch(maybe_null, name);
1213
1210
case DRIZZLE_TYPE_DATETIME:
1214
field= new Field_datetime(maybe_null, name);
1211
field= new Field_datetime(maybe_null, name, &my_charset_bin);
1216
1213
case DRIZZLE_TYPE_TIME:
1217
field= new field::Time(maybe_null, name);
1214
field= new field::Time(maybe_null, name, &my_charset_bin);
1219
1216
case DRIZZLE_TYPE_BOOLEAN:
1220
1217
case DRIZZLE_TYPE_UUID:
1431
uint32_t Item::max_char_length() const
1433
return max_length / collation.collation->mbmaxlen;
1436
void Item::fix_length_and_charset(uint32_t max_char_length_arg, CHARSET_INFO *cs)
1438
max_length= char_to_byte_length_safe(max_char_length_arg, cs->mbmaxlen);
1439
collation.collation= cs;
1442
void Item::fix_char_length(uint32_t max_char_length_arg)
1444
max_length= char_to_byte_length_safe(max_char_length_arg, collation.collation->mbmaxlen);
1447
void Item::fix_char_length_uint64_t(uint64_t max_char_length_arg)
1449
uint64_t max_result_length= max_char_length_arg *
1450
collation.collation->mbmaxlen;
1452
if (max_result_length >= MAX_BLOB_WIDTH)
1454
max_length= MAX_BLOB_WIDTH;
1459
max_length= max_result_length;
1463
void Item::fix_length_and_charset_datetime(uint32_t max_char_length_arg)
1465
collation.set(&my_charset_bin);
1466
fix_char_length(max_char_length_arg);
1469
1428
Item_result item_cmp_type(Item_result a,Item_result b)
1471
1430
if (a == STRING_RESULT && b == STRING_RESULT)
1681
1640
case STRING_RESULT:
1682
1641
assert(item->collation.collation);
1643
enum enum_field_types type;
1685
1645
DATE/TIME fields have STRING_RESULT result type.
1686
1646
To preserve type they needed to be handled separately.
1688
if (field::isDateTime(item->field_type()))
1648
if ((type= item->field_type()) == DRIZZLE_TYPE_DATETIME ||
1649
type == DRIZZLE_TYPE_TIME ||
1650
type == DRIZZLE_TYPE_MICROTIME ||
1651
type == DRIZZLE_TYPE_DATE ||
1652
type == DRIZZLE_TYPE_TIMESTAMP)
1690
1654
new_field= item->tmp_table_field_from_field_type(table, 1);