1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
4
5
* Copyright (C) 2008 MySQL
6
7
* This program is free software; you can redistribute it and/or modify
31
32
#include "drizzled/field/str.h"
32
33
#include "drizzled/field/num.h"
33
34
#include "drizzled/field/blob.h"
35
#include "drizzled/field/boolean.h"
34
36
#include "drizzled/field/enum.h"
35
37
#include "drizzled/field/null.h"
36
38
#include "drizzled/field/date.h"
40
42
#include "drizzled/field/int32.h"
41
43
#include "drizzled/field/int64.h"
42
44
#include "drizzled/field/num.h"
43
#include "drizzled/field/timestamp.h"
45
#include "drizzled/field/time.h"
46
#include "drizzled/field/epoch.h"
44
47
#include "drizzled/field/datetime.h"
48
#include "drizzled/field/microtime.h"
45
49
#include "drizzled/field/varstring.h"
46
50
#include "drizzled/field/uuid.h"
47
51
#include "drizzled/time_functions.h"
795
976
field->decimals= 0;
798
int64_t Field::convert_decimal2int64_t(const my_decimal *val, bool, int *err)
979
int64_t Field::convert_decimal2int64_t(const type::Decimal *val, bool, int *err)
801
if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
982
if (warn_if_overflow(val->val_int32(E_DEC_ERROR &
802
983
~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
805
986
i= (val->sign() ? INT64_MIN : INT64_MAX);
829
1010
return copy->length+ store_length;
832
bool Field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1013
bool Field::get_date(type::Time <ime,uint32_t fuzzydate)
835
1016
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
836
1017
if (!(res=val_str_internal(&tmp)) || str_to_datetime_with_warn(res->ptr(), res->length(),
837
ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
1018
<ime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
845
bool Field::get_time(DRIZZLE_TIME *ltime)
1026
bool Field::get_time(type::Time <ime)
848
1029
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
850
if (!(res=val_str_internal(&tmp)) || str_to_time_with_warn(res->ptr(), res->length(), ltime))
1031
if (!(res=val_str_internal(&tmp)) || str_to_time_with_warn(res->ptr(), res->length(), <ime))
858
int Field::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
1039
int Field::store_time(type::Time <ime, type::timestamp_t)
860
char buff[MAX_DATE_STRING_REP_LENGTH];
861
uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
862
return store(buff, length, &my_charset_bin);
1045
return store(tmp.ptr(), tmp.length(), &my_charset_bin);
865
1048
bool Field::optimize_range(uint32_t idx, uint32_t)
931
1114
if (!Field::eq_def(field))
933
1117
TYPELIB *from_lib=((Field_enum*) field)->typelib;
935
1119
if (typelib->count < from_lib->count)
937
1122
for (uint32_t i=0 ; i < from_lib->count ; i++)
938
1124
if (my_strnncoll(field_charset,
939
1125
(const unsigned char*)typelib->type_names[i],
940
1126
strlen(typelib->type_names[i]),
941
1127
(const unsigned char*)from_lib->type_names[i],
942
1128
strlen(from_lib->type_names[i])))
950
1138
case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
951
1139
case DRIZZLE_TYPE_UUID: return field::Uuid::max_string_length();
1140
case DRIZZLE_TYPE_MICROTIME: return field::Microtime::max_string_length();
1141
case DRIZZLE_TYPE_TIMESTAMP: return field::Epoch::max_string_length();
1142
case DRIZZLE_TYPE_BOOLEAN: return field::Boolean::max_string_length();
952
1143
case DRIZZLE_TYPE_DATE:
953
1144
case DRIZZLE_TYPE_ENUM:
954
1145
case DRIZZLE_TYPE_LONG: return 4;
955
1146
case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
1147
case DRIZZLE_TYPE_TIME:
956
1148
case DRIZZLE_TYPE_DATETIME:
957
case DRIZZLE_TYPE_TIMESTAMP:
958
1149
case DRIZZLE_TYPE_LONGLONG: return 8; /* Don't crash if no int64_t */
959
1150
case DRIZZLE_TYPE_NULL: return 0;
960
1151
case DRIZZLE_TYPE_BLOB: return 4 + portable_sizeof_char_ptr;
961
1152
case DRIZZLE_TYPE_DECIMAL:
1006
1196
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1197
drizzled::error_t code,
1008
1198
const char *str,
1009
1199
uint32_t str_length,
1010
enum enum_drizzle_timestamp_type ts_type,
1200
type::timestamp_t ts_type,
1011
1201
int cuted_increment)
1013
1203
Session *session= table ? table->in_use : current_session;
1021
1211
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1212
drizzled::error_t code,
1024
enum enum_drizzle_timestamp_type ts_type,
1214
type::timestamp_t ts_type,
1025
1215
int cuted_increment)
1027
1217
Session *session= table ? table->in_use : current_session;
1038
1228
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1039
const uint32_t code,
1229
const drizzled::error_t code,
1041
enum enum_drizzle_timestamp_type ts_type)
1231
type::timestamp_t ts_type)
1043
1233
Session *session= table ? table->in_use : current_session;
1044
1234
if (session->really_abort_on_warning() ||
1078
1268
table->clearWriteSet(field_index);
1271
void Field::pack_num(uint64_t arg, unsigned char *destination)
1273
if (not destination)
1276
int64_tstore(destination, arg);
1279
void Field::pack_num(uint32_t arg, unsigned char *destination)
1281
if (not destination)
1284
longstore(destination, arg);
1287
uint64_t Field::unpack_num(uint64_t &destination, const unsigned char *arg) const
1292
int64_tget(destination, arg);
1297
uint32_t Field::unpack_num(uint32_t &destination, const unsigned char *arg) const
1302
longget(destination, arg);
1081
1307
std::ostream& operator<<(std::ostream& output, const Field &field)
1083
1309
output << "Field:(";
1084
1310
output << field.field_name;
1085
1311
output << ", ";
1086
1312
output << drizzled::display::type(field.real_type());
1315
if (field.flags & NOT_NULL_FLAG)
1316
output << " NOT_NULL";
1318
if (field.flags & PRI_KEY_FLAG)
1319
output << ", PRIMARY KEY";
1321
if (field.flags & UNIQUE_KEY_FLAG)
1322
output << ", UNIQUE KEY";
1324
if (field.flags & MULTIPLE_KEY_FLAG)
1325
output << ", MULTIPLE KEY";
1327
if (field.flags & BLOB_FLAG)
1330
if (field.flags & UNSIGNED_FLAG)
1331
output << ", UNSIGNED";
1333
if (field.flags & BINARY_FLAG)
1334
output << ", BINARY";
1089
1338
return output; // for multiple << operators.