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"
439
436
if (orig_len != length && ! is_autogenerated_name)
442
push_warning_printf(&getSession(),
439
push_warning_printf(current_session,
443
440
DRIZZLE_ERROR::WARN_LEVEL_WARN,
444
441
ER_NAME_BECOMES_EMPTY,
445
442
ER(ER_NAME_BECOMES_EMPTY),
446
443
str + length - orig_len);
448
push_warning_printf(&getSession(),
445
push_warning_printf(current_session,
449
446
DRIZZLE_ERROR::WARN_LEVEL_WARN,
450
447
ER_REMOVED_SPACES,
451
448
ER(ER_REMOVED_SPACES),
485
482
else if (result_type() == STRING_RESULT)
487
char buff[type::Time::MAX_STRING_LENGTH];
488
485
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
489
486
if (!(res=val_str(&tmp)) ||
490
str_to_datetime_with_warn(&getSession(), res->ptr(), res->length(),
487
str_to_datetime_with_warn(current_session, res->ptr(), res->length(),
491
488
<ime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
503
500
if (not type::is_valid(date_value))
505
char buff[DECIMAL_LONGLONG_DIGITS], *end;
506
503
end= internal::int64_t10_to_str(value, buff, -10);
507
make_truncated_value_warning(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN,
504
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
508
505
buff, (int) (end-buff), type::DRIZZLE_TIMESTAMP_NONE, NULL);
521
518
bool Item::get_time(type::Time <ime)
523
char buff[type::Time::MAX_STRING_LENGTH];
524
521
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
525
522
if (!(res=val_str(&tmp)) or
526
str_to_time_with_warn(&getSession(), res->ptr(), res->length(), <ime))
523
str_to_time_with_warn(current_session, res->ptr(), res->length(), <ime))
1091
1088
bool Item::is_datetime()
1093
return field::isDateTime(field_type());
1090
switch (field_type())
1092
case DRIZZLE_TYPE_TIME:
1093
case DRIZZLE_TYPE_DATE:
1094
case DRIZZLE_TYPE_DATETIME:
1095
case DRIZZLE_TYPE_TIMESTAMP:
1096
case DRIZZLE_TYPE_MICROTIME:
1098
case DRIZZLE_TYPE_BLOB:
1099
case DRIZZLE_TYPE_VARCHAR:
1100
case DRIZZLE_TYPE_DOUBLE:
1101
case DRIZZLE_TYPE_DECIMAL:
1102
case DRIZZLE_TYPE_ENUM:
1103
case DRIZZLE_TYPE_LONG:
1104
case DRIZZLE_TYPE_LONGLONG:
1105
case DRIZZLE_TYPE_NULL:
1106
case DRIZZLE_TYPE_UUID:
1107
case DRIZZLE_TYPE_BOOLEAN:
1096
1115
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);