1
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 MySQL
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.
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.
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
21
#ifndef DRIZZLED_FIELD_BLOB_H
22
#define DRIZZLED_FIELD_BLOB_H
24
#include <drizzled/field/str.h>
26
#include "drizzled/global_charset_info.h"
34
* Class representing a BLOB data type column
36
class Field_blob :public Field_str {
38
String value; // For temporaries
48
Field_blob(unsigned char *ptr_arg,
49
unsigned char *null_ptr_arg,
50
unsigned char null_bit_arg,
51
const char *field_name_arg,
53
const CHARSET_INFO * const cs);
54
Field_blob(uint32_t len_arg,
56
const char *field_name_arg,
57
const CHARSET_INFO * const cs)
58
:Field_str((unsigned char*) NULL,
60
maybe_null_arg ? (unsigned char *) "": 0,
68
enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
69
enum ha_base_keytype key_type() const
70
{ return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
71
int store(const char *to,uint32_t length,
72
const CHARSET_INFO * const charset);
74
int store(int64_t nr, bool unsigned_val);
76
double val_real(void);
77
int64_t val_int(void);
78
String *val_str(String*,String *);
79
my_decimal *val_decimal(my_decimal *);
80
int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
81
int cmp(const unsigned char *a,const unsigned char *b)
82
{ return cmp_max(a, b, UINT32_MAX); }
83
int cmp(const unsigned char *a, uint32_t a_length, const unsigned char *b, uint32_t b_length);
84
int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
85
int key_cmp(const unsigned char *,const unsigned char*);
86
int key_cmp(const unsigned char *str, uint32_t length);
87
uint32_t key_length() const { return 0; }
88
void sort_string(unsigned char *buff,uint32_t length);
89
uint32_t pack_length() const;
93
Return the packed length without the pointer size added.
95
This is used to determine the size of the actual data in the row
98
@returns The length of the raw data itself without the pointer.
100
uint32_t pack_length_no_ptr() const
101
{ return (uint32_t) (sizeof(uint32_t)); }
103
uint32_t sort_length() const;
104
virtual uint32_t max_data_length() const
106
return (uint32_t) (((uint64_t) 1 << 32) -1);
108
int reset(void) { memset(ptr, 0, sizeof(uint32_t)+sizeof(unsigned char*)); return 0; }
109
void reset_fields() { memset(&value, 0, sizeof(value)); }
110
#ifndef WORDS_BIGENDIAN
113
void store_length(unsigned char *i_ptr, uint32_t i_number, bool low_byte_first);
114
void store_length(unsigned char *i_ptr, uint32_t i_number);
116
inline void store_length(uint32_t number)
118
store_length(ptr, number);
122
Return the packed length plus the length of the data.
124
This is used to determine the size of the data plus the
125
packed length portion in the row data.
127
@returns The length in the row plus the size of the data.
129
uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
131
uint32_t get_length(uint32_t row_offset= 0);
132
uint32_t get_length(const unsigned char *ptr, bool low_byte_first);
133
uint32_t get_length(const unsigned char *ptr_arg);
134
void put_length(unsigned char *pos, uint32_t length);
135
inline void get_ptr(unsigned char **str)
137
memcpy(str,ptr+sizeof(uint32_t),sizeof(unsigned char*));
139
inline void get_ptr(unsigned char **str, uint32_t row_offset)
141
memcpy(str,ptr+sizeof(uint32_t)+row_offset,sizeof(char*));
143
inline void set_ptr(unsigned char *length, unsigned char *data)
145
memcpy(ptr,length,sizeof(uint32_t));
146
memcpy(ptr+sizeof(uint32_t),&data,sizeof(char*));
148
void set_ptr_offset(ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
150
unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
151
store_length(ptr_ofs, length);
152
memcpy(ptr_ofs+sizeof(uint32_t),&data,sizeof(char*));
154
inline void set_ptr(uint32_t length, unsigned char *data)
156
set_ptr_offset(0, length, data);
158
uint32_t get_key_image(unsigned char *buff,uint32_t length);
159
uint32_t get_key_image(std::basic_string<unsigned char> &buff, uint32_t length);
160
void set_key_image(const unsigned char *buff,uint32_t length);
161
void sql_type(String &str) const;
166
if (value.copy((char*) tmp, get_length(), charset()))
171
tmp=(unsigned char*) value.ptr();
172
memcpy(ptr+sizeof(uint32_t),&tmp,sizeof(char*));
175
virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
176
uint32_t max_length, bool low_byte_first);
177
unsigned char *pack_key(unsigned char *to, const unsigned char *from,
178
uint32_t max_length, bool low_byte_first);
179
virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
180
uint32_t , bool low_byte_first);
181
void free() { value.free(); }
182
inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
183
friend int field_conv(Field *to,Field *from);
184
uint32_t size_of() const { return sizeof(*this); }
185
bool has_charset(void) const
186
{ return charset() == &my_charset_bin ? false : true; }
187
uint32_t max_display_length();
190
} /* namespace drizzled */
192
#endif /* DRIZZLED_FIELD_BLOB_H */