Drizzled Public API Documentation

client.cc

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 } /* namespace drizzled */