~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/client.cc

  • Committer: Brian Aker
  • Date: 2010-12-08 22:35:56 UTC
  • mfrom: (1819.9.158 update-innobase)
  • Revision ID: brian@tangent.org-20101208223556-37mi4omqg7lkjzf3
Merge in Stewart's changes, 1.3 changes.

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