00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #pragma once
00022
00023 #include <drizzled/field/str.h>
00024 #include <drizzled/charset.h>
00025 #include <string>
00026 #include <drizzled/visibility.h>
00027
00028 namespace drizzled {
00029
00033 class DRIZZLED_API Field_blob :
00034 public Field_str
00035 {
00036 protected:
00037 String value;
00038 public:
00039
00040 using Field::store;
00041 using Field::cmp;
00042 using Field::pack;
00043 using Field::unpack;
00044 using Field::val_int;
00045 using Field::val_str;
00046
00047 Field_blob(unsigned char *ptr_arg,
00048 unsigned char *null_ptr_arg,
00049 unsigned char null_bit_arg,
00050 const char *field_name_arg,
00051 TableShare *share,
00052 const charset_info_st * const cs);
00053 Field_blob(uint32_t len_arg,
00054 bool maybe_null_arg,
00055 const char *field_name_arg,
00056 const charset_info_st * const cs)
00057 :Field_str((unsigned char*) NULL,
00058 len_arg,
00059 maybe_null_arg ? (unsigned char *) "": 0,
00060 0,
00061 field_name_arg,
00062 cs)
00063 {
00064 flags|= BLOB_FLAG;
00065 }
00066
00067 enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
00068 enum ha_base_keytype key_type() const
00069 { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
00070 int store(const char *to,uint32_t length,
00071 const charset_info_st * const charset);
00072 int store(double nr);
00073 int store(int64_t nr, bool unsigned_val);
00074
00075 double val_real(void) const;
00076 int64_t val_int(void) const;
00077 String *val_str(String*,String *) const;
00078 type::Decimal *val_decimal(type::Decimal *) const;
00079 int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
00080 int cmp(const unsigned char *a,const unsigned char *b)
00081 { return cmp_max(a, b, UINT32_MAX); }
00082 int cmp(const unsigned char *a, uint32_t a_length, const unsigned char *b, uint32_t b_length);
00083 int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
00084 int key_cmp(const unsigned char *,const unsigned char*);
00085 int key_cmp(const unsigned char *str, uint32_t length);
00086 uint32_t key_length() const { return 0; }
00087 void sort_string(unsigned char *buff,uint32_t length);
00088 uint32_t pack_length() const;
00089
00090
00099 uint32_t pack_length_no_ptr() const
00100 { return (uint32_t) (sizeof(uint32_t)); }
00101
00102 uint32_t sort_length() const;
00103 virtual uint32_t max_data_length() const
00104 {
00105 return (uint32_t) (((uint64_t) 1 << 32) -1);
00106 }
00107 int reset(void) { memset(ptr, 0, sizeof(uint32_t)+sizeof(unsigned char*)); return 0; }
00108 void reset_fields() { memset(&value, 0, sizeof(value)); }
00109 #ifndef WORDS_BIGENDIAN
00110 static
00111 #endif
00112 void store_length(unsigned char *i_ptr, uint32_t i_number, bool low_byte_first);
00113 void store_length(unsigned char *i_ptr, uint32_t i_number);
00114
00115 inline void store_length(uint32_t number)
00116 {
00117 store_length(ptr, number);
00118 }
00119
00128 uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
00129
00130 DRIZZLED_API uint32_t get_length(uint32_t row_offset= 0) const;
00131 DRIZZLED_API uint32_t get_length(const unsigned char *ptr, bool low_byte_first) const;
00132 DRIZZLED_API uint32_t get_length(const unsigned char *ptr_arg) const;
00133 void put_length(unsigned char *pos, uint32_t length);
00134 inline unsigned char* get_ptr() const
00135 {
00136 unsigned char* str;
00137 memcpy(&str, ptr + sizeof(uint32_t), sizeof(unsigned char*));
00138 return str;
00139 }
00140 inline void set_ptr(unsigned char *length, unsigned char *data)
00141 {
00142 memcpy(ptr,length,sizeof(uint32_t));
00143 memcpy(ptr+sizeof(uint32_t),&data,sizeof(char*));
00144 }
00145 void set_ptr_offset(ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
00146 {
00147 unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
00148 store_length(ptr_ofs, length);
00149 memcpy(ptr_ofs+sizeof(uint32_t),&data,sizeof(char*));
00150 }
00151 inline void set_ptr(uint32_t length, unsigned char *data)
00152 {
00153 set_ptr_offset(0, length, data);
00154 }
00155 uint32_t get_key_image(unsigned char *buff,uint32_t length);
00156 uint32_t get_key_image(std::basic_string<unsigned char> &buff, uint32_t length);
00157 void set_key_image(const unsigned char *buff,uint32_t length);
00158 inline void copy()
00159 {
00160 value.copy((char*)get_ptr(), get_length(), charset());
00161 char* tmp= value.ptr();
00162 memcpy(ptr + sizeof(uint32_t), &tmp, sizeof(char*));
00163 }
00164 virtual unsigned char *pack(unsigned char *to, const unsigned char *from, uint32_t max_length, bool low_byte_first);
00165 unsigned char *pack_key(unsigned char *to, const unsigned char *from, uint32_t max_length, bool low_byte_first);
00166 virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from, uint32_t , bool low_byte_first);
00167 void free() { value.free(); }
00168 friend int field_conv(Field *to,Field *from);
00169 uint32_t size_of() const { return sizeof(*this); }
00170 bool has_charset(void) const
00171 { return charset() != &my_charset_bin; }
00172 uint32_t max_display_length();
00173 };
00174
00175 }
00176
00177