18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
22
#include <boost/lexical_cast.hpp>
24
#include "drizzled/field/date.h"
25
#include "drizzled/error.h"
26
#include "drizzled/table.h"
27
#include "drizzled/temporal.h"
28
#include "drizzled/session.h"
29
#include "drizzled/time_functions.h"
24
#include <drizzled/field/date.h>
25
#include <drizzled/error.h>
26
#include <drizzled/table.h>
27
#include <drizzled/temporal.h>
28
#include <drizzled/session.h>
29
#include <drizzled/time_functions.h>
30
#include <drizzled/current_session.h>
31
#include <drizzled/system_variables.h>
113
115
/* Convert the integer to a string using boost::lexical_cast */
114
116
std::string tmp(boost::lexical_cast<std::string>(from));
116
my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
118
my_error(ER_INVALID_DATE_VALUE, MYF(ME_FATALERROR), tmp.c_str());
120
122
/* Create the stored integer format. @TODO This should go away. Should be up to engine... */
121
123
uint32_t int_value= (temporal.years() * 10000) + (temporal.months() * 100) + temporal.days();
122
124
int4store(ptr, int_value);
126
int Field_date::store_time(DRIZZLE_TIME *ltime,
127
enum enum_drizzle_timestamp_type time_type)
129
int Field_date::store_time(type::Time <ime,
130
type::timestamp_t time_type)
131
if (time_type == DRIZZLE_TIMESTAMP_DATE ||
132
time_type == DRIZZLE_TIMESTAMP_DATETIME)
134
if (time_type == type::DRIZZLE_TIMESTAMP_DATE || time_type == type::DRIZZLE_TIMESTAMP_DATETIME)
134
tmp= ltime->year*10000 + ltime->month*100 + ltime->day;
135
if (check_date(ltime, tmp != 0,
137
(current_session->variables.sql_mode &
138
(MODE_NO_ZERO_DATE | MODE_INVALID_DATES))), &error))
136
tmp= ltime.year*10000 + ltime.month*100 + ltime.day;
138
Session *session= getTable() ? getTable()->in_use : current_session;
139
type::cut_t cut_error= type::VALID;
140
if (ltime.check(tmp != 0,
142
(session->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))), cut_error))
140
char buff[MAX_DATE_STRING_REP_LENGTH];
144
char buff[type::Time::MAX_STRING_LENGTH];
141
145
String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
142
make_date(ltime, &str);
146
ltime.convert(str, type::DRIZZLE_TIMESTAMP_DATE);
143
147
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED,
144
str.ptr(), str.length(), DRIZZLE_TIMESTAMP_DATE, 1);
148
str.ptr(), str.length(), type::DRIZZLE_TIMESTAMP_DATE, 1);
146
if (!error && ltime->time_type != DRIZZLE_TIMESTAMP_DATE &&
147
(ltime->hour || ltime->minute || ltime->second || ltime->second_part))
151
error= static_cast<int>(cut_error);
153
if (not error && ltime.time_type != type::DRIZZLE_TIMESTAMP_DATE &&
154
(ltime.hour || ltime.minute || ltime.second || ltime.second_part))
149
char buff[MAX_DATE_STRING_REP_LENGTH];
156
char buff[type::Time::MAX_STRING_LENGTH];
150
157
String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
151
make_datetime(ltime, &str);
152
159
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE,
153
160
ER_WARN_DATA_TRUNCATED,
154
str.ptr(), str.length(), DRIZZLE_TIMESTAMP_DATE, 1);
161
str.ptr(), str.length(), type::DRIZZLE_TIMESTAMP_DATE, 1);
209
218
return val_buffer;
212
bool Field_date::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
221
bool Field_date::get_date(type::Time <ime, uint32_t fuzzydate) const
214
223
uint32_t tmp=(uint32_t) uint4korr(ptr);
215
ltime->day= (int) (tmp%100);
216
ltime->month= (int) (tmp/100%100);
217
ltime->year= (int) (tmp/10000);
218
ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
219
ltime->hour= ltime->minute= ltime->second= ltime->second_part= ltime->neg= 0;
220
return ((!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ?
224
ltime.day= (int) (tmp%100);
225
ltime.month= (int) (tmp/100%100);
226
ltime.year= (int) (tmp/10000);
227
ltime.time_type= type::DRIZZLE_TIMESTAMP_DATE;
228
ltime.hour= ltime.minute= ltime.second= ltime.second_part= ltime.neg= 0;
230
return ((!(fuzzydate & TIME_FUZZY_DATE) && (!ltime.month || !ltime.day)) ?
224
bool Field_date::get_time(DRIZZLE_TIME *ltime)
234
bool Field_date::get_time(type::Time <ime) const
226
return Field_date::get_date(ltime,0);
236
return Field_date::get_date(ltime ,0);
229
239
int Field_date::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)