~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/time/get_format.cc

  • Committer: Jay Pipes
  • Date: 2009-02-28 17:49:22 UTC
  • mto: (910.2.6 mordred-noatomics)
  • mto: This revision was merged to the branch mainline in revision 908.
  • Revision ID: jpipes@serialcoder-20090228174922-jczgt4d0662fqmnf
Merging in old r902 temporal 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 <drizzled/server_includes.h>
21
 
#include CSTDINT_H
22
 
#include <drizzled/function/time/get_format.h>
23
 
 
24
 
String *Item_func_get_format::val_str(String *str)
25
 
{
26
 
  assert(fixed == 1);
27
 
  const char *format_name;
28
 
  KNOWN_DATE_TIME_FORMAT *format;
29
 
  String *val= args[0]->val_str(str);
30
 
  ulong val_len;
31
 
 
32
 
  if ((null_value= args[0]->null_value))
33
 
    return 0;
34
 
 
35
 
  val_len= val->length();
36
 
  for (format= &known_date_time_formats[0];
37
 
       (format_name= format->format_name);
38
 
       format++)
39
 
  {
40
 
    uint32_t format_name_len;
41
 
    format_name_len= strlen(format_name);
42
 
    if (val_len == format_name_len &&
43
 
        !my_strnncoll(&my_charset_utf8_general_ci,
44
 
                      (const unsigned char *) val->ptr(), val_len,
45
 
                      (const unsigned char *) format_name, val_len))
46
 
    {
47
 
      const char *format_str= get_date_time_format_str(format, type);
48
 
      str->set(format_str, strlen(format_str), &my_charset_bin);
49
 
      return str;
50
 
    }
51
 
  }
52
 
 
53
 
  null_value= 1;
54
 
  return 0;
55
 
}
56
 
 
57
 
void Item_func_get_format::print(String *str, enum_query_type query_type)
58
 
{
59
 
  str->append(func_name());
60
 
  str->append('(');
61
 
 
62
 
  switch (type) {
63
 
  case DRIZZLE_TIMESTAMP_DATE:
64
 
    str->append(STRING_WITH_LEN("DATE, "));
65
 
    break;
66
 
  case DRIZZLE_TIMESTAMP_DATETIME:
67
 
    str->append(STRING_WITH_LEN("DATETIME, "));
68
 
    break;
69
 
  case DRIZZLE_TIMESTAMP_TIME:
70
 
    str->append(STRING_WITH_LEN("TIME, "));
71
 
    break;
72
 
  default:
73
 
    assert(0);
74
 
  }
75
 
  args[0]->print(str, query_type);
76
 
  str->append(')');
77
 
}
78
 
 
79