~drizzle-trunk/drizzle/development

642.1.6 by Lee
move functions from item.cc/item.h to item directory
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
1122.2.10 by Monty Taylor
Fixed all of the include guards.
20
#ifndef DRIZZLED_ITEM_STRING_H
21
#define DRIZZLED_ITEM_STRING_H
642.1.6 by Lee
move functions from item.cc/item.h to item directory
22
642.1.62 by Lee
more header file cleanup
23
#include <drizzled/item/basic_constant.h>
24
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
25
namespace drizzled
26
{
27
642.1.6 by Lee
move functions from item.cc/item.h to item directory
28
class Item_string :public Item_basic_constant
29
{
30
public:
31
  Item_string(const char *str,uint32_t length,
1022.1.3 by Brian Aker
Force UTF8 (remove the bits for looking for ascii).
32
              const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
642.1.6 by Lee
move functions from item.cc/item.h to item directory
33
    : m_cs_specified(false)
34
  {
35
    str_value.set_or_copy_aligned(str, length, cs);
1022.1.3 by Brian Aker
Force UTF8 (remove the bits for looking for ascii).
36
    collation.set(cs, dv);
642.1.6 by Lee
move functions from item.cc/item.h to item directory
37
    /*
38
      We have to have a different max_length than 'length' here to
39
      ensure that we get the right length if we do use the item
40
      to create a new table. In this case max_length must be the maximum
1052.2.3 by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards.
41
      number of chars for a string of this type because we in CreateField::
642.1.6 by Lee
move functions from item.cc/item.h to item directory
42
      divide the max_length with mbmaxlen).
43
    */
44
    max_length= str_value.numchars()*cs->mbmaxlen;
45
    set_name(str, length, cs);
46
    decimals=NOT_FIXED_DEC;
47
    // it is constant => can be used without fix_fields (and frequently used)
48
    fixed= 1;
49
  }
50
  /* Just create an item and do not fill string representation */
51
  Item_string(const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
52
    : m_cs_specified(false)
53
  {
54
    collation.set(cs, dv);
55
    max_length= 0;
56
    set_name(NULL, 0, cs);
57
    decimals= NOT_FIXED_DEC;
58
    fixed= 1;
59
  }
60
  Item_string(const char *name_par, const char *str, uint32_t length,
1022.1.3 by Brian Aker
Force UTF8 (remove the bits for looking for ascii).
61
              const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
642.1.6 by Lee
move functions from item.cc/item.h to item directory
62
    : m_cs_specified(false)
63
  {
64
    str_value.set_or_copy_aligned(str, length, cs);
1022.1.3 by Brian Aker
Force UTF8 (remove the bits for looking for ascii).
65
    collation.set(cs, dv);
642.1.6 by Lee
move functions from item.cc/item.h to item directory
66
    max_length= str_value.numchars()*cs->mbmaxlen;
67
    set_name(name_par, 0, cs);
68
    decimals=NOT_FIXED_DEC;
69
    // it is constant => can be used without fix_fields (and frequently used)
70
    fixed= 1;
71
  }
72
  enum Type type() const { return STRING_ITEM; }
73
  double val_real();
74
  int64_t val_int();
75
  String *val_str(String*)
76
  {
77
    assert(fixed == 1);
78
    return (String*) &str_value;
79
  }
80
  my_decimal *val_decimal(my_decimal *);
81
  int save_in_field(Field *field, bool no_conversions);
82
  enum Item_result result_type () const { return STRING_RESULT; }
83
  enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
84
  bool basic_const_item() const { return 1; }
85
  bool eq(const Item *item, bool binary_cmp) const;
86
  Item *clone_item()
87
  {
88
    return new Item_string(name, str_value.ptr(),
89
    			   str_value.length(), collation.collation);
90
  }
91
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
92
  inline void append(char *str, uint32_t length)
93
  {
94
    str_value.append(str, length);
95
    max_length= str_value.numchars() * collation.collation->mbmaxlen;
96
  }
97
  virtual void print(String *str, enum_query_type query_type);
98
99
  /**
100
    Return true if character-set-introducer was explicitly specified in the
101
    original query for this item (text literal).
102
103
    This operation is to be called from Item_string::print(). The idea is
104
    that when a query is generated (re-constructed) from the Item-tree,
105
    character-set-introducers should appear only for those literals, where
106
    they were explicitly specified by the user. Otherwise, that may lead to
107
    loss collation information (character set introducers implies default
108
    collation for the literal).
109
110
    Basically, that makes sense only for views and hopefully will be gone
111
    one day when we start using original query as a view definition.
112
113
    @return This operation returns the value of m_cs_specified attribute.
114
      @retval true if character set introducer was explicitly specified in
115
      the original query.
116
      @retval false otherwise.
117
  */
118
  inline bool is_cs_specified() const
119
  {
120
    return m_cs_specified;
121
  }
122
123
  /**
124
    Set the value of m_cs_specified attribute.
125
126
    m_cs_specified attribute shows whether character-set-introducer was
127
    explicitly specified in the original query for this text literal or
128
    not. The attribute makes sense (is used) only for views.
129
130
    This operation is to be called from the parser during parsing an input
131
    query.
132
  */
133
  inline void set_cs_specified(bool cs_specified)
134
  {
135
    m_cs_specified= cs_specified;
136
  }
137
138
private:
139
  bool m_cs_specified;
140
};
141
142
143
class Item_static_string_func :public Item_string
144
{
145
  const char *func_name;
146
public:
147
  Item_static_string_func(const char *name_par, const char *str, uint32_t length,
148
                          const CHARSET_INFO * const cs,
149
                          Derivation dv= DERIVATION_COERCIBLE)
150
    :Item_string(NULL, str, length, cs, dv), func_name(name_par)
151
  {}
152
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
153
154
  virtual inline void print(String *str, enum_query_type)
155
  {
156
    str->append(func_name);
157
  }
158
};
159
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
160
} /* namespace drizzled */
161
1122.2.10 by Monty Taylor
Fixed all of the include guards.
162
#endif /* DRIZZLED_ITEM_STRING_H */