18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include <drizzled/server_includes.h>
23
#include <drizzled/field/datetime.h>
24
#include <drizzled/error.h>
25
#include <drizzled/table.h>
26
#include <drizzled/session.h>
21
#include "drizzled/server_includes.h"
22
#include "drizzled/field/datetime.h"
23
#include "drizzled/error.h"
24
#include "drizzled/table.h"
25
#include "drizzled/temporal.h"
26
#include "drizzled/session.h"
29
33
#if defined(CMATH_NAMESPACE)
72
77
int64_tstore(ptr,tmp);
77
int Field_datetime::store(double nr)
80
if (nr < 0.0 || nr > 99991231235959.0)
82
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
83
ER_WARN_DATA_OUT_OF_RANGE,
84
nr, DRIZZLE_TIMESTAMP_DATETIME);
88
error|= Field_datetime::store((int64_t) rint(nr), false);
93
int Field_datetime::store(int64_t nr,
96
DRIZZLE_TIME not_used;
98
int64_t initial_nr= nr;
99
Session *session= table ? table->in_use : current_session;
101
nr= number_to_datetime(nr, ¬_used, (TIME_FUZZY_DATE |
102
(session->variables.sql_mode &
104
MODE_INVALID_DATES))), &error);
106
if (nr == INT64_C(-1))
113
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
114
error == 2 ? ER_WARN_DATA_OUT_OF_RANGE :
115
ER_WARN_DATA_TRUNCATED, initial_nr,
116
DRIZZLE_TIMESTAMP_DATETIME, 1);
118
#ifdef WORDS_BIGENDIAN
119
if (table && table->s->db_low_byte_first)
125
int64_tstore(ptr,nr);
78
#endif /* NOTDEFINED */
80
* Try to create a DateTime from the supplied string. Throw an error
81
* if unable to create a valid DateTime.
83
drizzled::DateTime temporal;
84
if (! temporal.from_string(from, (size_t) len))
86
my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), from);
89
/* Create the stored integer format. @TODO This should go away. Should be up to engine... */
91
temporal.to_int64_t(&int_value);
93
#ifdef WORDS_BIGENDIAN
94
if (table && table->s->db_low_byte_first)
96
int8store(ptr, int_value);
100
int64_tstore(ptr, int_value);
104
int Field_datetime::store(double from)
106
if (from < 0.0 || from > 99991231235959.0)
108
/* Convert the double to a string using stringstream */
109
std::stringstream ss;
111
ss.precision(18); /* 18 places should be fine for error display of double input. */
112
ss << from; ss >> tmp;
114
my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
117
return Field_datetime::store((int64_t) rint(from), false);
120
int Field_datetime::store(int64_t from, bool)
123
* Try to create a DateTime from the supplied integer. Throw an error
124
* if unable to create a valid DateTime.
126
drizzled::DateTime temporal;
127
if (! temporal.from_int64_t(from))
129
/* Convert the integer to a string using stringstream */
130
std::stringstream ss;
132
ss << from; ss >> tmp;
134
my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
139
* Because "from" may be a silly MySQL-like "datetime number" (like, oh, 101)
140
* we must here get the value of the DateTime as its *real* int64_t, after
141
* the conversion above has been done...yuck. God, save us.
144
temporal.to_int64_t(&int_value);
146
#ifdef WORDS_BIGENDIAN
147
if (table && table->s->db_low_byte_first)
149
int8store(ptr, int_value);
153
int64_tstore(ptr, int_value);
130
157
int Field_datetime::store_time(DRIZZLE_TIME *ltime,
131
158
enum enum_drizzle_timestamp_type time_type)