22 #include <boost/lexical_cast.hpp>
23 #include <drizzled/field/time.h>
24 #include <drizzled/error.h>
25 #include <drizzled/table.h>
26 #include <drizzled/session.h>
29 #include <arpa/inet.h>
45 unsigned char *null_ptr_arg,
46 unsigned char null_bit_arg,
47 const char *field_name_arg) :
58 const char *field_name_arg) :
61 maybe_null_arg ? (unsigned char*)
"": 0,
68 int Time::store(
const char *from,
74 ASSERT_COLUMN_MARKED_FOR_WRITE;
78 std::string tmp(boost::lexical_cast<std::string>(from));
79 my_error(ER_INVALID_TIME_VALUE, MYF(0), tmp.c_str());
88 int Time::store(
double from)
90 ASSERT_COLUMN_MARKED_FOR_WRITE;
96 if (from > (
double)TIME_MAX_VALUE)
101 else if (from < (
double) - TIME_MAX_VALUE)
103 tmp= -TIME_MAX_VALUE;
108 tmp=(long) floor(fabs(from));
113 if (tmp % 100 > 59 || tmp/100 % 100 > 59)
119 return store(tmp,
false);
123 std::string tmp(boost::lexical_cast<std::string>(from));
124 my_error(ER_INVALID_TIME_VALUE, MYF(0), tmp.c_str());
129 int Time::store(int64_t from,
bool)
131 ASSERT_COLUMN_MARKED_FOR_WRITE;
141 std::string tmp(boost::lexical_cast<std::string>(from));
142 my_error(ER_INVALID_TIME_VALUE, MYF(0), tmp.c_str());
156 memcpy(
ptr, &tmp,
sizeof(int32_t));
163 memcpy(&tmp,
ptr,
sizeof(int32_t));
169 void Time::unpack_time(int32_t &destination,
const unsigned char *source)
const
171 memcpy(&destination, source,
sizeof(int32_t));
172 destination= htonl(destination);
175 double Time::val_real(
void)
const
177 return (
double) Time::val_int();
180 int64_t Time::val_int(
void)
const
182 ASSERT_COLUMN_MARKED_FOR_READ;
185 unpack_time(temporal);
193 String *Time::val_str(String *val_buffer, String *)
const
198 val_buffer->alloc(to_len);
199 to= (
char *) val_buffer->ptr();
201 val_buffer->set_charset(&my_charset_bin);
204 unpack_time(temporal);
208 assert(rlen < to_len);
210 val_buffer->length(rlen);
214 bool Time::get_date(type::Time <ime, uint32_t)
const
219 unpack_time(temporal);
221 ltime.time_type= type::DRIZZLE_TIMESTAMP_DATETIME;
222 ltime.year= temporal.
years();
223 ltime.month= temporal.
months();
224 ltime.day= temporal.
days();
225 ltime.hour= temporal.
hours();
226 ltime.minute= temporal.
minutes();
227 ltime.second= temporal.
seconds();
232 bool Time::get_time(type::Time <ime)
const
234 return Time::get_date(ltime, 0);
237 int Time::cmp(
const unsigned char *a_ptr,
const unsigned char *b_ptr)
241 unpack_time(a, a_ptr);
242 unpack_time(b, b_ptr);
244 return (a < b) ? -1 : (a > b) ? 1 : 0;
248 void Time::sort_string(
unsigned char *to,uint32_t )
250 #ifdef WORDS_BIGENDIAN
251 if (!getTable() || !getTable()->getShare()->db_low_byte_first)
268 long Time::get_timestamp(
bool *null_value)
const
270 if ((*null_value= is_null()))
274 return unpack_num(tmp);
277 size_t Time::max_string_length()
279 return sizeof(int64_t);
bool from_string(const char *from, size_t from_len)
void to_uint64_t(uint64_t &to) const
int to_string(char *to, size_t to_len) const
void to_int32_t(int32_t *to) const
Time(unsigned char *ptr_arg, uint32_t len_arg, unsigned char *null_ptr_arg, unsigned char null_bit_arg, const char *field_name_arg)
bool from_time_t(const time_t from)
bool from_int32_t(const int32_t from)