39
40
** In string context: YYYY-MM-DD HH:MM:DD
40
41
** In number context: YYYYMMDDHHMMDD
41
** Stored as a 8 byte unsigned int. Should sometimes be change to a 6 byte int.
42
42
****************************************************************************/
44
44
int Field_datetime::store(const char *from,
61
61
temporal.to_int64_t(&int_value);
63
63
#ifdef WORDS_BIGENDIAN
64
if (getTable() && getTable()->s->db_low_byte_first)
64
if (getTable() && getTable()->isDatabaseLowByteFirst())
66
66
int8store(ptr, int_value);
76
76
ASSERT_COLUMN_MARKED_FOR_WRITE;
77
77
if (from < 0.0 || from > 99991231235959.0)
79
/* Convert the double to a string using stringstream */
82
ss.precision(18); /* 18 places should be fine for error display of double input. */
83
ss << from; ss >> tmp;
79
/* Convert the double to a string using boost::lexical_cast */
80
std::string tmp(boost::lexical_cast<std::string>(from));
85
82
my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
99
96
if (! temporal.from_int64_t(from))
101
/* Convert the integer to a string using stringstream */
102
std::stringstream ss;
104
ss << from; ss >> tmp;
98
/* Convert the integer to a string using boost::lexical_cast */
99
std::string tmp(boost::lexical_cast<std::string>(from));
106
101
my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
116
111
temporal.to_int64_t(&int_value);
118
113
#ifdef WORDS_BIGENDIAN
119
if (getTable() && getTable()->s->db_low_byte_first)
114
if (getTable() && getTable()->isDatabaseLowByteFirst())
121
116
int8store(ptr, int_value);
129
int Field_datetime::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
124
int Field_datetime::store_time(type::Time <ime, type::timestamp_t)
131
126
DateTime temporal;
133
temporal.set_years(ltime->year);
134
temporal.set_months(ltime->month);
135
temporal.set_days(ltime->day);
136
temporal.set_hours(ltime->hour);
137
temporal.set_minutes(ltime->minute);
138
temporal.set_seconds(ltime->second);
128
temporal.set_years(ltime.year);
129
temporal.set_months(ltime.month);
130
temporal.set_days(ltime.day);
131
temporal.set_hours(ltime.hour);
132
temporal.set_minutes(ltime.minute);
133
temporal.set_seconds(ltime.second);
140
135
if (! temporal.is_valid())
142
char tmp_string[MAX_DATE_STRING_REP_LENGTH];
137
char tmp_string[type::Time::MAX_STRING_LENGTH];
143
138
size_t tmp_string_len;
145
tmp_string_len= temporal.to_string(tmp_string, MAX_DATE_STRING_REP_LENGTH);
146
assert(tmp_string_len < MAX_DATE_STRING_REP_LENGTH);
140
tmp_string_len= temporal.to_string(tmp_string, type::Time::MAX_STRING_LENGTH);
141
assert(tmp_string_len < type::Time::MAX_STRING_LENGTH);
147
142
my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp_string);
152
147
temporal.to_int64_t(&int_value);
154
149
#ifdef WORDS_BIGENDIAN
155
if (getTable() && getTable()->s->db_low_byte_first)
150
if (getTable() && getTable()->isDatabaseLowByteFirst())
157
152
int8store(ptr, int_value);
161
156
int64_tstore(ptr, int_value);
207
203
* not null without a default value.
209
205
dt.from_int64_t(tmp, false); /* NOTE: this does *NOT* attempt convertion
210
from formats such as 20090101 as
211
the stored value has already been
206
from formats such as 20090101 as
207
the stored value has already been
216
212
rlen= dt.to_string((char*)val_buffer->ptr(), DateTime::MAX_STRING_LENGTH);
221
217
return val_buffer;
224
bool Field_datetime::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
220
bool Field_datetime::get_date(type::Time <ime, uint32_t fuzzydate)
226
222
int64_t tmp=Field_datetime::val_int();
227
223
uint32_t part1,part2;
228
224
part1=(uint32_t) (tmp/INT64_C(1000000));
229
225
part2=(uint32_t) (tmp - (uint64_t) part1*INT64_C(1000000));
231
ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME;
233
ltime->second_part= 0;
234
ltime->second= (int) (part2%100);
235
ltime->minute= (int) (part2/100%100);
236
ltime->hour= (int) (part2/10000);
237
ltime->day= (int) (part1%100);
238
ltime->month= (int) (part1/100%100);
239
ltime->year= (int) (part1/10000);
240
return (!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ? 1 : 0;
227
ltime.time_type= type::DRIZZLE_TIMESTAMP_DATETIME;
229
ltime.second_part= 0;
230
ltime.second= (int) (part2%100);
231
ltime.minute= (int) (part2/100%100);
232
ltime.hour= (int) (part2/10000);
233
ltime.day= (int) (part1%100);
234
ltime.month= (int) (part1/100%100);
235
ltime.year= (int) (part1/10000);
237
return (!(fuzzydate & TIME_FUZZY_DATE) && (!ltime.month || !ltime.day)) ? 1 : 0;
243
bool Field_datetime::get_time(DRIZZLE_TIME *ltime)
240
bool Field_datetime::get_time(type::Time <ime)
245
242
return Field_datetime::get_date(ltime,0);