1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "drizzled/charset_info.h"
23
#include <drizzled/base.h>
24
#include <plugin/myisam/my_handler.h>
25
#include "drizzled/internal/my_sys.h"
30
using namespace drizzled;
34
int CMP_NUM(const T& a, const T&b)
36
return (a < b) ? -1 : (a == b) ? 0 : 1;
40
int ha_compare_text(const CHARSET_INFO * const charset_info, unsigned char *a, uint32_t a_length,
41
unsigned char *b, uint32_t b_length, bool part_key,
1
/* Copyright (C) 2002-2006 MySQL AB
3
This library is free software; you can redistribute it and/or
4
modify it under the terms of the GNU Library General Public
5
License as published by the Free Software Foundation; version 2
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public
14
License along with this library; if not, write to the Free
15
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18
#include <my_global.h>
21
#include <my_handler.h>
24
#include "mysys_priv.h"
25
#include "my_handler_errors.h"
27
int ha_compare_text(CHARSET_INFO *charset_info, uchar *a, uint a_length,
28
uchar *b, uint b_length, my_bool part_key,
29
my_bool skip_end_space)
45
32
return charset_info->coll->strnncollsp(charset_info, a, a_length,
46
b, b_length, (bool)!skip_end_space);
33
b, b_length, (my_bool)!skip_end_space);
47
34
return charset_info->coll->strnncoll(charset_info, a, a_length,
48
35
b, b_length, part_key);
52
static int compare_bin(unsigned char *a, uint32_t a_length, unsigned char *b, uint32_t b_length,
53
bool part_key, bool skip_end_space)
39
static int compare_bin(uchar *a, uint a_length, uchar *b, uint b_length,
40
my_bool part_key, my_bool skip_end_space)
55
uint32_t length= min(a_length,b_length);
56
unsigned char *end= a+ length;
42
uint length= min(a_length,b_length);
43
uchar *end= a+ length;
104
91
next_flag How keys should be compared
105
92
If bit SEARCH_FIND is not set the keys includes the row
106
93
position and this should also be compared
107
diff_pos OUT Number of first keypart where values differ, counting
94
diff_pos OUT Number of first keypart where values differ, counting
109
96
diff_pos[1] OUT (b + diff_pos[1]) points to first value in tuple b
110
97
that is different from corresponding value in tuple a.
113
100
Example1: if the function is called for tuples
114
101
('aaa','bbb') and ('eee','fff'), then
115
102
diff_pos[0] = 1 (as 'aaa' != 'eee')
133
120
#define FCMP(A,B) ((int) (A) - (int) (B))
135
int ha_key_cmp(register HA_KEYSEG *keyseg, register unsigned char *a,
136
register unsigned char *b, uint32_t key_length, uint32_t nextflag,
122
int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a,
123
register uchar *b, uint key_length, uint nextflag,
143
uint32_t next_key_length;
144
unsigned char *orig_b= b;
132
uint next_key_length;
147
136
for ( ; (int) key_length >0 ; key_length=next_key_length, keyseg++)
150
uint32_t piks=! (keyseg->flag & HA_NO_SORT);
139
uint piks=! (keyseg->flag & HA_NO_SORT);
152
141
diff_pos[1]= (uint)(b - orig_b);
205
uint32_t length=(uint) (end-a), a_length=length, b_length=length;
194
uint length=(uint) (end-a), a_length=length, b_length=length;
207
196
(flag= ha_compare_text(keyseg->charset, a, a_length, b, b_length,
208
(bool) ((nextflag & SEARCH_PREFIX) &&
197
(my_bool) ((nextflag & SEARCH_PREFIX) &&
209
198
next_key_length <= 0),
210
(bool)!(nextflag & SEARCH_PREFIX))))
199
(my_bool)!(nextflag & SEARCH_PREFIX))))
211
200
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
216
205
case HA_KEYTYPE_BINARY:
217
207
if (keyseg->flag & HA_SPACE_PACK)
219
209
int a_length,b_length,pack_length;
276
267
(flag=compare_bin(a,a_length,b,b_length,
277
(bool) ((nextflag & SEARCH_PREFIX) &&
268
(my_bool) ((nextflag & SEARCH_PREFIX) &&
278
269
next_key_length <= 0), 0)))
279
270
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
276
case HA_KEYTYPE_INT8:
278
int i_1= (int) *((signed char*) a);
279
int i_2= (int) *((signed char*) b);
280
if (piks && (flag = CMP_NUM(i_1,i_2)))
281
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
286
case HA_KEYTYPE_SHORT_INT:
287
s_1= mi_sint2korr(a);
288
s_2= mi_sint2korr(b);
289
if (piks && (flag = CMP_NUM(s_1,s_2)))
290
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
292
b+= 2; /* sizeof(short int); */
294
case HA_KEYTYPE_USHORT_INT:
297
us_1= mi_sint2korr(a);
298
us_2= mi_sint2korr(b);
299
if (piks && (flag = CMP_NUM(us_1,us_2)))
300
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
302
b+=2; /* sizeof(short int); */
284
305
case HA_KEYTYPE_LONG_INT:
285
306
l_1= mi_sint4korr(a);
286
307
l_2= mi_sint4korr(b);
319
361
b+= 8; /* sizeof(double); */
363
case HA_KEYTYPE_NUM: /* Numeric key */
368
if (keyseg->flag & HA_REVERSE_SORT)
370
swap_variables(uchar*, a, b);
371
swap_flag=1; /* Remember swap of a & b */
372
end= a+ (int) (end-b);
374
if (keyseg->flag & HA_SPACE_PACK)
376
alength= *a++; blength= *b++;
378
next_key_length=key_length-blength-1;
382
alength= (int) (end-a);
383
blength=keyseg->length;
384
/* remove pre space from keys */
385
for ( ; alength && *a == ' ' ; a++, alength--) ;
386
for ( ; blength && *b == ' ' ; b++, blength--) ;
395
swap_variables(uchar*, a, b);
396
swap_variables(int, alength, blength);
397
swap_flag=1-swap_flag;
398
alength--; blength--;
403
while (alength && (*a == '+' || *a == '0'))
407
while (blength && (*b == '+' || *b == '0'))
411
if (alength != blength)
412
return (alength < blength) ? -1 : 1;
415
return ((int) a[-1] - (int) b[-1]);
423
if (swap_flag) /* Restore pointers */
424
swap_variables(uchar*, a, b);
321
427
case HA_KEYTYPE_LONGLONG:
324
430
ll_a= mi_sint8korr(a);
325
431
ll_b= mi_sint8korr(b);
326
432
if (piks && (flag = CMP_NUM(ll_a,ll_b)))
569
Register handler error messages for usage with my_error()
572
This is safe to call multiple times as my_error_register()
573
will ignore calls to register already registered error numbers.
577
void my_handler_error_register(void)
580
If you got compilation error here about compile_time_assert array, check
581
that every HA_ERR_xxx constant has a corresponding error message in
582
handler_error_messages[] list (check mysys/ma_handler_errors.h and
585
compile_time_assert(HA_ERR_FIRST + array_elements(handler_error_messages) ==
587
my_error_register(handler_error_messages, HA_ERR_FIRST,
588
HA_ERR_FIRST+ array_elements(handler_error_messages)-1);
592
void my_handler_error_unregister(void)
594
my_error_unregister(HA_ERR_FIRST,
595
HA_ERR_FIRST+ array_elements(handler_error_messages)-1);