~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/client.cc

Cleanup around SAFEMALLOC

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