Drizzled Public API Documentation

varstring.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 #include <string>
00025 
00026 namespace drizzled
00027 {
00028 
00029 class Field_varstring :public Field_str {
00030 public:
00031 
00032   using Field::store;
00033   using Field::pack;
00034   using Field::unpack;
00035   using Field::val_int;
00036   using Field::val_str;
00037 
00038   /*
00039     The maximum space available in a Field_varstring, in bytes. See
00040     length_bytes.
00041   */
00042   static const uint32_t MAX_SIZE;
00043 private:
00044   /* Store number of bytes used to store length (1 or 2) */
00045   uint32_t length_bytes;
00046 public:
00047   Field_varstring(unsigned char *ptr_arg,
00048                   uint32_t len_arg,
00049                   uint32_t length_bytes_arg,
00050                   unsigned char *null_ptr_arg,
00051                   unsigned char null_bit_arg,
00052                   const char *field_name_arg,
00053                   const CHARSET_INFO * const cs);
00054   Field_varstring(uint32_t len_arg,
00055                   bool maybe_null_arg,
00056                   const char *field_name_arg,
00057                   const CHARSET_INFO * const cs);
00058 
00059   enum_field_types type() const { return DRIZZLE_TYPE_VARCHAR; }
00060   enum ha_base_keytype key_type() const;
00061   bool zero_pack() const { return 0; }
00062   int  reset(void) { memset(ptr, 0, field_length+length_bytes); return 0; }
00063   uint32_t pack_length() const { return (uint32_t) field_length+length_bytes; }
00064   uint32_t pack_length_no_ptr() const { return length_bytes; }
00065   uint32_t key_length() const { return (uint32_t) field_length; }
00066   uint32_t sort_length() const
00067   {
00068     return (uint32_t) field_length + (field_charset == &my_charset_bin ?
00069                                       length_bytes : 0);
00070   }
00071   int  store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
00072 
00073 
00074   int  store(int64_t nr, bool unsigned_val);
00075   int  store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
00076   double val_real(void) const;
00077   int64_t val_int(void) const;
00078   String *val_str(String*,String *) const;
00079   inline String *val_str(String *str) { return val_str(str, str); }
00080   type::Decimal *val_decimal(type::Decimal *) const;
00081   int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
00082   inline  int cmp(const unsigned char *str) { return cmp(ptr,str); }
00083   int cmp(const unsigned char *a,const unsigned char *b)
00084   {
00085     return cmp_max(a, b, UINT32_MAX);
00086   }
00087   void sort_string(unsigned char *buff,uint32_t length);
00088   uint32_t get_key_image(unsigned char *buff,uint32_t length);
00089   uint32_t get_key_image(std::basic_string <unsigned char> &buff, uint32_t length);
00090   void set_key_image(const unsigned char *buff,uint32_t length);
00091   void sql_type(String &str) const;
00092   virtual unsigned char *pack(unsigned char *to,
00093                               const unsigned char *from,
00094                               uint32_t max_length,
00095                               bool low_byte_first);
00096 
00097   virtual const unsigned char *unpack(unsigned char* to,
00098                                       const unsigned char *from,
00099                                       uint32_t param_data,
00100                                       bool low_byte_first);
00101 
00102   int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
00103   int key_cmp(const unsigned char *,const unsigned char*);
00104   int key_cmp(const unsigned char *str, uint32_t length);
00105   uint32_t max_packed_col_length(uint32_t max_length);
00106   uint32_t used_length();
00107   uint32_t size_of() const { return sizeof(*this); }
00108   enum_field_types real_type() const { return DRIZZLE_TYPE_VARCHAR; }
00109   bool has_charset(void) const
00110   { return charset() == &my_charset_bin ? false : true; }
00111   Field *new_field(memory::Root *root, Table *new_table, bool keep_type);
00112   Field *new_key_field(memory::Root *root, Table *new_table,
00113                        unsigned char *new_ptr, unsigned char *new_null_ptr,
00114                        uint32_t new_null_bit);
00115 };
00116 
00117 } /* namespace drizzled */
00118 
00119