drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
client.cc
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2008 Sun Microsystems, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <config.h>
21
22#include <cstdio>
23
24#include <drizzled/plugin/client.h>
25#include <drizzled/type/time.h>
26
27namespace drizzled {
28
29void plugin::Client::store(const type::Time *from)
30{
31 const size_t buff_len= 40;
32 char buff[buff_len];
33 uint32_t length= 0;
34 uint32_t day;
35
36 switch (from->time_type)
37 {
38 case type::DRIZZLE_TIMESTAMP_DATETIME:
39 length= snprintf(buff, (buff_len-length), "%04d-%02d-%02d %02d:%02d:%02d",
40 (int) from->year,
41 (int) from->month,
42 (int) from->day,
43 (int) from->hour,
44 (int) from->minute,
45 (int) from->second);
46 if (from->second_part)
47 length+= snprintf(buff+length, (buff_len-length), ".%06d", (int)from->second_part);
48 break;
49
50 case type::DRIZZLE_TIMESTAMP_DATE:
51 length= snprintf(buff, (buff_len-length), "%04d-%02d-%02d",
52 (int) from->year,
53 (int) from->month,
54 (int) from->day);
55 break;
56
57 case type::DRIZZLE_TIMESTAMP_TIME:
58 day= (from->year || from->month) ? 0 : from->day;
59 length= snprintf(buff, (buff_len-length), "%s%02ld:%02d:%02d",
60 from->neg ? "-" : "",
61 (long) day*24L+(long) from->hour,
62 (int) from->minute,
63 (int) from->second);
64 if (from->second_part)
65 length+= snprintf(buff+length, (buff_len-length), ".%06d", (int)from->second_part);
66 break;
67
68 case type::DRIZZLE_TIMESTAMP_NONE:
69 case type::DRIZZLE_TIMESTAMP_ERROR:
70 default:
71 assert(false);
72 return;
73 }
74
75 return store(buff);
76}
77
78void plugin::Client::store(const char *from)
79{
80 return from ? store(from, strlen(from)) : store();
81}
82
83
84} /* namespace drizzled */
TODO: Rename this file - func.h is stupid.