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 void plugin::Client::store(const type::Time *from)
00030 {
00031 const size_t buff_len= 40;
00032 char buff[buff_len];
00033 uint32_t length= 0;
00034 uint32_t day;
00035
00036 switch (from->time_type)
00037 {
00038 case type::DRIZZLE_TIMESTAMP_DATETIME:
00039 length= snprintf(buff, (buff_len-length), "%04d-%02d-%02d %02d:%02d:%02d",
00040 (int) from->year,
00041 (int) from->month,
00042 (int) from->day,
00043 (int) from->hour,
00044 (int) from->minute,
00045 (int) from->second);
00046 if (from->second_part)
00047 length+= snprintf(buff+length, (buff_len-length), ".%06d", (int)from->second_part);
00048 break;
00049
00050 case type::DRIZZLE_TIMESTAMP_DATE:
00051 length= snprintf(buff, (buff_len-length), "%04d-%02d-%02d",
00052 (int) from->year,
00053 (int) from->month,
00054 (int) from->day);
00055 break;
00056
00057 case type::DRIZZLE_TIMESTAMP_TIME:
00058 day= (from->year || from->month) ? 0 : from->day;
00059 length= snprintf(buff, (buff_len-length), "%s%02ld:%02d:%02d",
00060 from->neg ? "-" : "",
00061 (long) day*24L+(long) from->hour,
00062 (int) from->minute,
00063 (int) from->second);
00064 if (from->second_part)
00065 length+= snprintf(buff+length, (buff_len-length), ".%06d", (int)from->second_part);
00066 break;
00067
00068 case type::DRIZZLE_TIMESTAMP_NONE:
00069 case type::DRIZZLE_TIMESTAMP_ERROR:
00070 default:
00071 assert(false);
00072 return;
00073 }
00074
00075 return store(buff);
00076 }
00077
00078 void plugin::Client::store(const char *from)
00079 {
00080 return from ? store(from, strlen(from)) : store();
00081 }
00082
00083
00084 }