Drizzled Public API Documentation

blob.h
1 /* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2008 MySQL
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #pragma once
22 
23 #include <drizzled/field/str.h>
24 #include <drizzled/charset.h>
25 #include <string>
26 #include <drizzled/visibility.h>
27 
28 namespace drizzled {
29 
34  public Field_str
35 {
36 protected:
37  String value; // For temporaries
38 public:
39 
40  using Field::store;
41  using Field::cmp;
42  using Field::pack;
43  using Field::unpack;
44  using Field::val_int;
45  using Field::val_str;
46 
47  Field_blob(unsigned char *ptr_arg,
48  unsigned char *null_ptr_arg,
49  unsigned char null_bit_arg,
50  const char *field_name_arg,
51  TableShare *share,
52  const charset_info_st * const cs);
53  Field_blob(uint32_t len_arg,
54  bool maybe_null_arg,
55  const char *field_name_arg,
56  const charset_info_st * const cs)
57  :Field_str((unsigned char*) NULL,
58  len_arg,
59  maybe_null_arg ? (unsigned char *) "": 0,
60  0,
61  field_name_arg,
62  cs)
63  {
64  flags|= BLOB_FLAG;
65  }
66 
67  enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
68  enum ha_base_keytype key_type() const
69  { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
70  int store(const char *to,uint32_t length,
71  const charset_info_st * const charset);
72  int store(double nr);
73  int store(int64_t nr, bool unsigned_val);
74 
75  double val_real(void) const;
76  int64_t val_int(void) const;
77  String *val_str(String*,String *) const;
78  type::Decimal *val_decimal(type::Decimal *) const;
79  int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
80  int cmp(const unsigned char *a,const unsigned char *b)
81  { return cmp_max(a, b, UINT32_MAX); }
82  int cmp(const unsigned char *a, uint32_t a_length, const unsigned char *b, uint32_t b_length);
83  int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
84  int key_cmp(const unsigned char *,const unsigned char*);
85  int key_cmp(const unsigned char *str, uint32_t length);
86  uint32_t key_length() const { return 0; }
87  void sort_string(unsigned char *buff,uint32_t length);
88  uint32_t pack_length() const;
89 
90 
99  uint32_t pack_length_no_ptr() const
100  { return (uint32_t) (sizeof(uint32_t)); }
101 
102  uint32_t sort_length() const;
103  virtual uint32_t max_data_length() const
104  {
105  return (uint32_t) (((uint64_t) 1 << 32) -1);
106  }
107  int reset(void) { memset(ptr, 0, sizeof(uint32_t)+sizeof(unsigned char*)); return 0; }
108  void reset_fields() { memset(&value, 0, sizeof(value)); }
109 #ifndef WORDS_BIGENDIAN
110  static
111 #endif
112  void store_length(unsigned char *i_ptr, uint32_t i_number, bool low_byte_first);
113  void store_length(unsigned char *i_ptr, uint32_t i_number);
114 
115  inline void store_length(uint32_t number)
116  {
117  store_length(ptr, number);
118  }
119 
128  uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
129 
130  DRIZZLED_API uint32_t get_length(uint32_t row_offset= 0) const;
131  DRIZZLED_API uint32_t get_length(const unsigned char *ptr, bool low_byte_first) const;
132  DRIZZLED_API uint32_t get_length(const unsigned char *ptr_arg) const;
133  void put_length(unsigned char *pos, uint32_t length);
134  inline unsigned char* get_ptr() const
135  {
136  unsigned char* str;
137  memcpy(&str, ptr + sizeof(uint32_t), sizeof(unsigned char*));
138  return str;
139  }
140  inline void set_ptr(unsigned char *length, unsigned char *data)
141  {
142  memcpy(ptr,length,sizeof(uint32_t));
143  memcpy(ptr+sizeof(uint32_t),&data,sizeof(char*));
144  }
145  void set_ptr_offset(ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
146  {
147  unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
148  store_length(ptr_ofs, length);
149  memcpy(ptr_ofs+sizeof(uint32_t),&data,sizeof(char*));
150  }
151  inline void set_ptr(uint32_t length, unsigned char *data)
152  {
153  set_ptr_offset(0, length, data);
154  }
155  uint32_t get_key_image(unsigned char *buff,uint32_t length);
156  uint32_t get_key_image(std::basic_string<unsigned char> &buff, uint32_t length);
157  void set_key_image(const unsigned char *buff,uint32_t length);
158  inline void copy()
159  {
160  value.copy((char*)get_ptr(), get_length(), charset());
161  char* tmp= value.ptr();
162  memcpy(ptr + sizeof(uint32_t), &tmp, sizeof(char*));
163  }
164  virtual unsigned char *pack(unsigned char *to, const unsigned char *from, uint32_t max_length, bool low_byte_first);
165  unsigned char *pack_key(unsigned char *to, const unsigned char *from, uint32_t max_length, bool low_byte_first);
166  virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from, uint32_t , bool low_byte_first);
167  void free() { value.free(); }
168  friend int field_conv(Field *to,Field *from);
169  uint32_t size_of() const { return sizeof(*this); }
170  bool has_charset(void) const
171  { return charset() != &my_charset_bin; }
172  uint32_t max_display_length();
173 };
174 
175 } /* namespace drizzled */
176 
177