22 #include <boost/lexical_cast.hpp>
24 #include <drizzled/field/date.h>
25 #include <drizzled/error.h>
26 #include <drizzled/table.h>
28 #include <drizzled/session.h>
29 #include <drizzled/time_functions.h>
30 #include <drizzled/current_session.h>
31 #include <drizzled/system_variables.h>
65 int Field_date::store(
const char *from,
67 const charset_info_st *
const )
75 ASSERT_COLUMN_MARKED_FOR_WRITE;
77 if (! temporal.from_string(from, (
size_t) len))
79 my_error(ER_INVALID_DATE_VALUE, MYF(ME_FATALERROR), from);
83 uint32_t int_value= (temporal.years() * 10000) + (temporal.months() * 100) + temporal.days();
84 int4store(
ptr, int_value);
88 int Field_date::store(
double from)
90 ASSERT_COLUMN_MARKED_FOR_WRITE;
91 if (from < 0.0 || from > 99991231235959.0)
97 ss << from; ss >> tmp;
99 my_error(ER_INVALID_DATE_VALUE, MYF(ME_FATALERROR), tmp.c_str());
102 return Field_date::store((int64_t) rint(from),
false);
105 int Field_date::store(int64_t from,
bool)
111 ASSERT_COLUMN_MARKED_FOR_WRITE;
113 if (! temporal.from_int64_t(from))
116 std::string tmp(boost::lexical_cast<std::string>(from));
118 my_error(ER_INVALID_DATE_VALUE, MYF(ME_FATALERROR), tmp.c_str());
123 uint32_t int_value= (temporal.years() * 10000) + (temporal.months() * 100) + temporal.days();
124 int4store(
ptr, int_value);
130 type::timestamp_t time_type)
134 if (time_type == type::DRIZZLE_TIMESTAMP_DATE || time_type == type::DRIZZLE_TIMESTAMP_DATETIME)
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))
144 char buff[type::Time::MAX_STRING_LENGTH];
145 String str(buff,
sizeof(buff), &my_charset_utf8_general_ci);
146 ltime.convert(str, type::DRIZZLE_TIMESTAMP_DATE);
148 str.ptr(), str.length(), type::DRIZZLE_TIMESTAMP_DATE, 1);
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))
156 char buff[type::Time::MAX_STRING_LENGTH];
157 String str(buff,
sizeof(buff), &my_charset_utf8_general_ci);
160 ER_WARN_DATA_TRUNCATED,
161 str.ptr(), str.length(), type::DRIZZLE_TIMESTAMP_DATE, 1);
169 set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
177 double Field_date::val_real(
void)
const
179 return (
double) Field_date::val_int();
182 int64_t Field_date::val_int(
void)
const
186 ASSERT_COLUMN_MARKED_FOR_READ;
193 String *Field_date::val_str(String *val_buffer, String *)
const
197 uint32_t tmp=(uint32_t) uint4korr(
ptr);
199 char *pos=(
char*) val_buffer->ptr()+10;
201 ASSERT_COLUMN_MARKED_FOR_READ;
205 part=(int32_t) (tmp % 100);
206 *pos--= (char) (
'0'+part%10);
207 *pos--= (char) (
'0'+part/10);
209 part=(int32_t) (tmp/100%100);
210 *pos--= (char) (
'0'+part%10);
211 *pos--= (char) (
'0'+part/10);
213 part=(int32_t) (tmp/10000);
214 *pos--= (char) (
'0'+part%10); part/=10;
215 *pos--= (char) (
'0'+part%10); part/=10;
216 *pos--= (char) (
'0'+part%10); part/=10;
217 *pos= (char) (
'0'+part);
221 bool Field_date::get_date(type::Time <ime, uint32_t fuzzydate)
const
223 uint32_t tmp=(uint32_t) uint4korr(
ptr);
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)) ?
234 bool Field_date::get_time(type::Time <ime)
const
236 return Field_date::get_date(ltime ,0);
239 int Field_date::cmp(
const unsigned char *a_ptr,
const unsigned char *b_ptr)
242 a=(uint32_t) uint4korr(a_ptr);
243 b=(uint32_t) uint4korr(b_ptr);
244 return (a < b) ? -1 : (a > b) ? 1 : 0;
247 void Field_date::sort_string(
unsigned char *to,uint32_t )
bool set_warning(DRIZZLE_ERROR::enum_warning_level, drizzled::error_t code, int cuted_increment)
int store_time(type::Time <ime, type::timestamp_t type)
TODO: Rename this file - func.h is stupid.
bool check(bool not_zero_date, uint32_t flags, type::cut_t &was_cut) const
Check datetime value for validity according to flags.
drizzle_system_variables & variables
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, drizzled::error_t code, const char *str, uint32_t str_len, type::timestamp_t ts_type, int cuted_increment)