00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022 #include <drizzled/item/basic_constant.h>
00023 #include <drizzled/charset_info.h>
00024
00025 namespace drizzled
00026 {
00027
00028 class Item_string :public Item_basic_constant
00029 {
00030 public:
00031 Item_string(const char *str,uint32_t length,
00032 const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
00033 : m_cs_specified(false)
00034 {
00035 str_value.set_or_copy_aligned(str, length, cs);
00036 collation.set(cs, dv);
00037
00038
00039
00040
00041
00042
00043
00044 max_length= str_value.numchars()*cs->mbmaxlen;
00045 set_name(str, length, cs);
00046 decimals=NOT_FIXED_DEC;
00047
00048 fixed= 1;
00049 }
00050
00051 Item_string(const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
00052 : m_cs_specified(false)
00053 {
00054 collation.set(cs, dv);
00055 max_length= 0;
00056 set_name(NULL, 0, cs);
00057 decimals= NOT_FIXED_DEC;
00058 fixed= 1;
00059 }
00060 Item_string(const char *name_par, const char *str, uint32_t length,
00061 const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
00062 : m_cs_specified(false)
00063 {
00064 str_value.set_or_copy_aligned(str, length, cs);
00065 collation.set(cs, dv);
00066 max_length= str_value.numchars()*cs->mbmaxlen;
00067 set_name(name_par, 0, cs);
00068 decimals=NOT_FIXED_DEC;
00069
00070 fixed= 1;
00071 }
00072 enum Type type() const { return STRING_ITEM; }
00073 double val_real();
00074 int64_t val_int();
00075 String *val_str(String*)
00076 {
00077 assert(fixed == 1);
00078 return (String*) &str_value;
00079 }
00080 type::Decimal *val_decimal(type::Decimal *);
00081 int save_in_field(Field *field, bool no_conversions);
00082 enum Item_result result_type () const { return STRING_RESULT; }
00083 enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
00084 bool basic_const_item() const { return 1; }
00085 bool eq(const Item *item, bool binary_cmp) const;
00086 Item *clone_item()
00087 {
00088 return new Item_string(name, str_value.ptr(),
00089 str_value.length(), collation.collation);
00090 }
00091 Item *safe_charset_converter(const CHARSET_INFO * const tocs);
00092 inline void append(char *str, uint32_t length)
00093 {
00094 str_value.append(str, length);
00095 max_length= str_value.numchars() * collation.collation->mbmaxlen;
00096 }
00097 virtual void print(String *str);
00098
00118 inline bool is_cs_specified() const
00119 {
00120 return m_cs_specified;
00121 }
00122
00133 inline void set_cs_specified(bool cs_specified)
00134 {
00135 m_cs_specified= cs_specified;
00136 }
00137
00138 private:
00139 bool m_cs_specified;
00140 };
00141
00142
00143 class Item_static_string_func :public Item_string
00144 {
00145 const char *func_name;
00146 public:
00147 Item_static_string_func(const char *name_par, const char *str, uint32_t length,
00148 const CHARSET_INFO * const cs,
00149 Derivation dv= DERIVATION_COERCIBLE)
00150 :Item_string(NULL, str, length, cs, dv), func_name(name_par)
00151 {}
00152 Item *safe_charset_converter(const CHARSET_INFO * const tocs);
00153
00154 virtual inline void print(String *str)
00155 {
00156 str->append(func_name);
00157 }
00158 };
00159
00160 }
00161