520.1.25
by Monty Taylor
Removed the split. |
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 |
||
1241.9.36
by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h. |
22 |
#include "config.h" |
214
by Brian Aker
Rename of fields (fix issue with string and decimal .h clashing). |
23 |
#include <drizzled/field/blob.h> |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
24 |
#include <drizzled/table.h> |
25 |
#include <drizzled/session.h> |
|
1241.9.62
by Monty Taylor
Removed plugin/myisam/myisam.h from session.h |
26 |
#include "plugin/myisam/myisam.h" |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
27 |
|
656.1.1
by Monty Taylor
OOOh doggie. Got rid of my_alloca. |
28 |
#include <string> |
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
29 |
#include <algorithm> |
656.1.1
by Monty Taylor
OOOh doggie. Got rid of my_alloca. |
30 |
|
31 |
using namespace std; |
|
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
32 |
|
1085.1.2
by Monty Taylor
Fixed -Wmissing-declarations |
33 |
static uint32_t blob_pack_length_to_max_length(uint32_t arg) |
322.2.2
by Mats Kindahl
Hiding THD::proc_info field and providing a setter and getter. |
34 |
{
|
1067.4.6
by Nathan Williams
Converted all usages of cmax in drizzled/field/ and drizzled/function/ to std::max. |
35 |
return max(UINT32_MAX, |
36 |
(uint32_t)((INT64_C(1) << min(arg, 4U) * 8) - INT64_C(1))); |
|
322.2.2
by Mats Kindahl
Hiding THD::proc_info field and providing a setter and getter. |
37 |
}
|
38 |
||
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
39 |
|
40 |
/****************************************************************************
|
|
41 |
** blob type
|
|
42 |
** A blob is saved as a length and a pointer. The length is stored in the
|
|
43 |
** packlength slot and may be from 1-4.
|
|
44 |
****************************************************************************/
|
|
45 |
||
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. |
46 |
Field_blob::Field_blob(unsigned char *ptr_arg, |
47 |
unsigned char *null_ptr_arg, |
|
48 |
unsigned char null_bit_arg, |
|
49 |
const char *field_name_arg, |
|
50 |
TableShare *share, |
|
51 |
uint32_t blob_pack_length, |
|
52 |
const CHARSET_INFO * const cs) |
|
53 |
:Field_str(ptr_arg, |
|
54 |
blob_pack_length_to_max_length(blob_pack_length), |
|
55 |
null_ptr_arg, |
|
56 |
null_bit_arg, |
|
57 |
field_name_arg, |
|
58 |
cs), |
|
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
59 |
packlength(blob_pack_length) |
60 |
{
|
|
61 |
flags|= BLOB_FLAG; |
|
62 |
share->blob_fields++; |
|
63 |
/* TODO: why do not fill table->s->blob_field array here? */
|
|
64 |
}
|
|
65 |
||
481
by Brian Aker
Remove all of uchar. |
66 |
void Field_blob::store_length(unsigned char *i_ptr, |
482
by Brian Aker
Remove uint. |
67 |
uint32_t i_packlength, |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
68 |
uint32_t i_number, |
779.1.30
by Monty Taylor
Quick fix for #ifdef WORDS_BIGENDIAN. |
69 |
bool low_byte_first) |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
70 |
{
|
779.1.30
by Monty Taylor
Quick fix for #ifdef WORDS_BIGENDIAN. |
71 |
#ifndef WORDS_BIGENDIAN
|
72 |
(void)low_byte_first; |
|
73 |
#endif
|
|
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
74 |
switch (i_packlength) { |
75 |
case 1: |
|
481
by Brian Aker
Remove all of uchar. |
76 |
i_ptr[0]= (unsigned char) i_number; |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
77 |
break; |
78 |
case 2: |
|
79 |
#ifdef WORDS_BIGENDIAN
|
|
80 |
if (low_byte_first) |
|
81 |
{
|
|
82 |
int2store(i_ptr,(unsigned short) i_number); |
|
83 |
}
|
|
84 |
else
|
|
85 |
#endif
|
|
86 |
shortstore(i_ptr,(unsigned short) i_number); |
|
87 |
break; |
|
88 |
case 3: |
|
89 |
int3store(i_ptr,i_number); |
|
90 |
break; |
|
91 |
case 4: |
|
92 |
#ifdef WORDS_BIGENDIAN
|
|
93 |
if (low_byte_first) |
|
94 |
{
|
|
95 |
int4store(i_ptr,i_number); |
|
96 |
}
|
|
97 |
else
|
|
98 |
#endif
|
|
99 |
longstore(i_ptr,i_number); |
|
100 |
}
|
|
101 |
}
|
|
102 |
||
103 |
||
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
104 |
void Field_blob::store_length(unsigned char *i_ptr, uint32_t i_packlength, |
105 |
uint32_t i_number) |
|
106 |
{
|
|
107 |
store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first); |
|
108 |
}
|
|
109 |
||
110 |
||
481
by Brian Aker
Remove all of uchar. |
111 |
uint32_t Field_blob::get_length(const unsigned char *pos, |
779.1.30
by Monty Taylor
Quick fix for #ifdef WORDS_BIGENDIAN. |
112 |
uint32_t packlength_arg, |
113 |
bool low_byte_first) |
|
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
114 |
{
|
779.1.30
by Monty Taylor
Quick fix for #ifdef WORDS_BIGENDIAN. |
115 |
#ifndef WORDS_BIGENDIAN
|
116 |
(void)low_byte_first; |
|
117 |
#endif
|
|
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
118 |
switch (packlength_arg) { |
119 |
case 1: |
|
120 |
return (uint32_t) pos[0]; |
|
121 |
case 2: |
|
122 |
{
|
|
206
by Brian Aker
Removed final uint dead types. |
123 |
uint16_t tmp; |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
124 |
#ifdef WORDS_BIGENDIAN
|
125 |
if (low_byte_first) |
|
126 |
tmp=sint2korr(pos); |
|
127 |
else
|
|
128 |
#endif
|
|
129 |
shortget(tmp,pos); |
|
130 |
return (uint32_t) tmp; |
|
131 |
}
|
|
132 |
case 3: |
|
133 |
return (uint32_t) uint3korr(pos); |
|
134 |
case 4: |
|
135 |
{
|
|
136 |
uint32_t tmp; |
|
137 |
#ifdef WORDS_BIGENDIAN
|
|
138 |
if (low_byte_first) |
|
139 |
tmp=uint4korr(pos); |
|
140 |
else
|
|
141 |
#endif
|
|
142 |
longget(tmp,pos); |
|
143 |
return (uint32_t) tmp; |
|
144 |
}
|
|
145 |
}
|
|
146 |
return 0; // Impossible |
|
147 |
}
|
|
148 |
||
149 |
||
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
150 |
uint32_t Field_blob::get_packed_size(const unsigned char *ptr_arg, |
151 |
bool low_byte_first) |
|
152 |
{
|
|
153 |
return packlength + get_length(ptr_arg, packlength, low_byte_first); |
|
154 |
}
|
|
155 |
||
156 |
||
157 |
uint32_t Field_blob::get_length(uint32_t row_offset) |
|
158 |
{
|
|
159 |
return get_length(ptr+row_offset, this->packlength, |
|
160 |
table->s->db_low_byte_first); |
|
161 |
}
|
|
162 |
||
163 |
||
164 |
uint32_t Field_blob::get_length(const unsigned char *ptr_arg) |
|
165 |
{
|
|
166 |
return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first); |
|
167 |
}
|
|
168 |
||
169 |
||
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
170 |
/**
|
171 |
Put a blob length field into a record buffer.
|
|
172 |
||
173 |
Depending on the maximum length of a blob, its length field is
|
|
174 |
put into 1 to 4 bytes. This is a property of the blob object,
|
|
175 |
described by 'packlength'.
|
|
176 |
||
177 |
@param pos Pointer into the record buffer.
|
|
178 |
@param length The length value to put.
|
|
179 |
*/
|
|
180 |
||
481
by Brian Aker
Remove all of uchar. |
181 |
void Field_blob::put_length(unsigned char *pos, uint32_t length) |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
182 |
{
|
183 |
switch (packlength) { |
|
184 |
case 1: |
|
185 |
*pos= (char) length; |
|
186 |
break; |
|
187 |
case 2: |
|
188 |
int2store(pos, length); |
|
189 |
break; |
|
190 |
case 3: |
|
191 |
int3store(pos, length); |
|
192 |
break; |
|
193 |
case 4: |
|
194 |
int4store(pos, length); |
|
195 |
break; |
|
196 |
}
|
|
197 |
}
|
|
198 |
||
199 |
||
482
by Brian Aker
Remove uint. |
200 |
int Field_blob::store(const char *from,uint32_t length, const CHARSET_INFO * const cs) |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
201 |
{
|
482
by Brian Aker
Remove uint. |
202 |
uint32_t copy_length, new_length; |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
203 |
const char *well_formed_error_pos; |
204 |
const char *cannot_convert_error_pos; |
|
205 |
const char *from_end_pos, *tmp; |
|
206 |
char buff[STRING_BUFFER_USUAL_SIZE]; |
|
207 |
String tmpstr(buff,sizeof(buff), &my_charset_bin); |
|
208 |
||
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
209 |
ASSERT_COLUMN_MARKED_FOR_WRITE; |
210 |
||
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
211 |
if (!length) |
212 |
{
|
|
212.6.1
by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file. |
213 |
memset(ptr, 0, Field_blob::pack_length()); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
214 |
return 0; |
215 |
}
|
|
216 |
||
217 |
if (from == value.ptr()) |
|
218 |
{
|
|
219 |
uint32_t dummy_offset; |
|
220 |
if (!String::needs_conversion(length, cs, field_charset, &dummy_offset)) |
|
221 |
{
|
|
222 |
Field_blob::store_length(length); |
|
629.3.6
by Kristian Nielsen
A couple more fixes of previous bmove()->memcpy(), changed to |
223 |
memmove(ptr+packlength, &from, sizeof(char*)); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
224 |
return 0; |
225 |
}
|
|
226 |
if (tmpstr.copy(from, length, cs)) |
|
227 |
goto oom_error; |
|
228 |
from= tmpstr.ptr(); |
|
229 |
}
|
|
230 |
||
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
231 |
new_length= min(max_data_length(), field_charset->mbmaxlen * length); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
232 |
if (value.alloc(new_length)) |
233 |
goto oom_error; |
|
234 |
||
235 |
/*
|
|
236 |
"length" is OK as "nchars" argument to well_formed_copy_nchars as this
|
|
237 |
is never used to limit the length of the data. The cut of long data
|
|
238 |
is done with the new_length value.
|
|
239 |
*/
|
|
240 |
copy_length= well_formed_copy_nchars(field_charset, |
|
241 |
(char*) value.ptr(), new_length, |
|
242 |
cs, from, length, |
|
243 |
length, |
|
244 |
&well_formed_error_pos, |
|
245 |
&cannot_convert_error_pos, |
|
246 |
&from_end_pos); |
|
247 |
||
248 |
Field_blob::store_length(copy_length); |
|
249 |
tmp= value.ptr(); |
|
629.3.6
by Kristian Nielsen
A couple more fixes of previous bmove()->memcpy(), changed to |
250 |
memmove(ptr+packlength, &tmp, sizeof(char*)); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
251 |
|
252 |
if (check_string_copy_error(this, well_formed_error_pos, |
|
253 |
cannot_convert_error_pos, from + length, cs)) |
|
254 |
return 2; |
|
255 |
||
256 |
return report_if_important_data(from_end_pos, from + length); |
|
257 |
||
258 |
oom_error: |
|
259 |
/* Fatal OOM error */
|
|
212.6.1
by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file. |
260 |
memset(ptr, 0, Field_blob::pack_length()); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
261 |
return -1; |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
262 |
}
|
263 |
||
264 |
||
265 |
int Field_blob::store(double nr) |
|
266 |
{
|
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
267 |
const CHARSET_INFO * const cs=charset(); |
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
268 |
ASSERT_COLUMN_MARKED_FOR_WRITE; |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
269 |
value.set_real(nr, NOT_FIXED_DEC, cs); |
895
by Brian Aker
Completion (?) of uint conversion. |
270 |
return Field_blob::store(value.ptr(),(uint32_t) value.length(), cs); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
271 |
}
|
272 |
||
273 |
||
274 |
int Field_blob::store(int64_t nr, bool unsigned_val) |
|
275 |
{
|
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
276 |
const CHARSET_INFO * const cs=charset(); |
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
277 |
ASSERT_COLUMN_MARKED_FOR_WRITE; |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
278 |
value.set_int(nr, unsigned_val, cs); |
895
by Brian Aker
Completion (?) of uint conversion. |
279 |
return Field_blob::store(value.ptr(), (uint32_t) value.length(), cs); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
280 |
}
|
281 |
||
282 |
||
283 |
double Field_blob::val_real(void) |
|
284 |
{
|
|
285 |
int not_used; |
|
286 |
char *end_not_used, *blob; |
|
287 |
uint32_t length; |
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
288 |
const CHARSET_INFO *cs; |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
289 |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
290 |
ASSERT_COLUMN_MARKED_FOR_READ; |
291 |
||
212.6.3
by Mats Kindahl
Removing deprecated functions from code and replacing them with C99 equivalents: |
292 |
memcpy(&blob,ptr+packlength,sizeof(char*)); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
293 |
if (!blob) |
294 |
return 0.0; |
|
295 |
length= get_length(ptr); |
|
296 |
cs= charset(); |
|
297 |
return my_strntod(cs, blob, length, &end_not_used, ¬_used); |
|
298 |
}
|
|
299 |
||
300 |
||
301 |
int64_t Field_blob::val_int(void) |
|
302 |
{
|
|
303 |
int not_used; |
|
304 |
char *blob; |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
305 |
|
306 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
307 |
||
212.6.3
by Mats Kindahl
Removing deprecated functions from code and replacing them with C99 equivalents: |
308 |
memcpy(&blob,ptr+packlength,sizeof(char*)); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
309 |
if (!blob) |
310 |
return 0; |
|
311 |
uint32_t length=get_length(ptr); |
|
312 |
return my_strntoll(charset(),blob,length,10,NULL,¬_used); |
|
313 |
}
|
|
314 |
||
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
315 |
String *Field_blob::val_str(String *, |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
316 |
String *val_ptr) |
317 |
{
|
|
318 |
char *blob; |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
319 |
|
320 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
321 |
||
212.6.3
by Mats Kindahl
Removing deprecated functions from code and replacing them with C99 equivalents: |
322 |
memcpy(&blob,ptr+packlength,sizeof(char*)); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
323 |
if (!blob) |
324 |
val_ptr->set("",0,charset()); // A bit safer than ->length(0) |
|
325 |
else
|
|
326 |
val_ptr->set((const char*) blob,get_length(ptr),charset()); |
|
327 |
return val_ptr; |
|
328 |
}
|
|
329 |
||
330 |
||
331 |
my_decimal *Field_blob::val_decimal(my_decimal *decimal_value) |
|
332 |
{
|
|
333 |
const char *blob; |
|
334 |
size_t length; |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
335 |
|
336 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
337 |
||
481
by Brian Aker
Remove all of uchar. |
338 |
memcpy(&blob, ptr+packlength, sizeof(const unsigned char*)); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
339 |
if (!blob) |
340 |
{
|
|
341 |
blob= ""; |
|
342 |
length= 0; |
|
343 |
}
|
|
344 |
else
|
|
345 |
length= get_length(ptr); |
|
346 |
||
347 |
str2my_decimal(E_DEC_FATAL_ERROR, blob, length, charset(), |
|
348 |
decimal_value); |
|
349 |
return decimal_value; |
|
350 |
}
|
|
351 |
||
352 |
||
481
by Brian Aker
Remove all of uchar. |
353 |
int Field_blob::cmp(const unsigned char *a,uint32_t a_length, const unsigned char *b, |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
354 |
uint32_t b_length) |
355 |
{
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
356 |
return field_charset->coll->strnncollsp(field_charset, |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
357 |
a, a_length, b, b_length, |
358 |
0); |
|
359 |
}
|
|
360 |
||
361 |
||
481
by Brian Aker
Remove all of uchar. |
362 |
int Field_blob::cmp_max(const unsigned char *a_ptr, const unsigned char *b_ptr, |
482
by Brian Aker
Remove uint. |
363 |
uint32_t max_length) |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
364 |
{
|
481
by Brian Aker
Remove all of uchar. |
365 |
unsigned char *blob1,*blob2; |
212.6.3
by Mats Kindahl
Removing deprecated functions from code and replacing them with C99 equivalents: |
366 |
memcpy(&blob1,a_ptr+packlength,sizeof(char*)); |
367 |
memcpy(&blob2,b_ptr+packlength,sizeof(char*)); |
|
482
by Brian Aker
Remove uint. |
368 |
uint32_t a_len= get_length(a_ptr), b_len= get_length(b_ptr); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
369 |
set_if_smaller(a_len, max_length); |
370 |
set_if_smaller(b_len, max_length); |
|
371 |
return Field_blob::cmp(blob1,a_len,blob2,b_len); |
|
372 |
}
|
|
373 |
||
374 |
||
481
by Brian Aker
Remove all of uchar. |
375 |
int Field_blob::cmp_binary(const unsigned char *a_ptr, const unsigned char *b_ptr, |
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
376 |
uint32_t max_length) |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
377 |
{
|
378 |
char *a,*b; |
|
482
by Brian Aker
Remove uint. |
379 |
uint32_t diff; |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
380 |
uint32_t a_length,b_length; |
212.6.3
by Mats Kindahl
Removing deprecated functions from code and replacing them with C99 equivalents: |
381 |
memcpy(&a,a_ptr+packlength,sizeof(char*)); |
382 |
memcpy(&b,b_ptr+packlength,sizeof(char*)); |
|
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
383 |
|
384 |
a_length= get_length(a_ptr); |
|
385 |
||
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
386 |
if (a_length > max_length) |
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
387 |
a_length= max_length; |
388 |
||
389 |
b_length= get_length(b_ptr); |
|
390 |
||
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
391 |
if (b_length > max_length) |
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
392 |
b_length= max_length; |
393 |
||
394 |
diff= memcmp(a,b,min(a_length,b_length)); |
|
395 |
||
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
396 |
return diff ? diff : (int) (a_length - b_length); |
397 |
}
|
|
398 |
||
399 |
/* The following is used only when comparing a key */
|
|
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... |
400 |
uint32_t Field_blob::get_key_image(unsigned char *buff, uint32_t length) |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
401 |
{
|
402 |
uint32_t blob_length= get_length(ptr); |
|
481
by Brian Aker
Remove all of uchar. |
403 |
unsigned char *blob; |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
404 |
|
405 |
get_ptr(&blob); |
|
482
by Brian Aker
Remove uint. |
406 |
uint32_t local_char_length= length / field_charset->mbmaxlen; |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
407 |
local_char_length= my_charpos(field_charset, blob, blob + blob_length, |
408 |
local_char_length); |
|
409 |
set_if_smaller(blob_length, local_char_length); |
|
410 |
||
411 |
if ((uint32_t) length > blob_length) |
|
412 |
{
|
|
413 |
/*
|
|
1237.9.2
by Padraig O'Sullivan
Moved opt_range.[cc,h] into the optimizer directory and namespace and renamed the files to |
414 |
Must clear this as we do a memcmp in optimizer/range.cc to detect
|
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
415 |
identical keys
|
416 |
*/
|
|
212.6.1
by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file. |
417 |
memset(buff+HA_KEY_BLOB_LENGTH+blob_length, 0, (length-blob_length)); |
895
by Brian Aker
Completion (?) of uint conversion. |
418 |
length=(uint32_t) blob_length; |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
419 |
}
|
420 |
int2store(buff,length); |
|
421 |
memcpy(buff+HA_KEY_BLOB_LENGTH, blob, length); |
|
422 |
return HA_KEY_BLOB_LENGTH+length; |
|
423 |
}
|
|
424 |
||
425 |
||
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... |
426 |
uint32_t Field_blob::get_key_image(basic_string<unsigned char> &buff, uint32_t length) |
656.1.1
by Monty Taylor
OOOh doggie. Got rid of my_alloca. |
427 |
{
|
428 |
uint32_t blob_length= get_length(ptr); |
|
429 |
unsigned char *blob; |
|
430 |
||
431 |
get_ptr(&blob); |
|
432 |
uint32_t local_char_length= length / field_charset->mbmaxlen; |
|
433 |
local_char_length= my_charpos(field_charset, blob, blob + blob_length, |
|
434 |
local_char_length); |
|
435 |
set_if_smaller(blob_length, local_char_length); |
|
436 |
||
437 |
unsigned char len_buff[HA_KEY_BLOB_LENGTH]; |
|
438 |
int2store(len_buff,length); |
|
439 |
buff.append(len_buff); |
|
440 |
buff.append(blob, blob_length); |
|
441 |
||
442 |
if (length > blob_length) |
|
443 |
{
|
|
444 |
/*
|
|
1237.9.2
by Padraig O'Sullivan
Moved opt_range.[cc,h] into the optimizer directory and namespace and renamed the files to |
445 |
Must clear this as we do a memcmp in optimizer/range.cc to detect
|
656.1.1
by Monty Taylor
OOOh doggie. Got rid of my_alloca. |
446 |
identical keys
|
447 |
*/
|
|
448 |
||
449 |
buff.append(length-blob_length, '0'); |
|
450 |
}
|
|
451 |
return HA_KEY_BLOB_LENGTH+length; |
|
452 |
}
|
|
453 |
||
482
by Brian Aker
Remove uint. |
454 |
void Field_blob::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 |
455 |
{
|
456 |
length= uint2korr(buff); |
|
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... |
457 |
(void) Field_blob::store((const char*) buff+HA_KEY_BLOB_LENGTH, length, field_charset); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
458 |
}
|
459 |
||
482
by Brian Aker
Remove uint. |
460 |
int Field_blob::key_cmp(const unsigned char *key_ptr, uint32_t max_key_length) |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
461 |
{
|
481
by Brian Aker
Remove all of uchar. |
462 |
unsigned char *blob1; |
482
by Brian Aker
Remove uint. |
463 |
uint32_t blob_length=get_length(ptr); |
212.6.3
by Mats Kindahl
Removing deprecated functions from code and replacing them with C99 equivalents: |
464 |
memcpy(&blob1,ptr+packlength,sizeof(char*)); |
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
465 |
const CHARSET_INFO * const cs= charset(); |
482
by Brian Aker
Remove uint. |
466 |
uint32_t local_char_length= max_key_length / cs->mbmaxlen; |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
467 |
local_char_length= my_charpos(cs, blob1, blob1+blob_length, |
468 |
local_char_length); |
|
469 |
set_if_smaller(blob_length, local_char_length); |
|
470 |
return Field_blob::cmp(blob1, blob_length, |
|
471 |
key_ptr+HA_KEY_BLOB_LENGTH, |
|
472 |
uint2korr(key_ptr)); |
|
473 |
}
|
|
474 |
||
481
by Brian Aker
Remove all of uchar. |
475 |
int Field_blob::key_cmp(const unsigned char *a,const unsigned char *b) |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
476 |
{
|
477 |
return Field_blob::cmp(a+HA_KEY_BLOB_LENGTH, uint2korr(a), |
|
478 |
b+HA_KEY_BLOB_LENGTH, uint2korr(b)); |
|
479 |
}
|
|
480 |
||
481 |
uint32_t Field_blob::sort_length() const |
|
482 |
{
|
|
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
483 |
return (uint32_t) (current_session->variables.max_sort_length + |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
484 |
(field_charset == &my_charset_bin ? 0 : packlength)); |
485 |
}
|
|
486 |
||
482
by Brian Aker
Remove uint. |
487 |
void Field_blob::sort_string(unsigned char *to,uint32_t length) |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
488 |
{
|
481
by Brian Aker
Remove all of uchar. |
489 |
unsigned char *blob; |
482
by Brian Aker
Remove uint. |
490 |
uint32_t blob_length=get_length(); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
491 |
|
492 |
if (!blob_length) |
|
212.6.1
by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file. |
493 |
memset(to, 0, length); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
494 |
else
|
495 |
{
|
|
496 |
if (field_charset == &my_charset_bin) |
|
497 |
{
|
|
481
by Brian Aker
Remove all of uchar. |
498 |
unsigned char *pos; |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
499 |
|
500 |
/*
|
|
501 |
Store length of blob last in blob to shorter blobs before longer blobs
|
|
502 |
*/
|
|
503 |
length-= packlength; |
|
504 |
pos= to+length; |
|
505 |
||
506 |
switch (packlength) { |
|
507 |
case 1: |
|
508 |
*pos= (char) blob_length; |
|
509 |
break; |
|
510 |
case 2: |
|
511 |
mi_int2store(pos, blob_length); |
|
512 |
break; |
|
513 |
case 3: |
|
514 |
mi_int3store(pos, blob_length); |
|
515 |
break; |
|
516 |
case 4: |
|
517 |
mi_int4store(pos, blob_length); |
|
518 |
break; |
|
519 |
}
|
|
520 |
}
|
|
212.6.3
by Mats Kindahl
Removing deprecated functions from code and replacing them with C99 equivalents: |
521 |
memcpy(&blob,ptr+packlength,sizeof(char*)); |
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
522 |
|
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
523 |
blob_length=my_strnxfrm(field_charset, |
524 |
to, length, blob, blob_length); |
|
525 |
assert(blob_length == length); |
|
526 |
}
|
|
527 |
}
|
|
528 |
||
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
529 |
uint32_t Field_blob::pack_length() const |
530 |
{
|
|
531 |
return (uint32_t) (packlength+table->s->blob_ptr_size); |
|
532 |
}
|
|
533 |
||
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
534 |
void Field_blob::sql_type(String &res) const |
535 |
{
|
|
536 |
if (charset() == &my_charset_bin) |
|
221
by Brian Aker
First pass of removing length types for ints. |
537 |
res.set_ascii(STRING_WITH_LEN("blob")); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
538 |
else
|
221
by Brian Aker
First pass of removing length types for ints. |
539 |
res.set_ascii(STRING_WITH_LEN("text")); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
540 |
}
|
541 |
||
481
by Brian Aker
Remove all of uchar. |
542 |
unsigned char *Field_blob::pack(unsigned char *to, const unsigned char *from, |
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
543 |
uint32_t max_length, bool low_byte_first) |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
544 |
{
|
481
by Brian Aker
Remove all of uchar. |
545 |
unsigned char *save= ptr; |
546 |
ptr= (unsigned char*) from; |
|
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
547 |
uint32_t length= get_length(); // Length of from string |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
548 |
|
549 |
/*
|
|
550 |
Store max length, which will occupy packlength bytes. If the max
|
|
551 |
length given is smaller than the actual length of the blob, we
|
|
552 |
just store the initial bytes of the blob.
|
|
553 |
*/
|
|
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
554 |
store_length(to, packlength, min(length, max_length), low_byte_first); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
555 |
|
556 |
/*
|
|
557 |
Store the actual blob data, which will occupy 'length' bytes.
|
|
558 |
*/
|
|
559 |
if (length > 0) |
|
560 |
{
|
|
481
by Brian Aker
Remove all of uchar. |
561 |
get_ptr((unsigned char**) &from); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
562 |
memcpy(to+packlength, from,length); |
563 |
}
|
|
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
564 |
|
565 |
ptr= save; // Restore org row pointer |
|
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
566 |
return(to+packlength+length); |
567 |
}
|
|
568 |
||
569 |
/**
|
|
570 |
Unpack a blob field from row data.
|
|
571 |
||
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
572 |
This method is used to unpack a blob field from a master whose size of
|
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
573 |
the field is less than that of the slave. Note: This method is included
|
574 |
to satisfy inheritance rules, but is not needed for blob fields. It
|
|
575 |
simply is used as a pass-through to the original unpack() method for
|
|
576 |
blob fields.
|
|
577 |
||
578 |
@param to Destination of the data
|
|
579 |
@param from Source of the data
|
|
580 |
@param param_data @c true if base types should be stored in little-
|
|
581 |
endian format, @c false if native format should
|
|
582 |
be used.
|
|
583 |
||
584 |
@return New pointer into memory based on from + length of the data
|
|
585 |
*/
|
|
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
586 |
const unsigned char *Field_blob::unpack(unsigned char *, |
1237.2.3
by Brian Aker
Tiny cast and remove dead call cleanup. |
587 |
const unsigned char *from, |
588 |
uint32_t param_data, |
|
589 |
bool low_byte_first) |
|
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
590 |
{
|
482
by Brian Aker
Remove uint. |
591 |
uint32_t const master_packlength= |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
592 |
param_data > 0 ? param_data & 0xFF : packlength; |
593 |
uint32_t const length= get_length(from, master_packlength, low_byte_first); |
|
1003.1.12
by Brian Aker
Begin of abstract out the bitmap from direct reference. |
594 |
table->setWriteSet(field_index); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
595 |
store(reinterpret_cast<const char*>(from) + master_packlength, |
596 |
length, field_charset); |
|
597 |
return(from + master_packlength + length); |
|
598 |
}
|
|
599 |
||
600 |
/** Create a packed key that will be used for storage from a MySQL row. */
|
|
601 |
||
481
by Brian Aker
Remove all of uchar. |
602 |
unsigned char * |
482
by Brian Aker
Remove uint. |
603 |
Field_blob::pack_key(unsigned char *to, const unsigned char *from, uint32_t max_length, |
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
604 |
bool ) |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
605 |
{
|
481
by Brian Aker
Remove all of uchar. |
606 |
unsigned char *save= ptr; |
607 |
ptr= (unsigned char*) from; |
|
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
608 |
uint32_t length=get_length(); // Length of from string |
482
by Brian Aker
Remove uint. |
609 |
uint32_t local_char_length= ((field_charset->mbmaxlen > 1) ? |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
610 |
max_length/field_charset->mbmaxlen : max_length); |
611 |
if (length) |
|
481
by Brian Aker
Remove all of uchar. |
612 |
get_ptr((unsigned char**) &from); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
613 |
if (length > local_char_length) |
614 |
local_char_length= my_charpos(field_charset, from, from+length, |
|
615 |
local_char_length); |
|
616 |
set_if_smaller(length, local_char_length); |
|
481
by Brian Aker
Remove all of uchar. |
617 |
*to++= (unsigned char) length; |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
618 |
if (max_length > 255) // 2 byte length |
481
by Brian Aker
Remove all of uchar. |
619 |
*to++= (unsigned char) (length >> 8); |
173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
620 |
memcpy(to, from, length); |
621 |
ptr=save; // Restore org row pointer |
|
622 |
return to+length; |
|
623 |
}
|
|
624 |
||
625 |
||
626 |
/**
|
|
627 |
maximum possible display length for blob.
|
|
628 |
||
629 |
@return
|
|
630 |
length
|
|
631 |
*/
|
|
632 |
||
633 |
uint32_t Field_blob::max_display_length() |
|
634 |
{
|
|
635 |
switch (packlength) |
|
636 |
{
|
|
637 |
case 1: |
|
638 |
return 255 * field_charset->mbmaxlen; |
|
639 |
case 2: |
|
640 |
return 65535 * field_charset->mbmaxlen; |
|
641 |
case 3: |
|
642 |
return 16777215 * field_charset->mbmaxlen; |
|
643 |
case 4: |
|
644 |
return (uint32_t) 4294967295U; |
|
645 |
default: |
|
646 |
assert(0); // we should never go here |
|
647 |
return 0; |
|
648 |
}
|
|
649 |
}
|