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"
297
294
with_sum_func(false),
298
295
is_autogenerated_name(true),
299
296
with_subselect(false),
300
collation(&my_charset_bin, DERIVATION_COERCIBLE),
301
_session(*current_session)
297
collation(&my_charset_bin, DERIVATION_COERCIBLE)
303
299
cmp_context= (Item_result)-1;
305
301
/* Put item in free list so that we can free all items at end */
306
next= getSession().free_list;
307
getSession().free_list= this;
302
Session *session= current_session;
303
next= session->free_list;
304
session->free_list= this;
310
307
Item constructor can be called during execution other then SQL_COM
311
command => we should check session->getLex()->current_select on zero (session->lex
308
command => we should check session->lex->current_select on zero (session->lex
312
309
can be uninitialised)
314
if (getSession().getLex()->current_select)
311
if (session->lex->current_select)
316
enum_parsing_place place= getSession().getLex()->current_select->parsing_place;
313
enum_parsing_place place= session->lex->current_select->parsing_place;
317
314
if (place == SELECT_LIST || place == IN_HAVING)
318
getSession().getLex()->current_select->select_n_having_items++;
315
session->lex->current_select->select_n_having_items++;
336
333
is_autogenerated_name(item->is_autogenerated_name),
337
334
with_subselect(item->with_subselect),
338
335
collation(item->collation),
339
cmp_context(item->cmp_context),
336
cmp_context(item->cmp_context)
342
338
/* Put this item in the session's free list */
343
next= getSession().free_list;
344
getSession().free_list= this;
339
next= session->free_list;
340
session->free_list= this;
347
343
uint32_t Item::float_length(uint32_t decimals_par) const
439
435
if (orig_len != length && ! is_autogenerated_name)
442
push_warning_printf(&getSession(),
438
push_warning_printf(current_session,
443
439
DRIZZLE_ERROR::WARN_LEVEL_WARN,
444
440
ER_NAME_BECOMES_EMPTY,
445
441
ER(ER_NAME_BECOMES_EMPTY),
446
442
str + length - orig_len);
448
push_warning_printf(&getSession(),
444
push_warning_printf(current_session,
449
445
DRIZZLE_ERROR::WARN_LEVEL_WARN,
450
446
ER_REMOVED_SPACES,
451
447
ER(ER_REMOVED_SPACES),
485
481
else if (result_type() == STRING_RESULT)
487
char buff[type::Time::MAX_STRING_LENGTH];
488
484
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
489
485
if (!(res=val_str(&tmp)) ||
490
str_to_datetime_with_warn(&getSession(), res->ptr(), res->length(),
486
str_to_datetime_with_warn(current_session, res->ptr(), res->length(),
491
487
<ime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
503
499
if (not type::is_valid(date_value))
505
char buff[DECIMAL_LONGLONG_DIGITS], *end;
506
502
end= internal::int64_t10_to_str(value, buff, -10);
507
make_truncated_value_warning(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN,
503
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
508
504
buff, (int) (end-buff), type::DRIZZLE_TIMESTAMP_NONE, NULL);
1091
1086
bool Item::is_datetime()
1093
return field::isDateTime(field_type());
1088
switch (field_type())
1090
case DRIZZLE_TYPE_TIME:
1091
case DRIZZLE_TYPE_DATE:
1092
case DRIZZLE_TYPE_DATETIME:
1093
case DRIZZLE_TYPE_TIMESTAMP:
1094
case DRIZZLE_TYPE_MICROTIME:
1096
case DRIZZLE_TYPE_BLOB:
1097
case DRIZZLE_TYPE_VARCHAR:
1098
case DRIZZLE_TYPE_DOUBLE:
1099
case DRIZZLE_TYPE_DECIMAL:
1100
case DRIZZLE_TYPE_ENUM:
1101
case DRIZZLE_TYPE_LONG:
1102
case DRIZZLE_TYPE_LONGLONG:
1103
case DRIZZLE_TYPE_NULL:
1104
case DRIZZLE_TYPE_UUID:
1105
case DRIZZLE_TYPE_BOOLEAN:
1096
1113
String *Item::check_well_formed_result(String *str, bool send_error)
1197
1217
name, decimals, 0, unsigned_flag);
1199
1219
case DRIZZLE_TYPE_NULL:
1200
field= new Field_null((unsigned char*) 0, max_length, name);
1220
field= new Field_null((unsigned char*) 0, max_length, name, &my_charset_bin);
1202
1222
case DRIZZLE_TYPE_DATE:
1203
field= new Field_date(maybe_null, name);
1223
field= new Field_date(maybe_null, name, &my_charset_bin);
1206
1226
case DRIZZLE_TYPE_MICROTIME:
1211
1231
field= new field::Epoch(maybe_null, name);
1213
1233
case DRIZZLE_TYPE_DATETIME:
1214
field= new Field_datetime(maybe_null, name);
1234
field= new Field_datetime(maybe_null, name, &my_charset_bin);
1216
1236
case DRIZZLE_TYPE_TIME:
1217
field= new field::Time(maybe_null, name);
1237
field= new field::Time(maybe_null, name, &my_charset_bin);
1219
1239
case DRIZZLE_TYPE_BOOLEAN:
1220
1240
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
1451
Item_result item_cmp_type(Item_result a,Item_result b)
1471
1453
if (a == STRING_RESULT && b == STRING_RESULT)
1681
1663
case STRING_RESULT:
1682
1664
assert(item->collation.collation);
1666
enum enum_field_types type;
1685
1668
DATE/TIME fields have STRING_RESULT result type.
1686
1669
To preserve type they needed to be handled separately.
1688
if (field::isDateTime(item->field_type()))
1671
if ((type= item->field_type()) == DRIZZLE_TYPE_DATETIME ||
1672
type == DRIZZLE_TYPE_TIME ||
1673
type == DRIZZLE_TYPE_MICROTIME ||
1674
type == DRIZZLE_TYPE_DATE ||
1675
type == DRIZZLE_TYPE_TIMESTAMP)
1690
1677
new_field= item->tmp_table_field_from_field_type(table, 1);