~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/client.cc

Reverted 1103

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
27
 
namespace drizzled
28
 
{
29
 
 
30
 
bool plugin::Client::store(const type::Time *from)
31
 
{
32
 
  const size_t buff_len= 40;
33
 
  char buff[buff_len];
34
 
  uint32_t length= 0;
35
 
  uint32_t day;
36
 
 
37
 
  switch (from->time_type)
38
 
  {
39
 
  case type::DRIZZLE_TIMESTAMP_DATETIME:
40
 
    length= snprintf(buff, (buff_len-length), "%04d-%02d-%02d %02d:%02d:%02d",
41
 
                    (int) from->year,
42
 
                    (int) from->month,
43
 
                    (int) from->day,
44
 
                    (int) from->hour,
45
 
                    (int) from->minute,
46
 
                    (int) from->second);
47
 
    if (from->second_part)
48
 
      length+= snprintf(buff+length, (buff_len-length), ".%06d", (int)from->second_part);
49
 
    break;
50
 
 
51
 
  case type::DRIZZLE_TIMESTAMP_DATE:
52
 
    length= snprintf(buff, (buff_len-length), "%04d-%02d-%02d",
53
 
                    (int) from->year,
54
 
                    (int) from->month,
55
 
                    (int) from->day);
56
 
    break;
57
 
 
58
 
  case type::DRIZZLE_TIMESTAMP_TIME:
59
 
    day= (from->year || from->month) ? 0 : from->day;
60
 
    length= snprintf(buff, (buff_len-length), "%s%02ld:%02d:%02d",
61
 
                    from->neg ? "-" : "",
62
 
                    (long) day*24L+(long) from->hour,
63
 
                    (int) from->minute,
64
 
                    (int) from->second);
65
 
    if (from->second_part)
66
 
      length+= snprintf(buff+length, (buff_len-length), ".%06d", (int)from->second_part);
67
 
    break;
68
 
 
69
 
  case type::DRIZZLE_TIMESTAMP_NONE:
70
 
  case type::DRIZZLE_TIMESTAMP_ERROR:
71
 
  default:
72
 
    assert(0);
73
 
    return false;
74
 
  }
75
 
 
76
 
  return store(buff);
77
 
}
78
 
 
79
 
bool plugin::Client::store(const char *from)
80
 
{
81
 
  if (from == NULL)
82
 
    return store();
83
 
 
84
 
  return store(from, strlen(from));
85
 
}
86
 
 
87
 
 
88
 
} /* namespace drizzled */