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>
30
#include <drizzled/current_session.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"
114
113
/* Convert the integer to a string using boost::lexical_cast */
115
114
std::string tmp(boost::lexical_cast<std::string>(from));
117
my_error(ER_INVALID_DATE_VALUE, MYF(ME_FATALERROR), tmp.c_str());
116
my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
121
120
/* Create the stored integer format. @TODO This should go away. Should be up to engine... */
122
121
uint32_t int_value= (temporal.years() * 10000) + (temporal.months() * 100) + temporal.days();
123
122
int4store(ptr, int_value);
128
int Field_date::store_time(type::Time <ime,
129
type::timestamp_t time_type)
126
int Field_date::store_time(type::Time *ltime,
127
enum enum_drizzle_timestamp_type time_type)
133
if (time_type == type::DRIZZLE_TIMESTAMP_DATE || time_type == type::DRIZZLE_TIMESTAMP_DATETIME)
131
if (time_type == DRIZZLE_TIMESTAMP_DATE ||
132
time_type == DRIZZLE_TIMESTAMP_DATETIME)
135
tmp= ltime.year*10000 + ltime.month*100 + ltime.day;
137
Session *session= getTable() ? getTable()->in_use : current_session;
138
type::cut_t cut_error= type::VALID;
139
if (ltime.check(tmp != 0,
141
(session->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))), cut_error))
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))
143
char buff[type::Time::MAX_STRING_LENGTH];
140
char buff[MAX_DATE_STRING_REP_LENGTH];
144
141
String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
145
ltime.convert(str, type::DRIZZLE_TIMESTAMP_DATE);
142
make_date(ltime, &str);
146
143
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED,
147
str.ptr(), str.length(), type::DRIZZLE_TIMESTAMP_DATE, 1);
144
str.ptr(), str.length(), DRIZZLE_TIMESTAMP_DATE, 1);
150
error= static_cast<int>(cut_error);
152
if (not error && ltime.time_type != type::DRIZZLE_TIMESTAMP_DATE &&
153
(ltime.hour || ltime.minute || ltime.second || ltime.second_part))
146
if (!error && ltime->time_type != DRIZZLE_TIMESTAMP_DATE &&
147
(ltime->hour || ltime->minute || ltime->second || ltime->second_part))
155
char buff[type::Time::MAX_STRING_LENGTH];
149
char buff[MAX_DATE_STRING_REP_LENGTH];
156
150
String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
151
make_datetime(ltime, &str);
158
152
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE,
159
153
ER_WARN_DATA_TRUNCATED,
160
str.ptr(), str.length(), type::DRIZZLE_TIMESTAMP_DATE, 1);
154
str.ptr(), str.length(), DRIZZLE_TIMESTAMP_DATE, 1);
217
209
return val_buffer;
220
bool Field_date::get_date(type::Time <ime, uint32_t fuzzydate) const
212
bool Field_date::get_date(type::Time *ltime,uint32_t fuzzydate)
222
214
uint32_t tmp=(uint32_t) uint4korr(ptr);
223
ltime.day= (int) (tmp%100);
224
ltime.month= (int) (tmp/100%100);
225
ltime.year= (int) (tmp/10000);
226
ltime.time_type= type::DRIZZLE_TIMESTAMP_DATE;
227
ltime.hour= ltime.minute= ltime.second= ltime.second_part= ltime.neg= 0;
229
return ((!(fuzzydate & TIME_FUZZY_DATE) && (!ltime.month || !ltime.day)) ?
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)) ?
233
bool Field_date::get_time(type::Time <ime) const
224
bool Field_date::get_time(type::Time *ltime)
235
return Field_date::get_date(ltime ,0);
226
return Field_date::get_date(ltime,0);
238
229
int Field_date::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)