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