Drizzled Public API Documentation

string.h
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, Inc.
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 #pragma once
21 
22 #include <drizzled/item/basic_constant.h>
23 #include <drizzled/charset.h>
24 
25 namespace drizzled {
26 
28 {
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 
49  Item_string(const char *str,uint32_t length,
50  const charset_info_st * const cs, Derivation dv= DERIVATION_COERCIBLE)
51  {
52  assert(not (length % cs->mbminlen));
53  str_value.set(str, length, cs);
54  collation.set(cs, dv);
55  /*
56  We have to have a different max_length than 'length' here to
57  ensure that we get the right length if we do use the item
58  to create a new table. In this case max_length must be the maximum
59  number of chars for a string of this type because we in CreateField::
60  divide the max_length with mbmaxlen).
61  */
62  max_length= str_value.numchars()*cs->mbmaxlen;
63  set_name(str, length, cs);
64  decimals=NOT_FIXED_DEC;
65  // it is constant => can be used without fix_fields (and frequently used)
66  fixed= 1;
67  }
68  /* Just create an item and do not fill string representation */
69  Item_string(const charset_info_st * const cs, Derivation dv= DERIVATION_COERCIBLE)
70  {
71  collation.set(cs, dv);
72  max_length= 0;
73  set_name(NULL, 0, cs);
74  decimals= NOT_FIXED_DEC;
75  fixed= 1;
76  }
77  Item_string(const char *name_par, const char *str, uint32_t length,
78  const charset_info_st * const cs, Derivation dv= DERIVATION_COERCIBLE)
79  {
80  assert(not (length % cs->mbminlen));
81  str_value.set(str, length, cs);
82  collation.set(cs, dv);
83  max_length= str_value.numchars()*cs->mbmaxlen;
84  set_name(name_par, 0, cs);
85  decimals=NOT_FIXED_DEC;
86  // it is constant => can be used without fix_fields (and frequently used)
87  fixed= 1;
88  }
89  enum Type type() const { return STRING_ITEM; }
90  double val_real();
91  int64_t val_int();
93  {
94  assert(fixed == 1);
95  return (String*) &str_value;
96  }
98  int save_in_field(Field *field, bool no_conversions);
99  enum Item_result result_type () const { return STRING_RESULT; }
100  enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
101  bool basic_const_item() const { return 1; }
102  bool eq(const Item *item, bool binary_cmp) const;
103  Item *clone_item()
104  {
105  return new Item_string(name, str_value.ptr(), str_value.length(), collation.collation);
106  }
107  Item *safe_charset_converter(const charset_info_st * const tocs);
108  inline void append(str_ref v)
109  {
110  str_value.append(v);
111  max_length= str_value.numchars() * collation.collation->mbmaxlen;
112  }
113  virtual void print(String *str);
114 };
115 
116 
118 {
119  const char *func_name;
120 public:
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)
127  {}
128  Item *safe_charset_converter(const charset_info_st*);
129 
130  virtual inline void print(String *str)
131  {
132  str->append(func_name, strlen(func_name));
133  }
134 };
135 
136 } /* namespace drizzled */
137 
const char * name
Definition: item.h:110
bool fixed
Definition: item.h:120
int64_t val_int()
Definition: string.cc:97
bool basic_const_item() const
Definition: string.h:101
virtual void print(String *str)
Definition: string.cc:66
bool eq(const Item *item, bool binary_cmp) const
Definition: string.cc:54
virtual void print(String *str)
Definition: string.h:130
Derivation
Definition: enum.h:38
String * val_str(String *)
Definition: string.h:92
type::Decimal * val_decimal(type::Decimal *)
Definition: string.cc:117
double val_real()
Definition: string.cc:73
String str_value
Definition: item.h:107