18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
21
#include "drizzled/server_includes.h"
23
22
#include "drizzled/field/date.h"
24
23
#include "drizzled/error.h"
112
int Field_date::store(double nr)
114
if (nr < 0.0 || nr > 99991231235959.0)
116
int3store(ptr,(int32_t) 0);
117
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
118
ER_WARN_DATA_TRUNCATED, nr, DRIZZLE_TIMESTAMP_DATE);
121
return Field_date::store((int64_t) rint(nr), false);
125
int Field_date::store(int64_t nr,
131
Session *session= table ? table->in_use : current_session;
132
if (number_to_datetime(nr, &l_time,
134
(session->variables.sql_mode &
135
(MODE_NO_ZERO_DATE | MODE_INVALID_DATES))),
136
&error) == INT64_C(-1))
142
tmp= l_time.day + l_time.month*32 + l_time.year*16*32;
144
if (!error && l_time.time_type != DRIZZLE_TIMESTAMP_DATE &&
145
(l_time.hour || l_time.minute || l_time.second || l_time.second_part))
149
set_datetime_warning(error == 3 ? DRIZZLE_ERROR::WARN_LEVEL_NOTE :
150
DRIZZLE_ERROR::WARN_LEVEL_WARN,
152
ER_WARN_DATA_OUT_OF_RANGE : ER_WARN_DATA_TRUNCATED,
153
nr,DRIZZLE_TIMESTAMP_DATE, 1);
113
int Field_date::store(double from)
115
if (from < 0.0 || from > 99991231235959.0)
117
/* Convert the double to a string using stringstream */
118
std::stringstream ss;
120
ss.precision(18); /* 18 places should be fine for error display of double input. */
121
ss << from; ss >> tmp;
123
my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
126
return Field_date::store((int64_t) rint(from), false);
129
int Field_date::store(int64_t from, bool)
132
* Try to create a DateTime from the supplied integer. Throw an error
133
* if unable to create a valid DateTime.
135
drizzled::DateTime temporal;
136
if (! temporal.from_int64_t(from))
138
/* Convert the integer to a string using stringstream */
139
std::stringstream ss;
141
ss << from; ss >> tmp;
143
my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
147
/* Create the stored integer format. @TODO This should go away. Should be up to engine... */
148
uint32_t int_value= (temporal.years() * 16 * 32) + (temporal.months() * 32) + temporal.days();
149
int3store(ptr, int_value);
160
153
int Field_date::store_time(DRIZZLE_TIME *ltime,
161
154
enum enum_drizzle_timestamp_type time_type)