~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/item/string.h

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#pragma once
21
21
 
22
22
#include <drizzled/item/basic_constant.h>
23
 
#include <drizzled/charset_info.h>
24
 
 
25
 
namespace drizzled
26
 
{
27
 
 
28
 
class Item_string :public Item_basic_constant
 
23
#include <drizzled/charset.h>
 
24
 
 
25
namespace drizzled {
 
26
 
 
27
class Item_string : public Item_basic_constant
29
28
{
30
29
public:
 
30
  Item_string(str_ref str, const charset_info_st* cs, Derivation dv= DERIVATION_COERCIBLE)
 
31
  {
 
32
    assert(not (str.size() % cs->mbminlen));
 
33
    str_value.set(str.data(), str.size(), cs);
 
34
    collation.set(cs, dv);
 
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 CreateField::
 
40
      divide the max_length with mbmaxlen).
 
41
    */
 
42
    max_length= str_value.numchars() * cs->mbmaxlen;
 
43
    set_name(str.data(), str.size(), cs);
 
44
    decimals=NOT_FIXED_DEC;
 
45
    // it is constant => can be used without fix_fields (and frequently used)
 
46
    fixed= 1;
 
47
  }
 
48
 
31
49
  Item_string(const char *str,uint32_t length,
32
 
              const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
33
 
    : m_cs_specified(false)
 
50
              const charset_info_st * const cs, Derivation dv= DERIVATION_COERCIBLE)
34
51
  {
35
 
    str_value.set_or_copy_aligned(str, length, cs);
 
52
    assert(not (length % cs->mbminlen));
 
53
    str_value.set(str, length, cs);
36
54
    collation.set(cs, dv);
37
55
    /*
38
56
      We have to have a different max_length than 'length' here to
48
66
    fixed= 1;
49
67
  }
50
68
  /* 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)
 
69
  Item_string(const charset_info_st * const cs, Derivation dv= DERIVATION_COERCIBLE)
53
70
  {
54
71
    collation.set(cs, dv);
55
72
    max_length= 0;
58
75
    fixed= 1;
59
76
  }
60
77
  Item_string(const char *name_par, const char *str, uint32_t length,
61
 
              const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
62
 
    : m_cs_specified(false)
 
78
              const charset_info_st * const cs, Derivation dv= DERIVATION_COERCIBLE)
63
79
  {
64
 
    str_value.set_or_copy_aligned(str, length, cs);
 
80
    assert(not (length % cs->mbminlen));
 
81
    str_value.set(str, length, cs);
65
82
    collation.set(cs, dv);
66
83
    max_length= str_value.numchars()*cs->mbmaxlen;
67
84
    set_name(name_par, 0, cs);
85
102
  bool eq(const Item *item, bool binary_cmp) const;
86
103
  Item *clone_item()
87
104
  {
88
 
    return new Item_string(name, str_value.ptr(),
89
 
                           str_value.length(), collation.collation);
 
105
    return new Item_string(name, str_value.ptr(), str_value.length(), collation.collation);
90
106
  }
91
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
92
 
  inline void append(char *str, uint32_t length)
 
107
  Item *safe_charset_converter(const charset_info_st * const tocs);
 
108
  inline void append(str_ref v)
93
109
  {
94
 
    str_value.append(str, length);
 
110
    str_value.append(v);
95
111
    max_length= str_value.numchars() * collation.collation->mbmaxlen;
96
112
  }
97
113
  virtual void print(String *str);
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
114
};
141
115
 
142
116
 
143
 
class Item_static_string_func :public Item_string
 
117
class Item_static_string_func : public Item_string
144
118
{
145
119
  const char *func_name;
146
120
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)
 
121
  Item_static_string_func(const char *name_par,
 
122
                          str_ref str,
 
123
                          const charset_info_st* cs, 
 
124
                          Derivation dv= DERIVATION_COERCIBLE) :
 
125
    Item_string(NULL, str.data(), str.size(), cs, dv),
 
126
    func_name(name_par)
151
127
  {}
152
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
128
  Item *safe_charset_converter(const charset_info_st*);
153
129
 
154
130
  virtual inline void print(String *str)
155
131
  {
156
 
    str->append(func_name);
 
132
    str->append(func_name, strlen(func_name));
157
133
  }
158
134
};
159
135