~drizzle-trunk/drizzle/development

466 by Monty Taylor
Fixed modelines... these files are c++.
1
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
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
1122.2.10 by Monty Taylor
Fixed all of the include guards.
21
#ifndef DRIZZLED_FIELD_BLOB_H
22
#define DRIZZLED_FIELD_BLOB_H
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
23
1034.1.3 by Brian Aker
Collapse field classes (this does change enum/time decimal conversion
24
#include <drizzled/field/str.h>
584.5.1 by Monty Taylor
Removed field includes from field.h.
25
1241.9.28 by Monty Taylor
Removed global_charset_info.h from server_includes.h
26
#include "drizzled/global_charset_info.h"
27
656.1.1 by Monty Taylor
OOOh doggie. Got rid of my_alloca.
28
#include <string>
29
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
30
namespace drizzled
31
{
32
1055.2.5 by Jay Pipes
Removal of dead Field::image_type and st_key_part::image_type member variables. Legacy from geometry MyISAM types...
33
/**
34
 * Class representing a BLOB data type column
35
 */
1034.1.3 by Brian Aker
Collapse field classes (this does change enum/time decimal conversion
36
class Field_blob :public Field_str {
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
37
protected:
482 by Brian Aker
Remove uint.
38
  uint32_t packlength;
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
39
  String value;				// For temporaries
40
public:
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
41
42
  using Field::store;
43
  using Field::cmp;
44
  using Field::pack;
45
  using Field::unpack;
46
  using Field::val_int;
47
  using Field::val_str;
48
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
49
  Field_blob(unsigned char *ptr_arg,
50
             unsigned char *null_ptr_arg,
51
             unsigned char null_bit_arg,
1119.9.14 by Jay Pipes
Style cleanups after review. Thanks Monty :)
52
             const char *field_name_arg,
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
53
             TableShare *share,
54
             uint32_t blob_pack_length,
55
             const CHARSET_INFO * const cs);
56
  Field_blob(uint32_t len_arg,
57
             bool maybe_null_arg,
58
             const char *field_name_arg,
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
59
             const CHARSET_INFO * const cs)
1119.9.14 by Jay Pipes
Style cleanups after review. Thanks Monty :)
60
    :Field_str((unsigned char*) NULL,
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
61
               len_arg,
1119.9.14 by Jay Pipes
Style cleanups after review. Thanks Monty :)
62
               maybe_null_arg ? (unsigned char *) "": 0,
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
63
               0,
64
               field_name_arg,
65
               cs),
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
66
    packlength(4)
67
  {
68
    flags|= BLOB_FLAG;
69
  }
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
70
  Field_blob(uint32_t len_arg,
71
             bool maybe_null_arg,
72
             const char *field_name_arg,
73
             const CHARSET_INFO * const cs,
74
             bool set_packlength)
1119.9.14 by Jay Pipes
Style cleanups after review. Thanks Monty :)
75
    :Field_str((unsigned char*) NULL,
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
76
               len_arg,
77
               maybe_null_arg ? (unsigned char*) "": 0,
78
               0,
79
               field_name_arg,
80
               cs),
81
    packlength(4)
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
82
  {
83
    flags|= BLOB_FLAG;
84
    if (set_packlength)
85
    {
86
      uint32_t l_char_length= len_arg/cs->mbmaxlen;
87
      packlength= l_char_length <= 255 ? 1 :
88
                  l_char_length <= 65535 ? 2 :
89
                  l_char_length <= 16777215 ? 3 : 4;
90
    }
91
  }
92
  Field_blob(uint32_t packlength_arg)
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
93
    :Field_str((unsigned char*) 0,
94
               0,
95
               (unsigned char*) "",
96
               0,
97
               "temp",
98
               system_charset_info),
99
    packlength(packlength_arg) 
100
  {}
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
101
  enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
102
  enum ha_base_keytype key_type() const
103
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
104
  int  store(const char *to,uint32_t length,
105
             const CHARSET_INFO * const charset);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
106
  int  store(double nr);
107
  int  store(int64_t nr, bool unsigned_val);
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
108
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
109
  double val_real(void);
110
  int64_t val_int(void);
111
  String *val_str(String*,String *);
112
  my_decimal *val_decimal(my_decimal *);
481 by Brian Aker
Remove all of uchar.
113
  int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
114
  int cmp(const unsigned char *a,const unsigned char *b)
365.2.6 by Monty Taylor
Undid some stupid int->int16_t conversions.
115
    { return cmp_max(a, b, UINT32_MAX); }
481 by Brian Aker
Remove all of uchar.
116
  int cmp(const unsigned char *a, uint32_t a_length, const unsigned char *b, uint32_t b_length);
117
  int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
118
  int key_cmp(const unsigned char *,const unsigned char*);
482 by Brian Aker
Remove uint.
119
  int key_cmp(const unsigned char *str, uint32_t length);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
120
  uint32_t key_length() const { return 0; }
482 by Brian Aker
Remove uint.
121
  void sort_string(unsigned char *buff,uint32_t length);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
122
  uint32_t pack_length() const;
123
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
124
125
  /**
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
126
     Return the packed length without the pointer size added.
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
127
128
     This is used to determine the size of the actual data in the row
129
     buffer.
130
131
     @returns The length of the raw data itself without the pointer.
132
  */
133
  uint32_t pack_length_no_ptr() const
134
  { return (uint32_t) (packlength); }
135
  uint32_t sort_length() const;
136
  virtual uint32_t max_data_length() const
137
  {
138
    return (uint32_t) (((uint64_t) 1 << (packlength*8)) -1);
139
  }
481 by Brian Aker
Remove all of uchar.
140
  int reset(void) { memset(ptr, 0, packlength+sizeof(unsigned char*)); return 0; }
212.6.6 by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove().
141
  void reset_fields() { memset(&value, 0, sizeof(value)); }
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
142
#ifndef WORDS_BIGENDIAN
143
  static
144
#endif
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
145
  void store_length(unsigned char *i_ptr, uint32_t i_packlength,
146
                    uint32_t i_number, bool low_byte_first);
147
  void store_length(unsigned char *i_ptr, uint32_t i_packlength,
148
                    uint32_t i_number);
149
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
150
  inline void store_length(uint32_t number)
151
  {
152
    store_length(ptr, packlength, number);
153
  }
154
155
  /**
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
156
     Return the packed length plus the length of the data.
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
157
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
158
     This is used to determine the size of the data plus the
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
159
     packed length portion in the row data.
160
161
     @returns The length in the row plus the size of the data.
162
  */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
163
  uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
164
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
165
  uint32_t get_length(uint32_t row_offset= 0);
166
  uint32_t get_length(const unsigned char *ptr, uint32_t packlength,
167
                      bool low_byte_first);
168
  uint32_t get_length(const unsigned char *ptr_arg);
481 by Brian Aker
Remove all of uchar.
169
  void put_length(unsigned char *pos, uint32_t length);
170
  inline void get_ptr(unsigned char **str)
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
171
    {
481 by Brian Aker
Remove all of uchar.
172
      memcpy(str,ptr+packlength,sizeof(unsigned char*));
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
173
    }
482 by Brian Aker
Remove uint.
174
  inline void get_ptr(unsigned char **str, uint32_t row_offset)
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
175
    {
212.6.6 by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove().
176
      memcpy(str,ptr+packlength+row_offset,sizeof(char*));
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
177
    }
481 by Brian Aker
Remove all of uchar.
178
  inline void set_ptr(unsigned char *length, unsigned char *data)
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
179
    {
180
      memcpy(ptr,length,packlength);
212.6.3 by Mats Kindahl
Removing deprecated functions from code and replacing them with C99 equivalents:
181
      memcpy(ptr+packlength,&data,sizeof(char*));
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
182
    }
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
183
  void set_ptr_offset(ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
184
    {
481 by Brian Aker
Remove all of uchar.
185
      unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
186
      store_length(ptr_ofs, packlength, length);
212.6.3 by Mats Kindahl
Removing deprecated functions from code and replacing them with C99 equivalents:
187
      memcpy(ptr_ofs+packlength,&data,sizeof(char*));
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
188
    }
481 by Brian Aker
Remove all of uchar.
189
  inline void set_ptr(uint32_t length, unsigned char *data)
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
190
    {
191
      set_ptr_offset(0, length, data);
192
    }
1055.2.5 by Jay Pipes
Removal of dead Field::image_type and st_key_part::image_type member variables. Legacy from geometry MyISAM types...
193
  uint32_t get_key_image(unsigned char *buff,uint32_t length);
194
  uint32_t get_key_image(std::basic_string<unsigned char> &buff, uint32_t length);
482 by Brian Aker
Remove uint.
195
  void set_key_image(const unsigned char *buff,uint32_t length);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
196
  void sql_type(String &str) const;
197
  inline bool copy()
198
  {
481 by Brian Aker
Remove all of uchar.
199
    unsigned char *tmp;
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
200
    get_ptr(&tmp);
201
    if (value.copy((char*) tmp, get_length(), charset()))
202
    {
203
      Field_blob::reset();
204
      return 1;
205
    }
481 by Brian Aker
Remove all of uchar.
206
    tmp=(unsigned char*) value.ptr();
212.6.3 by Mats Kindahl
Removing deprecated functions from code and replacing them with C99 equivalents:
207
    memcpy(ptr+packlength,&tmp,sizeof(char*));
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
208
    return 0;
209
  }
481 by Brian Aker
Remove all of uchar.
210
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
482 by Brian Aker
Remove uint.
211
                      uint32_t max_length, bool low_byte_first);
481 by Brian Aker
Remove all of uchar.
212
  unsigned char *pack_key(unsigned char *to, const unsigned char *from,
482 by Brian Aker
Remove uint.
213
                  uint32_t max_length, bool low_byte_first);
481 by Brian Aker
Remove all of uchar.
214
  virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
482 by Brian Aker
Remove uint.
215
                              uint32_t param_data, bool low_byte_first);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
216
  void free() { value.free(); }
212.6.6 by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove().
217
  inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
218
  friend int field_conv(Field *to,Field *from);
482 by Brian Aker
Remove uint.
219
  uint32_t size_of() const { return sizeof(*this); }
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
220
  bool has_charset(void) const
221
  { return charset() == &my_charset_bin ? false : true; }
222
  uint32_t max_display_length();
223
};
224
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
225
} /* namespace drizzled */
226
1122.2.10 by Monty Taylor
Fixed all of the include guards.
227
#endif /* DRIZZLED_FIELD_BLOB_H */
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
228