~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/string.h

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

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