Drizzled Public API Documentation

blob.h

00001 /* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 MySQL
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #pragma once
00022 
00023 #include <drizzled/field/str.h>
00024 
00025 #include <drizzled/global_charset_info.h>
00026 
00027 #include <string>
00028 
00029 #include <drizzled/visibility.h>
00030 
00031 namespace drizzled
00032 {
00033 
00037 class DRIZZLED_API Field_blob :
00038   public Field_str
00039 {
00040 protected:
00041   String value;       // For temporaries
00042 public:
00043 
00044   using Field::store;
00045   using Field::cmp;
00046   using Field::pack;
00047   using Field::unpack;
00048   using Field::val_int;
00049   using Field::val_str;
00050 
00051   Field_blob(unsigned char *ptr_arg,
00052              unsigned char *null_ptr_arg,
00053              unsigned char null_bit_arg,
00054              const char *field_name_arg,
00055              TableShare *share,
00056              const CHARSET_INFO * const cs);
00057   Field_blob(uint32_t len_arg,
00058              bool maybe_null_arg,
00059              const char *field_name_arg,
00060              const CHARSET_INFO * const cs)
00061     :Field_str((unsigned char*) NULL,
00062                len_arg,
00063                maybe_null_arg ? (unsigned char *) "": 0,
00064                0,
00065                field_name_arg,
00066                cs)
00067   {
00068     flags|= BLOB_FLAG;
00069   }
00070 
00071   enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
00072   enum ha_base_keytype key_type() const
00073     { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
00074   int  store(const char *to,uint32_t length,
00075              const CHARSET_INFO * const charset);
00076   int  store(double nr);
00077   int  store(int64_t nr, bool unsigned_val);
00078 
00079   double val_real(void) const;
00080   int64_t val_int(void) const;
00081   String *val_str(String*,String *) const;
00082   type::Decimal *val_decimal(type::Decimal *) const;
00083   int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
00084   int cmp(const unsigned char *a,const unsigned char *b)
00085     { return cmp_max(a, b, UINT32_MAX); }
00086   int cmp(const unsigned char *a, uint32_t a_length, const unsigned char *b, uint32_t b_length);
00087   int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
00088   int key_cmp(const unsigned char *,const unsigned char*);
00089   int key_cmp(const unsigned char *str, uint32_t length);
00090   uint32_t key_length() const { return 0; }
00091   void sort_string(unsigned char *buff,uint32_t length);
00092   uint32_t pack_length() const;
00093 
00094 
00103   uint32_t pack_length_no_ptr() const
00104   { return (uint32_t) (sizeof(uint32_t)); }
00105 
00106   uint32_t sort_length() const;
00107   virtual uint32_t max_data_length() const
00108   {
00109     return (uint32_t) (((uint64_t) 1 << 32) -1);
00110   }
00111   int reset(void) { memset(ptr, 0, sizeof(uint32_t)+sizeof(unsigned char*)); return 0; }
00112   void reset_fields() { memset(&value, 0, sizeof(value)); }
00113 #ifndef WORDS_BIGENDIAN
00114   static
00115 #endif
00116   void store_length(unsigned char *i_ptr, uint32_t i_number, bool low_byte_first);
00117   void store_length(unsigned char *i_ptr, uint32_t i_number);
00118 
00119   inline void store_length(uint32_t number)
00120   {
00121     store_length(ptr, number);
00122   }
00123 
00132   uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
00133 
00134   DRIZZLED_API uint32_t get_length(uint32_t row_offset= 0) const;
00135   DRIZZLED_API uint32_t get_length(const unsigned char *ptr, bool low_byte_first) const;
00136   DRIZZLED_API uint32_t get_length(const unsigned char *ptr_arg) const;
00137   void put_length(unsigned char *pos, uint32_t length);
00138   inline void get_ptr(unsigned char **str)
00139     {
00140       memcpy(str,ptr+sizeof(uint32_t),sizeof(unsigned char*));
00141     }
00142   inline void get_ptr(unsigned char **str, uint32_t row_offset)
00143     {
00144       memcpy(str,ptr+sizeof(uint32_t)+row_offset,sizeof(char*));
00145     }
00146   inline void set_ptr(unsigned char *length, unsigned char *data)
00147     {
00148       memcpy(ptr,length,sizeof(uint32_t));
00149       memcpy(ptr+sizeof(uint32_t),&data,sizeof(char*));
00150     }
00151   void set_ptr_offset(ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
00152     {
00153       unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
00154       store_length(ptr_ofs, length);
00155       memcpy(ptr_ofs+sizeof(uint32_t),&data,sizeof(char*));
00156     }
00157   inline void set_ptr(uint32_t length, unsigned char *data)
00158     {
00159       set_ptr_offset(0, length, data);
00160     }
00161   uint32_t get_key_image(unsigned char *buff,uint32_t length);
00162   uint32_t get_key_image(std::basic_string<unsigned char> &buff, uint32_t length);
00163   void set_key_image(const unsigned char *buff,uint32_t length);
00164   void sql_type(String &str) const;
00165   inline bool copy()
00166   {
00167     unsigned char *tmp;
00168     get_ptr(&tmp);
00169     if (value.copy((char*) tmp, get_length(), charset()))
00170     {
00171       Field_blob::reset();
00172       return 1;
00173     }
00174     tmp=(unsigned char*) value.ptr();
00175     memcpy(ptr+sizeof(uint32_t),&tmp,sizeof(char*));
00176     return 0;
00177   }
00178   virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
00179                       uint32_t max_length, bool low_byte_first);
00180   unsigned char *pack_key(unsigned char *to, const unsigned char *from,
00181                   uint32_t max_length, bool low_byte_first);
00182   virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
00183                               uint32_t , bool low_byte_first);
00184   void free() { value.free(); }
00185   inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
00186   friend int field_conv(Field *to,Field *from);
00187   uint32_t size_of() const { return sizeof(*this); }
00188   bool has_charset(void) const
00189   { return charset() == &my_charset_bin ? false : true; }
00190   uint32_t max_display_length();
00191 };
00192 
00193 } /* namespace drizzled */
00194 
00195