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.h>
00024
00025 namespace drizzled {
00026
00027 class Item_string : public Item_basic_constant
00028 {
00029 public:
00030 Item_string(str_ref str, const charset_info_st* cs, Derivation dv= DERIVATION_COERCIBLE)
00031 {
00032 assert(not (str.size() % cs->mbminlen));
00033 str_value.set(str.data(), str.size(), cs);
00034 collation.set(cs, dv);
00035
00036
00037
00038
00039
00040
00041
00042 max_length= str_value.numchars() * cs->mbmaxlen;
00043 set_name(str.data(), str.size(), cs);
00044 decimals=NOT_FIXED_DEC;
00045
00046 fixed= 1;
00047 }
00048
00049 Item_string(const char *str,uint32_t length,
00050 const charset_info_st * const cs, Derivation dv= DERIVATION_COERCIBLE)
00051 {
00052 assert(not (length % cs->mbminlen));
00053 str_value.set(str, length, cs);
00054 collation.set(cs, dv);
00055
00056
00057
00058
00059
00060
00061
00062 max_length= str_value.numchars()*cs->mbmaxlen;
00063 set_name(str, length, cs);
00064 decimals=NOT_FIXED_DEC;
00065
00066 fixed= 1;
00067 }
00068
00069 Item_string(const charset_info_st * const cs, Derivation dv= DERIVATION_COERCIBLE)
00070 {
00071 collation.set(cs, dv);
00072 max_length= 0;
00073 set_name(NULL, 0, cs);
00074 decimals= NOT_FIXED_DEC;
00075 fixed= 1;
00076 }
00077 Item_string(const char *name_par, const char *str, uint32_t length,
00078 const charset_info_st * const cs, Derivation dv= DERIVATION_COERCIBLE)
00079 {
00080 assert(not (length % cs->mbminlen));
00081 str_value.set(str, length, cs);
00082 collation.set(cs, dv);
00083 max_length= str_value.numchars()*cs->mbmaxlen;
00084 set_name(name_par, 0, cs);
00085 decimals=NOT_FIXED_DEC;
00086
00087 fixed= 1;
00088 }
00089 enum Type type() const { return STRING_ITEM; }
00090 double val_real();
00091 int64_t val_int();
00092 String *val_str(String*)
00093 {
00094 assert(fixed == 1);
00095 return (String*) &str_value;
00096 }
00097 type::Decimal *val_decimal(type::Decimal *);
00098 int save_in_field(Field *field, bool no_conversions);
00099 enum Item_result result_type () const { return STRING_RESULT; }
00100 enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
00101 bool basic_const_item() const { return 1; }
00102 bool eq(const Item *item, bool binary_cmp) const;
00103 Item *clone_item()
00104 {
00105 return new Item_string(name, str_value.ptr(), str_value.length(), collation.collation);
00106 }
00107 Item *safe_charset_converter(const charset_info_st * const tocs);
00108 inline void append(str_ref v)
00109 {
00110 str_value.append(v);
00111 max_length= str_value.numchars() * collation.collation->mbmaxlen;
00112 }
00113 virtual void print(String *str);
00114 };
00115
00116
00117 class Item_static_string_func : public Item_string
00118 {
00119 const char *func_name;
00120 public:
00121 Item_static_string_func(const char *name_par, str_ref str, const charset_info_st* cs, Derivation dv= DERIVATION_COERCIBLE) :
00122 Item_string(NULL, str.data(), str.size(), cs, dv), func_name(name_par)
00123 {}
00124 Item *safe_charset_converter(const charset_info_st*);
00125
00126 virtual inline void print(String *str)
00127 {
00128 str->append(func_name);
00129 }
00130 };
00131
00132 }
00133