466
by Monty Taylor
Fixed modelines... these files are c++. |
1 |
/* - mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
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/varstring.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" |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
27 |
|
656.1.1
by Monty Taylor
OOOh doggie. Got rid of my_alloca. |
28 |
#include <string> |
29 |
||
30 |
using namespace std; |
|
31 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
32 |
namespace drizzled |
33 |
{
|
|
34 |
||
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
35 |
/****************************************************************************
|
36 |
VARCHAR type
|
|
37 |
Data in field->ptr is stored as:
|
|
38 |
1 or 2 bytes length-prefix-header (from Field_varstring::length_bytes)
|
|
39 |
data
|
|
40 |
||
41 |
NOTE:
|
|
42 |
When VARCHAR is stored in a key (for handler::index_read() etc) it's always
|
|
43 |
stored with a 2 byte prefix. (Just like blob keys).
|
|
44 |
||
45 |
Normally length_bytes is calculated as (field_length < 256 : 1 ? 2)
|
|
46 |
The exception is if there is a prefix key field that is part of a long
|
|
47 |
VARCHAR, in which case field_length for this may be 1 but the length_bytes
|
|
48 |
is 2.
|
|
49 |
****************************************************************************/
|
|
50 |
||
482
by Brian Aker
Remove uint. |
51 |
const uint32_t Field_varstring::MAX_SIZE= UINT16_MAX; |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
52 |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
53 |
Field_varstring::Field_varstring(unsigned char *ptr_arg, |
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. |
54 |
uint32_t len_arg, |
55 |
uint32_t length_bytes_arg, |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
56 |
unsigned char *null_ptr_arg, |
57 |
unsigned char null_bit_arg, |
|
58 |
const char *field_name_arg, |
|
1782.4.6
by Brian Aker
Style cleanup (no real changes). |
59 |
const CHARSET_INFO * const cs) : |
60 |
Field_str(ptr_arg, |
|
61 |
len_arg, |
|
62 |
null_ptr_arg, |
|
63 |
null_bit_arg, |
|
64 |
field_name_arg, cs), |
|
65 |
length_bytes(length_bytes_arg) |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
66 |
{
|
67 |
}
|
|
68 |
||
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. |
69 |
Field_varstring::Field_varstring(uint32_t len_arg, |
70 |
bool maybe_null_arg, |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
71 |
const char *field_name_arg, |
1782.4.6
by Brian Aker
Style cleanup (no real changes). |
72 |
const CHARSET_INFO * const cs) : |
73 |
Field_str((unsigned char*) 0, |
|
74 |
len_arg, |
|
75 |
maybe_null_arg ? (unsigned char*) "": 0, |
|
76 |
0, |
|
77 |
field_name_arg, |
|
78 |
cs), |
|
79 |
length_bytes(len_arg < 256 ? 1 :2) |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
80 |
{
|
81 |
}
|
|
82 |
||
482
by Brian Aker
Remove uint. |
83 |
int Field_varstring::store(const char *from,uint32_t length, const CHARSET_INFO * const cs) |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
84 |
{
|
482
by Brian Aker
Remove uint. |
85 |
uint32_t copy_length; |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
86 |
const char *well_formed_error_pos; |
87 |
const char *cannot_convert_error_pos; |
|
88 |
const char *from_end_pos; |
|
89 |
||
1225.1.6
by Padraig O'Sullivan
Now we are correctly setting the bitmaps in the I_S methods before adding a row to an I_S table. |
90 |
ASSERT_COLUMN_MARKED_FOR_WRITE; |
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
91 |
|
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
92 |
copy_length= well_formed_copy_nchars(field_charset, |
93 |
(char*) ptr + length_bytes, |
|
94 |
field_length, |
|
95 |
cs, from, length, |
|
96 |
field_length / field_charset->mbmaxlen, |
|
97 |
&well_formed_error_pos, |
|
98 |
&cannot_convert_error_pos, |
|
99 |
&from_end_pos); |
|
100 |
||
101 |
if (length_bytes == 1) |
|
481
by Brian Aker
Remove all of uchar. |
102 |
*ptr= (unsigned char) copy_length; |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
103 |
else
|
104 |
int2store(ptr, copy_length); |
|
105 |
||
106 |
if (check_string_copy_error(this, well_formed_error_pos, |
|
107 |
cannot_convert_error_pos, from + length, cs)) |
|
108 |
return 2; |
|
109 |
||
110 |
return report_if_important_data(from_end_pos, from + length); |
|
111 |
}
|
|
112 |
||
113 |
||
114 |
int Field_varstring::store(int64_t nr, bool unsigned_val) |
|
115 |
{
|
|
116 |
char buff[64]; |
|
482
by Brian Aker
Remove uint. |
117 |
uint32_t length; |
895
by Brian Aker
Completion (?) of uint conversion. |
118 |
length= (uint32_t) (field_charset->cset->int64_t10_to_str)(field_charset, |
1782.4.6
by Brian Aker
Style cleanup (no real changes). |
119 |
buff, |
120 |
sizeof(buff), |
|
121 |
(unsigned_val ? 10: -10), |
|
122 |
nr); |
|
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
123 |
return Field_varstring::store(buff, length, field_charset); |
124 |
}
|
|
125 |
||
126 |
||
127 |
double Field_varstring::val_real(void) |
|
128 |
{
|
|
129 |
int not_used; |
|
130 |
char *end_not_used; |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
131 |
|
132 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
133 |
||
895
by Brian Aker
Completion (?) of uint conversion. |
134 |
uint32_t length= length_bytes == 1 ? (uint32_t) *ptr : uint2korr(ptr); |
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
135 |
|
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
136 |
return my_strntod(field_charset, (char*) ptr+length_bytes, length, |
137 |
&end_not_used, ¬_used); |
|
138 |
}
|
|
139 |
||
140 |
||
141 |
int64_t Field_varstring::val_int(void) |
|
142 |
{
|
|
143 |
int not_used; |
|
144 |
char *end_not_used; |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
145 |
uint32_t length; |
146 |
||
147 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
148 |
||
149 |
length= length_bytes == 1 ? (uint32_t) *ptr : uint2korr(ptr); |
|
150 |
||
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
151 |
return my_strntoll(field_charset, (char*) ptr+length_bytes, length, 10, |
152 |
&end_not_used, ¬_used); |
|
153 |
}
|
|
154 |
||
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
155 |
String *Field_varstring::val_str(String *, |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
156 |
String *val_ptr) |
157 |
{
|
|
895
by Brian Aker
Completion (?) of uint conversion. |
158 |
uint32_t length= length_bytes == 1 ? (uint32_t) *ptr : uint2korr(ptr); |
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
159 |
|
160 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
161 |
||
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
162 |
val_ptr->set((const char*) ptr+length_bytes, length, field_charset); |
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
163 |
|
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
164 |
return val_ptr; |
165 |
}
|
|
166 |
||
167 |
||
168 |
my_decimal *Field_varstring::val_decimal(my_decimal *decimal_value) |
|
169 |
{
|
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
170 |
uint32_t length; |
171 |
||
172 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
173 |
||
174 |
length= length_bytes == 1 ? (uint32_t) *ptr : uint2korr(ptr); |
|
175 |
||
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
176 |
str2my_decimal(E_DEC_FATAL_ERROR, (char*) ptr+length_bytes, length, |
177 |
charset(), decimal_value); |
|
178 |
return decimal_value; |
|
179 |
}
|
|
180 |
||
181 |
||
481
by Brian Aker
Remove all of uchar. |
182 |
int Field_varstring::cmp_max(const unsigned char *a_ptr, const unsigned char *b_ptr, |
482
by Brian Aker
Remove uint. |
183 |
uint32_t max_len) |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
184 |
{
|
482
by Brian Aker
Remove uint. |
185 |
uint32_t a_length, b_length; |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
186 |
int diff; |
187 |
||
188 |
if (length_bytes == 1) |
|
189 |
{
|
|
895
by Brian Aker
Completion (?) of uint conversion. |
190 |
a_length= (uint32_t) *a_ptr; |
191 |
b_length= (uint32_t) *b_ptr; |
|
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
192 |
}
|
193 |
else
|
|
194 |
{
|
|
195 |
a_length= uint2korr(a_ptr); |
|
196 |
b_length= uint2korr(b_ptr); |
|
197 |
}
|
|
198 |
set_if_smaller(a_length, max_len); |
|
199 |
set_if_smaller(b_length, max_len); |
|
200 |
diff= field_charset->coll->strnncollsp(field_charset, |
|
201 |
a_ptr+ |
|
202 |
length_bytes, |
|
203 |
a_length, |
|
204 |
b_ptr+ |
|
205 |
length_bytes, |
|
206 |
b_length,0); |
|
207 |
return diff; |
|
208 |
}
|
|
209 |
||
210 |
||
211 |
/**
|
|
212 |
@note
|
|
213 |
varstring and blob keys are ALWAYS stored with a 2 byte length prefix
|
|
214 |
*/
|
|
215 |
||
482
by Brian Aker
Remove uint. |
216 |
int Field_varstring::key_cmp(const unsigned char *key_ptr, uint32_t max_key_length) |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
217 |
{
|
895
by Brian Aker
Completion (?) of uint conversion. |
218 |
uint32_t length= length_bytes == 1 ? (uint32_t) *ptr : uint2korr(ptr); |
482
by Brian Aker
Remove uint. |
219 |
uint32_t local_char_length= max_key_length / field_charset->mbmaxlen; |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
220 |
|
221 |
local_char_length= my_charpos(field_charset, ptr + length_bytes, |
|
1782.4.6
by Brian Aker
Style cleanup (no real changes). |
222 |
ptr + length_bytes + length, local_char_length); |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
223 |
set_if_smaller(length, local_char_length); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
224 |
return field_charset->coll->strnncollsp(field_charset, |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
225 |
ptr + length_bytes, |
226 |
length, |
|
227 |
key_ptr+ |
|
228 |
HA_KEY_BLOB_LENGTH, |
|
229 |
uint2korr(key_ptr), 0); |
|
230 |
}
|
|
231 |
||
232 |
||
233 |
/**
|
|
234 |
Compare to key segments (always 2 byte length prefix).
|
|
235 |
||
236 |
@note
|
|
237 |
This is used only to compare key segments created for index_read().
|
|
238 |
(keys are created and compared in key.cc)
|
|
239 |
*/
|
|
240 |
||
481
by Brian Aker
Remove all of uchar. |
241 |
int Field_varstring::key_cmp(const unsigned char *a,const unsigned char *b) |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
242 |
{
|
243 |
return field_charset->coll->strnncollsp(field_charset, |
|
244 |
a + HA_KEY_BLOB_LENGTH, |
|
245 |
uint2korr(a), |
|
246 |
b + HA_KEY_BLOB_LENGTH, |
|
247 |
uint2korr(b), |
|
248 |
0); |
|
249 |
}
|
|
250 |
||
251 |
||
482
by Brian Aker
Remove uint. |
252 |
void Field_varstring::sort_string(unsigned char *to,uint32_t length) |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
253 |
{
|
895
by Brian Aker
Completion (?) of uint conversion. |
254 |
uint32_t tot_length= length_bytes == 1 ? (uint32_t) *ptr : uint2korr(ptr); |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
255 |
|
256 |
if (field_charset == &my_charset_bin) |
|
257 |
{
|
|
258 |
/* Store length last in high-byte order to sort longer strings first */
|
|
259 |
if (length_bytes == 1) |
|
260 |
to[length-1]= tot_length; |
|
261 |
else
|
|
262 |
mi_int2store(to+length-2, tot_length); |
|
263 |
length-= length_bytes; |
|
264 |
}
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
265 |
|
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
266 |
tot_length= my_strnxfrm(field_charset, |
1782.4.6
by Brian Aker
Style cleanup (no real changes). |
267 |
to, length, ptr + length_bytes, |
268 |
tot_length); |
|
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
269 |
assert(tot_length == length); |
270 |
}
|
|
271 |
||
272 |
||
273 |
enum ha_base_keytype Field_varstring::key_type() const |
|
274 |
{
|
|
275 |
enum ha_base_keytype res; |
|
276 |
||
277 |
if (binary()) |
|
278 |
res= length_bytes == 1 ? HA_KEYTYPE_VARBINARY1 : HA_KEYTYPE_VARBINARY2; |
|
279 |
else
|
|
280 |
res= length_bytes == 1 ? HA_KEYTYPE_VARTEXT1 : HA_KEYTYPE_VARTEXT2; |
|
281 |
return res; |
|
282 |
}
|
|
283 |
||
284 |
||
285 |
void Field_varstring::sql_type(String &res) const |
|
286 |
{
|
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
287 |
const CHARSET_INFO * const cs=res.charset(); |
290
by Brian Aker
Update for ulong change over. |
288 |
uint32_t length; |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
289 |
|
290 |
length= cs->cset->snprintf(cs,(char*) res.ptr(), |
|
291 |
res.alloced_length(), "%s(%d)", |
|
292 |
(has_charset() ? "varchar" : "varbinary"), |
|
293 |
(int) field_length / charset()->mbmaxlen); |
|
294 |
res.length(length); |
|
295 |
}
|
|
296 |
||
297 |
||
205
by Brian Aker
uint32 -> uin32_t |
298 |
uint32_t Field_varstring::used_length() |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
299 |
{
|
481
by Brian Aker
Remove all of uchar. |
300 |
return length_bytes == 1 ? 1 + (uint32_t) (unsigned char) *ptr : 2 + uint2korr(ptr); |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
301 |
}
|
302 |
||
303 |
/*
|
|
304 |
Functions to create a packed row.
|
|
305 |
Here the number of length bytes are depending on the given max_length
|
|
306 |
*/
|
|
307 |
||
481
by Brian Aker
Remove all of uchar. |
308 |
unsigned char *Field_varstring::pack(unsigned char *to, const unsigned char *from, |
482
by Brian Aker
Remove uint. |
309 |
uint32_t max_length, |
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
310 |
bool ) |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
311 |
{
|
895
by Brian Aker
Completion (?) of uint conversion. |
312 |
uint32_t length= length_bytes == 1 ? (uint32_t) *from : uint2korr(from); |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
313 |
set_if_smaller(max_length, field_length); |
314 |
if (length > max_length) |
|
315 |
length=max_length; |
|
316 |
||
317 |
/* Length always stored little-endian */
|
|
318 |
*to++= length & 0xFF; |
|
319 |
if (max_length > 255) |
|
320 |
*to++= (length >> 8) & 0xFF; |
|
321 |
||
322 |
/* Store bytes of string */
|
|
323 |
if (length > 0) |
|
324 |
memcpy(to, from+length_bytes, length); |
|
325 |
return to+length; |
|
326 |
}
|
|
327 |
||
328 |
||
329 |
/**
|
|
330 |
Unpack a varstring field from row data.
|
|
331 |
||
332 |
This method is used to unpack a varstring field from a master
|
|
333 |
whose size of the field is less than that of the slave.
|
|
334 |
||
335 |
@note
|
|
336 |
The string length is always packed little-endian.
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
337 |
|
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
338 |
@param to Destination of the data
|
339 |
@param from Source of the data
|
|
340 |
@param param_data Length bytes from the master's field data
|
|
341 |
||
342 |
@return New pointer into memory based on from + length of the data
|
|
343 |
*/
|
|
481
by Brian Aker
Remove all of uchar. |
344 |
const unsigned char * |
345 |
Field_varstring::unpack(unsigned char *to, const unsigned char *from, |
|
482
by Brian Aker
Remove uint. |
346 |
uint32_t param_data, |
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
347 |
bool ) |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
348 |
{
|
482
by Brian Aker
Remove uint. |
349 |
uint32_t length; |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
350 |
uint32_t l_bytes= (param_data && (param_data < field_length)) ? |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
351 |
(param_data <= 255) ? 1 : 2 : length_bytes; |
352 |
if (l_bytes == 1) |
|
353 |
{
|
|
354 |
to[0]= *from++; |
|
355 |
length= to[0]; |
|
356 |
if (length_bytes == 2) |
|
357 |
to[1]= 0; |
|
358 |
}
|
|
359 |
else /* l_bytes == 2 */ |
|
360 |
{
|
|
361 |
length= uint2korr(from); |
|
362 |
to[0]= *from++; |
|
363 |
to[1]= *from++; |
|
364 |
}
|
|
365 |
if (length) |
|
366 |
memcpy(to+ length_bytes, from, length); |
|
367 |
return from+length; |
|
368 |
}
|
|
369 |
||
370 |
||
482
by Brian Aker
Remove uint. |
371 |
uint32_t Field_varstring::max_packed_col_length(uint32_t max_length) |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
372 |
{
|
373 |
return (max_length > 255 ? 2 : 1)+max_length; |
|
374 |
}
|
|
375 |
||
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... |
376 |
uint32_t Field_varstring::get_key_image(basic_string<unsigned char> &buff, uint32_t length) |
656.1.1
by Monty Taylor
OOOh doggie. Got rid of my_alloca. |
377 |
{
|
378 |
/* Key is always stored with 2 bytes */
|
|
379 |
const uint32_t key_len= 2; |
|
895
by Brian Aker
Completion (?) of uint conversion. |
380 |
uint32_t f_length= length_bytes == 1 ? (uint32_t) *ptr : uint2korr(ptr); |
656.1.1
by Monty Taylor
OOOh doggie. Got rid of my_alloca. |
381 |
uint32_t local_char_length= length / field_charset->mbmaxlen; |
382 |
unsigned char *pos= ptr+length_bytes; |
|
383 |
local_char_length= my_charpos(field_charset, pos, pos + f_length, |
|
384 |
local_char_length); |
|
385 |
set_if_smaller(f_length, local_char_length); |
|
386 |
unsigned char len_buff[key_len]; |
|
387 |
int2store(len_buff,f_length); |
|
388 |
buff.append(len_buff); |
|
389 |
buff.append(pos, f_length); |
|
390 |
if (f_length < length) |
|
391 |
{
|
|
392 |
/*
|
|
1237.9.2
by Padraig O'Sullivan
Moved opt_range.[cc,h] into the optimizer directory and namespace and renamed the files to |
393 |
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. |
394 |
identical keys
|
395 |
*/
|
|
396 |
buff.append(length-f_length, 0); |
|
397 |
}
|
|
398 |
return key_len+f_length; |
|
399 |
}
|
|
400 |
||
401 |
||
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... |
402 |
uint32_t Field_varstring::get_key_image(unsigned char *buff, uint32_t length) |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
403 |
{
|
895
by Brian Aker
Completion (?) of uint conversion. |
404 |
uint32_t f_length= length_bytes == 1 ? (uint32_t) *ptr : uint2korr(ptr); |
482
by Brian Aker
Remove uint. |
405 |
uint32_t local_char_length= length / field_charset->mbmaxlen; |
481
by Brian Aker
Remove all of uchar. |
406 |
unsigned char *pos= ptr+length_bytes; |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
407 |
local_char_length= my_charpos(field_charset, pos, pos + f_length, |
408 |
local_char_length); |
|
409 |
set_if_smaller(f_length, local_char_length); |
|
410 |
/* Key is always stored with 2 bytes */
|
|
411 |
int2store(buff,f_length); |
|
412 |
memcpy(buff+HA_KEY_BLOB_LENGTH, pos, f_length); |
|
413 |
if (f_length < length) |
|
414 |
{
|
|
415 |
/*
|
|
1237.9.2
by Padraig O'Sullivan
Moved opt_range.[cc,h] into the optimizer directory and namespace and renamed the files to |
416 |
Must clear this as we do a memcmp in optimizer/range.cc to detect
|
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
417 |
identical keys
|
418 |
*/
|
|
212.6.1
by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file. |
419 |
memset(buff+HA_KEY_BLOB_LENGTH+f_length, 0, (length-f_length)); |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
420 |
}
|
421 |
return HA_KEY_BLOB_LENGTH+f_length; |
|
422 |
}
|
|
423 |
||
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... |
424 |
void Field_varstring::set_key_image(const unsigned char *buff, uint32_t length) |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
425 |
{
|
426 |
length= uint2korr(buff); // Real length is here |
|
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... |
427 |
(void) Field_varstring::store((const char*) buff+HA_KEY_BLOB_LENGTH, length, field_charset); |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
428 |
}
|
429 |
||
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... |
430 |
int Field_varstring::cmp_binary(const unsigned char *a_ptr, |
431 |
const unsigned char *b_ptr, |
|
205
by Brian Aker
uint32 -> uin32_t |
432 |
uint32_t max_length) |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
433 |
{
|
205
by Brian Aker
uint32 -> uin32_t |
434 |
uint32_t a_length,b_length; |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
435 |
|
436 |
if (length_bytes == 1) |
|
437 |
{
|
|
895
by Brian Aker
Completion (?) of uint conversion. |
438 |
a_length= (uint32_t) *a_ptr; |
439 |
b_length= (uint32_t) *b_ptr; |
|
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
440 |
}
|
441 |
else
|
|
442 |
{
|
|
443 |
a_length= uint2korr(a_ptr); |
|
444 |
b_length= uint2korr(b_ptr); |
|
445 |
}
|
|
446 |
set_if_smaller(a_length, max_length); |
|
447 |
set_if_smaller(b_length, max_length); |
|
448 |
if (a_length != b_length) |
|
449 |
return 1; |
|
450 |
return memcmp(a_ptr+length_bytes, b_ptr+length_bytes, a_length); |
|
451 |
}
|
|
452 |
||
453 |
||
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
454 |
Field *Field_varstring::new_field(memory::Root *root, Table *new_table, bool keep_type) |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
455 |
{
|
456 |
Field_varstring *res= (Field_varstring*) Field::new_field(root, new_table, |
|
457 |
keep_type); |
|
458 |
if (res) |
|
459 |
res->length_bytes= length_bytes; |
|
460 |
return res; |
|
461 |
}
|
|
462 |
||
463 |
||
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
464 |
Field *Field_varstring::new_key_field(memory::Root *root, |
327.1.1
by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure). |
465 |
Table *new_table, |
481
by Brian Aker
Remove all of uchar. |
466 |
unsigned char *new_ptr, unsigned char *new_null_ptr, |
482
by Brian Aker
Remove uint. |
467 |
uint32_t new_null_bit) |
173.1.7
by Toru Maesaka
ripped out TIME and VARSTRING, moved to field/ |
468 |
{
|
469 |
Field_varstring *res; |
|
470 |
if ((res= (Field_varstring*) Field::new_key_field(root, |
|
471 |
new_table, |
|
472 |
new_ptr, |
|
473 |
new_null_ptr, |
|
474 |
new_null_bit))) |
|
475 |
{
|
|
476 |
/* Keys length prefixes are always packed with 2 bytes */
|
|
477 |
res->length_bytes= 2; |
|
478 |
}
|
|
479 |
return res; |
|
480 |
}
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
481 |
|
482 |
} /* namespace drizzled */ |