drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
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 <new>
26#include <string>
27#include <drizzled/visibility.h>
28
29namespace drizzled {
30
34class DRIZZLED_API Field_blob :
35 public Field_str
36{
37protected:
38 String value; // For temporaries
39public:
40
41 using Field::store;
42 using Field::cmp;
43 using Field::pack;
44 using Field::unpack;
45 using Field::val_int;
46 using Field::val_str;
47
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,
52 TableShare *share,
53 const charset_info_st * const cs);
54 Field_blob(uint32_t len_arg,
55 bool maybe_null_arg,
56 const char *field_name_arg,
57 const charset_info_st * const cs)
58 :Field_str((unsigned char*) NULL,
59 len_arg,
60 maybe_null_arg ? (unsigned char *) "": 0,
61 0,
62 field_name_arg,
63 cs)
64 {
65 flags|= BLOB_FLAG;
66 }
67
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_st * const charset);
73 int store(double nr);
74 int store(int64_t nr, bool unsigned_val);
75
76 double val_real(void) const;
77 int64_t val_int(void) const;
78 String *val_str(String*,String *) const;
79 type::Decimal *val_decimal(type::Decimal *) const;
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;
90
91
100 uint32_t pack_length_no_ptr() const
101 { return (uint32_t) (sizeof(uint32_t)); }
102
103 uint32_t sort_length() const;
104 virtual uint32_t max_data_length() const
105 {
106 return (uint32_t) (((uint64_t) 1 << 32) -1);
107 }
108 int reset(void) { memset(ptr, 0, sizeof(uint32_t)+sizeof(unsigned char*)); return 0; }
109 void reset_fields()
110 {
111 /* Field::new_field() creates a raw memdup clone; do not free the clone. */
112 ::new (static_cast<void *>(&value)) String();
113 }
114#ifndef WORDS_BIGENDIAN
115 static
116#endif
117 void store_length(unsigned char *i_ptr, uint32_t i_number, bool low_byte_first);
118 void store_length(unsigned char *i_ptr, uint32_t i_number);
119
120 inline void store_length(uint32_t number)
121 {
122 store_length(ptr, number);
123 }
124
133 uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
134
135 DRIZZLED_API uint32_t get_length(uint32_t row_offset= 0) const;
136 DRIZZLED_API uint32_t get_length(const unsigned char *ptr, bool low_byte_first) const;
137 DRIZZLED_API uint32_t get_length(const unsigned char *ptr_arg) const;
138 void put_length(unsigned char *pos, uint32_t length);
139 inline unsigned char* get_ptr() const
140 {
141 unsigned char* str;
142 memcpy(&str, ptr + sizeof(uint32_t), sizeof(unsigned char*));
143 return str;
144 }
145 inline void set_ptr(unsigned char *length, unsigned char *data)
146 {
147 memcpy(ptr,length,sizeof(uint32_t));
148 memcpy(ptr+sizeof(uint32_t),&data,sizeof(char*));
149 }
150 void set_ptr_offset(ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
151 {
152 unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
153 store_length(ptr_ofs, length);
154 memcpy(ptr_ofs+sizeof(uint32_t),&data,sizeof(char*));
155 }
156 inline void set_ptr(uint32_t length, unsigned char *data)
157 {
158 set_ptr_offset(0, length, data);
159 }
160 uint32_t get_key_image(unsigned char *buff,uint32_t length);
161 uint32_t get_key_image(std::basic_string<unsigned char> &buff, uint32_t length);
162 void set_key_image(const unsigned char *buff,uint32_t length);
163 inline void copy()
164 {
165 value.copy((char*)get_ptr(), get_length(), charset());
166 char* tmp= value.ptr();
167 memcpy(ptr + sizeof(uint32_t), &tmp, sizeof(char*));
168 }
169 virtual unsigned char *pack(unsigned char *to, const unsigned char *from, uint32_t max_length, bool low_byte_first);
170 unsigned char *pack_key(unsigned char *to, const unsigned char *from, uint32_t max_length, bool low_byte_first);
171 virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from, uint32_t , bool low_byte_first);
172 void free() { value.free(); }
173 friend int field_conv(Field *to,Field *from);
174 uint32_t size_of() const { return sizeof(*this); }
175 bool has_charset(void) const
176 { return charset() != &my_charset_bin; }
177 uint32_t max_display_length();
178};
179
180} /* namespace drizzled */
virtual uint32_t max_data_length() const
Definition blob.h:104
uint32_t pack_length() const
Definition blob.cc:445
uint32_t pack_length_no_ptr() const
Definition blob.h:100
virtual const unsigned char * unpack(unsigned char *to, const unsigned char *from, uint32_t param_data, bool low_byte_first)
Definition field.cc:968
virtual unsigned char * pack(unsigned char *to, const unsigned char *from, uint32_t max_length, bool low_byte_first)
Definition field.cc:955
TODO: Rename this file - func.h is stupid.
int field_conv(Field *to, Field *from)
Visibility Control Macros.
#define DRIZZLED_API
Definition visibility.h:38