32
31
#include "drizzled/field/str.h"
33
32
#include "drizzled/field/num.h"
34
33
#include "drizzled/field/blob.h"
35
#include "drizzled/field/boolean.h"
36
34
#include "drizzled/field/enum.h"
37
35
#include "drizzled/field/null.h"
38
36
#include "drizzled/field/date.h"
45
43
#include "drizzled/field/time.h"
46
44
#include "drizzled/field/epoch.h"
47
45
#include "drizzled/field/datetime.h"
48
#include "drizzled/field/microtime.h"
49
46
#include "drizzled/field/varstring.h"
50
47
#include "drizzled/field/uuid.h"
51
48
#include "drizzled/time_functions.h"
827
702
unsigned char *null_ptr_arg,
828
703
unsigned char null_bit_arg,
829
704
utype unireg_check_arg,
830
const char *field_name_arg) :
705
const char *field_name_arg)
832
708
null_ptr(null_ptr_arg),
834
710
orig_table(NULL),
835
711
field_name(field_name_arg),
836
comment(NULL_LEX_STRING),
839
714
part_of_key_not_clustered(0),
840
715
part_of_sortkey(0),
841
716
unireg_check(unireg_check_arg),
842
717
field_length(length_arg),
843
flags(null_ptr ? 0: NOT_NULL_FLAG),
845
718
null_bit(null_bit_arg),
846
719
is_created_from_null_item(false)
721
flags= null_ptr ? 0: NOT_NULL_FLAG;
722
comment.str= (char*) "";
850
727
void Field::hash(uint32_t *nr, uint32_t *nr2)
974
851
field->decimals= 0;
977
int64_t Field::convert_decimal2int64_t(const type::Decimal *val, bool, int *err)
854
int64_t Field::convert_decimal2int64_t(const my_decimal *val, bool, int *err)
980
if (warn_if_overflow(val->val_int32(E_DEC_ERROR &
857
if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
981
858
~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
984
861
i= (val->sign() ? INT64_MIN : INT64_MAX);
1008
885
return copy->length+ store_length;
1011
bool Field::get_date(type::Time <ime, uint32_t fuzzydate)
1013
char buff[type::Time::MAX_STRING_LENGTH];
1014
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1016
assert(getTable() and getTable()->getSession());
1018
if (not (res=val_str_internal(&tmp)) or
1019
str_to_datetime_with_warn(getTable()->getSession(),
1020
res->ptr(), res->length(),
1021
<ime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
1029
bool Field::get_time(type::Time <ime)
1031
char buff[type::Time::MAX_STRING_LENGTH];
1032
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1034
if (not (res= val_str_internal(&tmp)) or
1035
str_to_time_with_warn(getTable()->getSession(), res->ptr(), res->length(), <ime))
1043
int Field::store_time(type::Time <ime, type::timestamp_t)
1049
return store(tmp.ptr(), tmp.length(), &my_charset_bin);
888
bool Field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
891
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
892
if (!(res=val_str_internal(&tmp)) || str_to_datetime_with_warn(res->ptr(), res->length(),
893
ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
901
bool Field::get_time(DRIZZLE_TIME *ltime)
904
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
906
if (!(res=val_str_internal(&tmp)) || str_to_time_with_warn(res->ptr(), res->length(), ltime))
914
int Field::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
916
char buff[MAX_DATE_STRING_REP_LENGTH];
917
uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
918
return store(buff, length, &my_charset_bin);
1052
921
bool Field::optimize_range(uint32_t idx, uint32_t)
1118
987
if (!Field::eq_def(field))
1121
989
TYPELIB *from_lib=((Field_enum*) field)->typelib;
1123
991
if (typelib->count < from_lib->count)
1126
993
for (uint32_t i=0 ; i < from_lib->count ; i++)
1128
994
if (my_strnncoll(field_charset,
1129
995
(const unsigned char*)typelib->type_names[i],
1130
996
strlen(typelib->type_names[i]),
1131
997
(const unsigned char*)from_lib->type_names[i],
1132
998
strlen(from_lib->type_names[i])))
1141
1005
switch (type) {
1142
1006
case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
1143
1007
case DRIZZLE_TYPE_UUID: return field::Uuid::max_string_length();
1144
case DRIZZLE_TYPE_MICROTIME: return field::Microtime::max_string_length();
1145
case DRIZZLE_TYPE_TIMESTAMP: return field::Epoch::max_string_length();
1146
case DRIZZLE_TYPE_BOOLEAN: return field::Boolean::max_string_length();
1147
1008
case DRIZZLE_TYPE_DATE:
1148
1009
case DRIZZLE_TYPE_ENUM:
1149
1010
case DRIZZLE_TYPE_LONG: return 4;
1150
1011
case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
1151
1012
case DRIZZLE_TYPE_TIME:
1152
1013
case DRIZZLE_TYPE_DATETIME:
1014
case DRIZZLE_TYPE_TIMESTAMP:
1153
1015
case DRIZZLE_TYPE_LONGLONG: return 8; /* Don't crash if no int64_t */
1154
1016
case DRIZZLE_TYPE_NULL: return 0;
1155
1017
case DRIZZLE_TYPE_BLOB: return 4 + portable_sizeof_char_ptr;
1200
1062
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1201
drizzled::error_t code,
1202
1064
const char *str,
1203
1065
uint32_t str_length,
1204
type::timestamp_t ts_type,
1066
enum enum_drizzle_timestamp_type ts_type,
1205
1067
int cuted_increment)
1207
Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1209
if ((session->abortOnWarning() and
1069
Session *session= table ? table->in_use : current_session;
1070
if ((session->really_abort_on_warning() &&
1210
1071
level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
1211
1072
set_warning(level, code, cuted_increment))
1212
1073
make_truncated_value_warning(session, level, str, str_length, ts_type,
1216
1077
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1217
drizzled::error_t code,
1219
type::timestamp_t ts_type,
1080
enum enum_drizzle_timestamp_type ts_type,
1220
1081
int cuted_increment)
1222
Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1224
if (session->abortOnWarning() or
1083
Session *session= table ? table->in_use : current_session;
1084
if (session->really_abort_on_warning() ||
1225
1085
set_warning(level, code, cuted_increment))
1227
char str_nr[DECIMAL_LONGLONG_DIGITS];
1228
1088
char *str_end= internal::int64_t10_to_str(nr, str_nr, -10);
1229
1089
make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
1230
1090
ts_type, field_name);
1234
1094
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1235
const drizzled::error_t code,
1095
const uint32_t code,
1237
type::timestamp_t ts_type)
1097
enum enum_drizzle_timestamp_type ts_type)
1239
Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1241
if (session->abortOnWarning() or
1099
Session *session= table ? table->in_use : current_session;
1100
if (session->really_abort_on_warning() ||
1242
1101
set_warning(level, code, 1))
1244
1103
/* DBL_DIG is enough to print '-[digits].E+###' */
1283
1142
int64_tstore(destination, arg);
1286
void Field::pack_num(uint32_t arg, unsigned char *destination)
1288
if (not destination)
1291
longstore(destination, arg);
1294
1145
uint64_t Field::unpack_num(uint64_t &destination, const unsigned char *arg) const