00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <cstdio>
00023
00024 #include <drizzled/plugin/client.h>
00025 #include <drizzled/type/time.h>
00026
00027 namespace drizzled
00028 {
00029
00030 bool plugin::Client::store(const type::Time *from)
00031 {
00032 const size_t buff_len= 40;
00033 char buff[buff_len];
00034 uint32_t length= 0;
00035 uint32_t day;
00036
00037 switch (from->time_type)
00038 {
00039 case type::DRIZZLE_TIMESTAMP_DATETIME:
00040 length= snprintf(buff, (buff_len-length), "%04d-%02d-%02d %02d:%02d:%02d",
00041 (int) from->year,
00042 (int) from->month,
00043 (int) from->day,
00044 (int) from->hour,
00045 (int) from->minute,
00046 (int) from->second);
00047 if (from->second_part)
00048 length+= snprintf(buff+length, (buff_len-length), ".%06d", (int)from->second_part);
00049 break;
00050
00051 case type::DRIZZLE_TIMESTAMP_DATE:
00052 length= snprintf(buff, (buff_len-length), "%04d-%02d-%02d",
00053 (int) from->year,
00054 (int) from->month,
00055 (int) from->day);
00056 break;
00057
00058 case type::DRIZZLE_TIMESTAMP_TIME:
00059 day= (from->year || from->month) ? 0 : from->day;
00060 length= snprintf(buff, (buff_len-length), "%s%02ld:%02d:%02d",
00061 from->neg ? "-" : "",
00062 (long) day*24L+(long) from->hour,
00063 (int) from->minute,
00064 (int) from->second);
00065 if (from->second_part)
00066 length+= snprintf(buff+length, (buff_len-length), ".%06d", (int)from->second_part);
00067 break;
00068
00069 case type::DRIZZLE_TIMESTAMP_NONE:
00070 case type::DRIZZLE_TIMESTAMP_ERROR:
00071 default:
00072 assert(0);
00073 return false;
00074 }
00075
00076 return store(buff);
00077 }
00078
00079 bool plugin::Client::store(const char *from)
00080 {
00081 if (from == NULL)
00082 return store();
00083
00084 return store(from, strlen(from));
00085 }
00086
00087
00088 }