~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
21
#ifndef DRIZZLE_SERVER_FIELD_BLOB
22
#define DRIZZLE_SERVER_FIELD_BLOB
23
584.5.1 by Monty Taylor
Removed field includes from field.h.
24
#include <drizzled/field/longstr.h>
25
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
26
class Field_blob :public Field_longstr {
27
protected:
482 by Brian Aker
Remove uint.
28
  uint32_t packlength;
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
29
  String value;				// For temporaries
30
public:
481 by Brian Aker
Remove all of uchar.
31
  Field_blob(unsigned char *ptr_arg, unsigned char *null_ptr_arg, unsigned char null_bit_arg,
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
32
	     enum utype unireg_check_arg, const char *field_name_arg,
482 by Brian Aker
Remove uint.
33
	     TABLE_SHARE *share, uint32_t blob_pack_length, const CHARSET_INFO * const cs);
617 by Brian Aker
ulong fixes
34
  Field_blob(uint32_t len_arg, bool maybe_null_arg, 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.
35
             const CHARSET_INFO * const cs)
481 by Brian Aker
Remove all of uchar.
36
    :Field_longstr((unsigned char*) 0, len_arg, maybe_null_arg ? (unsigned char*) "": 0, 0,
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
37
                   NONE, field_name_arg, cs),
38
    packlength(4)
39
  {
40
    flags|= BLOB_FLAG;
41
  }
617 by Brian Aker
ulong fixes
42
  Field_blob(uint32_t len_arg, bool maybe_null_arg, 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.
43
	     const CHARSET_INFO * const cs, bool set_packlength)
481 by Brian Aker
Remove all of uchar.
44
    :Field_longstr((unsigned char*) 0,len_arg, maybe_null_arg ? (unsigned char*) "": 0, 0,
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
45
                   NONE, field_name_arg, cs)
46
  {
47
    flags|= BLOB_FLAG;
48
    packlength= 4;
49
    if (set_packlength)
50
    {
51
      uint32_t l_char_length= len_arg/cs->mbmaxlen;
52
      packlength= l_char_length <= 255 ? 1 :
53
                  l_char_length <= 65535 ? 2 :
54
                  l_char_length <= 16777215 ? 3 : 4;
55
    }
56
  }
57
  Field_blob(uint32_t packlength_arg)
481 by Brian Aker
Remove all of uchar.
58
    :Field_longstr((unsigned char*) 0, 0, (unsigned char*) "", 0, NONE, "temp", system_charset_info),
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
59
    packlength(packlength_arg) {}
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
60
  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
61
  enum ha_base_keytype key_type() const
62
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
482 by Brian Aker
Remove uint.
63
  int  store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
64
  int  store(double nr);
65
  int  store(int64_t nr, bool unsigned_val);
66
  double val_real(void);
67
  int64_t val_int(void);
68
  String *val_str(String*,String *);
69
  my_decimal *val_decimal(my_decimal *);
481 by Brian Aker
Remove all of uchar.
70
  int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
71
  int cmp(const unsigned char *a,const unsigned char *b)
365.2.6 by Monty Taylor
Undid some stupid int->int16_t conversions.
72
    { return cmp_max(a, b, UINT32_MAX); }
481 by Brian Aker
Remove all of uchar.
73
  int cmp(const unsigned char *a, uint32_t a_length, const unsigned char *b, uint32_t b_length);
74
  int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
75
  int key_cmp(const unsigned char *,const unsigned char*);
482 by Brian Aker
Remove uint.
76
  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
77
  uint32_t key_length() const { return 0; }
482 by Brian Aker
Remove uint.
78
  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.
79
  uint32_t pack_length() const;
80
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
81
82
  /**
83
     Return the packed length without the pointer size added. 
84
85
     This is used to determine the size of the actual data in the row
86
     buffer.
87
88
     @returns The length of the raw data itself without the pointer.
89
  */
90
  uint32_t pack_length_no_ptr() const
91
  { return (uint32_t) (packlength); }
482 by Brian Aker
Remove uint.
92
  uint32_t row_pack_length() { return pack_length_no_ptr(); }
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
93
  uint32_t sort_length() const;
94
  virtual uint32_t max_data_length() const
95
  {
96
    return (uint32_t) (((uint64_t) 1 << (packlength*8)) -1);
97
  }
481 by Brian Aker
Remove all of uchar.
98
  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().
99
  void reset_fields() { memset(&value, 0, sizeof(value)); }
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
100
#ifndef WORDS_BIGENDIAN
101
  static
102
#endif
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
103
  void store_length(unsigned char *i_ptr, uint32_t i_packlength,
104
                    uint32_t i_number, bool low_byte_first);
105
  void store_length(unsigned char *i_ptr, uint32_t i_packlength,
106
                    uint32_t i_number);
107
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
108
  inline void store_length(uint32_t number)
109
  {
110
    store_length(ptr, packlength, number);
111
  }
112
113
  /**
114
     Return the packed length plus the length of the data. 
115
116
     This is used to determine the size of the data plus the 
117
     packed length portion in the row data.
118
119
     @returns The length in the row plus the size of the data.
120
  */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
121
  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
122
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
123
  uint32_t get_length(uint32_t row_offset= 0);
124
  uint32_t get_length(const unsigned char *ptr, uint32_t packlength,
125
                      bool low_byte_first);
126
  uint32_t get_length(const unsigned char *ptr_arg);
481 by Brian Aker
Remove all of uchar.
127
  void put_length(unsigned char *pos, uint32_t length);
128
  inline void get_ptr(unsigned char **str)
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
129
    {
481 by Brian Aker
Remove all of uchar.
130
      memcpy(str,ptr+packlength,sizeof(unsigned char*));
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
131
    }
482 by Brian Aker
Remove uint.
132
  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
133
    {
212.6.6 by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove().
134
      memcpy(str,ptr+packlength+row_offset,sizeof(char*));
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
135
    }
481 by Brian Aker
Remove all of uchar.
136
  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
137
    {
138
      memcpy(ptr,length,packlength);
212.6.3 by Mats Kindahl
Removing deprecated functions from code and replacing them with C99 equivalents:
139
      memcpy(ptr+packlength,&data,sizeof(char*));
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
140
    }
481 by Brian Aker
Remove all of uchar.
141
  void set_ptr_offset(my_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
142
    {
481 by Brian Aker
Remove all of uchar.
143
      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
144
      store_length(ptr_ofs, packlength, length);
212.6.3 by Mats Kindahl
Removing deprecated functions from code and replacing them with C99 equivalents:
145
      memcpy(ptr_ofs+packlength,&data,sizeof(char*));
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
146
    }
481 by Brian Aker
Remove all of uchar.
147
  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
148
    {
149
      set_ptr_offset(0, length, data);
150
    }
482 by Brian Aker
Remove uint.
151
  uint32_t get_key_image(unsigned char *buff,uint32_t length, imagetype type);
152
  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
153
  void sql_type(String &str) const;
154
  inline bool copy()
155
  {
481 by Brian Aker
Remove all of uchar.
156
    unsigned char *tmp;
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
157
    get_ptr(&tmp);
158
    if (value.copy((char*) tmp, get_length(), charset()))
159
    {
160
      Field_blob::reset();
161
      return 1;
162
    }
481 by Brian Aker
Remove all of uchar.
163
    tmp=(unsigned char*) value.ptr();
212.6.3 by Mats Kindahl
Removing deprecated functions from code and replacing them with C99 equivalents:
164
    memcpy(ptr+packlength,&tmp,sizeof(char*));
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
165
    return 0;
166
  }
481 by Brian Aker
Remove all of uchar.
167
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
482 by Brian Aker
Remove uint.
168
                      uint32_t max_length, bool low_byte_first);
481 by Brian Aker
Remove all of uchar.
169
  unsigned char *pack_key(unsigned char *to, const unsigned char *from,
482 by Brian Aker
Remove uint.
170
                  uint32_t max_length, bool low_byte_first);
481 by Brian Aker
Remove all of uchar.
171
  unsigned char *pack_key_from_key_image(unsigned char* to, const unsigned char *from,
482 by Brian Aker
Remove uint.
172
                                 uint32_t max_length, bool low_byte_first);
481 by Brian Aker
Remove all of uchar.
173
  virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
482 by Brian Aker
Remove uint.
174
                              uint32_t param_data, bool low_byte_first);
481 by Brian Aker
Remove all of uchar.
175
  const unsigned char *unpack_key(unsigned char* to, const unsigned char *from,
482 by Brian Aker
Remove uint.
176
                          uint32_t max_length, bool low_byte_first);
177
  int pack_cmp(const unsigned char *a, const unsigned char *b, uint32_t key_length,
275 by Brian Aker
Full removal of my_bool from central server.
178
               bool insert_or_update);
482 by Brian Aker
Remove uint.
179
  int pack_cmp(const unsigned char *b, uint32_t key_length,bool insert_or_update);
180
  uint32_t packed_col_length(const unsigned char *col_ptr, uint32_t length);
181
  uint32_t max_packed_col_length(uint32_t max_length);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
182
  void free() { value.free(); }
212.6.6 by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove().
183
  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
184
  friend int field_conv(Field *to,Field *from);
482 by Brian Aker
Remove uint.
185
  uint32_t size_of() const { return sizeof(*this); }
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
186
  bool has_charset(void) const
187
  { return charset() == &my_charset_bin ? false : true; }
188
  uint32_t max_display_length();
482 by Brian Aker
Remove uint.
189
  uint32_t is_equal(Create_field *new_field);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
190
  bool in_read_set();
191
  bool in_write_set();
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
192
private:
481 by Brian Aker
Remove all of uchar.
193
  int do_save_field_metadata(unsigned char *first_byte);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
194
};
195
196
#endif
197