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 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 } /* namespace drizzled */