~drizzle-trunk/drizzle/development

971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
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
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
20
#include "config.h"
1502.3.1 by iwamatsu at nigauri
Add cstdio include to files needing it. Fixes the build on some debian
21
#include <cstdio>
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
22
#include "drizzled/plugin/client.h"
23
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
24
namespace drizzled
25
{
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
26
2030.1.5 by Brian Aker
Update for moving DRIZZLE_TIME to type::Time
27
bool plugin::Client::store(const type::Time *from)
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
28
{
1366.1.9 by Siddharth Prakash Singh
sprintf->snprintf in drizzled/plugin/client.cc
29
  const size_t buff_len= 40;
30
  char buff[buff_len];
31
  uint32_t length= 0;
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
32
  uint32_t day;
33
34
  switch (from->time_type)
35
  {
36
  case DRIZZLE_TIMESTAMP_DATETIME:
1366.1.9 by Siddharth Prakash Singh
sprintf->snprintf in drizzled/plugin/client.cc
37
    length= snprintf(buff, (buff_len-length), "%04d-%02d-%02d %02d:%02d:%02d",
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
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)
1366.1.9 by Siddharth Prakash Singh
sprintf->snprintf in drizzled/plugin/client.cc
45
      length+= snprintf(buff+length, (buff_len-length), ".%06d", (int)from->second_part);
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
46
    break;
47
48
  case DRIZZLE_TIMESTAMP_DATE:
1366.1.9 by Siddharth Prakash Singh
sprintf->snprintf in drizzled/plugin/client.cc
49
    length= snprintf(buff, (buff_len-length), "%04d-%02d-%02d",
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
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;
1366.1.9 by Siddharth Prakash Singh
sprintf->snprintf in drizzled/plugin/client.cc
57
    length= snprintf(buff, (buff_len-length), "%s%02ld:%02d:%02d",
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
58
                    from->neg ? "-" : "",
59
                    (long) day*24L+(long) from->hour,
60
                    (int) from->minute,
61
                    (int) from->second);
62
    if (from->second_part)
1366.1.9 by Siddharth Prakash Singh
sprintf->snprintf in drizzled/plugin/client.cc
63
      length+= snprintf(buff+length, (buff_len-length), ".%06d", (int)from->second_part);
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
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
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
82
83
84
} /* namespace drizzled */