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
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 "mysys_priv.h"
20
#include <mystrings/m_ctype.h>
21
#include <drizzled/base.h>
22
#include <my_handler.h>
25
#include "my_handler_errors.h"
28
Swap the contents of two variables.
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,
30
#define swap_variables(TYPE, a, b) \
38
int ha_compare_text(const CHARSET_INFO * const charset_info, uchar *a, uint a_length,
39
uchar *b, uint b_length, bool part_key,
42
40
bool skip_end_space)
52
static int compare_bin(unsigned char *a, uint32_t a_length, unsigned char *b, uint32_t b_length,
50
static int compare_bin(uchar *a, uint a_length, uchar *b, uint b_length,
53
51
bool part_key, bool skip_end_space)
55
uint32_t length= min(a_length,b_length);
56
unsigned char *end= a+ length;
53
uint length= min(a_length,b_length);
54
uchar *end= a+ length;
104
102
next_flag How keys should be compared
105
103
If bit SEARCH_FIND is not set the keys includes the row
106
104
position and this should also be compared
107
diff_pos OUT Number of first keypart where values differ, counting
105
diff_pos OUT Number of first keypart where values differ, counting
109
107
diff_pos[1] OUT (b + diff_pos[1]) points to first value in tuple b
110
108
that is different from corresponding value in tuple a.
113
111
Example1: if the function is called for tuples
114
112
('aaa','bbb') and ('eee','fff'), then
115
113
diff_pos[0] = 1 (as 'aaa' != 'eee')
133
131
#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,
133
int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a,
134
register uchar *b, uint key_length, uint nextflag,
141
140
uint32_t u_1,u_2;
143
uint32_t next_key_length;
144
unsigned char *orig_b= b;
143
uint next_key_length;
147
147
for ( ; (int) key_length >0 ; key_length=next_key_length, keyseg++)
150
uint32_t piks=! (keyseg->flag & HA_NO_SORT);
150
uint piks=! (keyseg->flag & HA_NO_SORT);
152
152
diff_pos[1]= (uint)(b - orig_b);
205
uint32_t length=(uint) (end-a), a_length=length, b_length=length;
205
uint length=(uint) (end-a), a_length=length, b_length=length;
207
207
(flag= ha_compare_text(keyseg->charset, a, a_length, b, b_length,
208
208
(bool) ((nextflag & SEARCH_PREFIX) &&
287
case HA_KEYTYPE_INT8:
289
int i_1= (int) *((signed char*) a);
290
int i_2= (int) *((signed char*) b);
291
if (piks && (flag = CMP_NUM(i_1,i_2)))
292
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
297
case HA_KEYTYPE_SHORT_INT:
298
s_1= mi_sint2korr(a);
299
s_2= mi_sint2korr(b);
300
if (piks && (flag = CMP_NUM(s_1,s_2)))
301
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
303
b+= 2; /* sizeof(short int); */
305
case HA_KEYTYPE_USHORT_INT:
308
us_1= mi_sint2korr(a);
309
us_2= mi_sint2korr(b);
310
if (piks && (flag = CMP_NUM(us_1,us_2)))
311
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
313
b+=2; /* sizeof(short int); */
284
316
case HA_KEYTYPE_LONG_INT:
285
317
l_1= mi_sint4korr(a);
286
318
l_2= mi_sint4korr(b);
319
372
b+= 8; /* sizeof(double); */
374
case HA_KEYTYPE_NUM: /* Numeric key */
379
if (keyseg->flag & HA_REVERSE_SORT)
381
swap_variables(uchar*, a, b);
382
swap_flag=1; /* Remember swap of a & b */
383
end= a+ (int) (end-b);
385
if (keyseg->flag & HA_SPACE_PACK)
387
alength= *a++; blength= *b++;
389
next_key_length=key_length-blength-1;
393
alength= (int) (end-a);
394
blength=keyseg->length;
395
/* remove pre space from keys */
396
for ( ; alength && *a == ' ' ; a++, alength--) ;
397
for ( ; blength && *b == ' ' ; b++, blength--) ;
406
swap_variables(uchar*, a, b);
407
swap_variables(int, alength, blength);
408
swap_flag=1-swap_flag;
409
alength--; blength--;
414
while (alength && (*a == '+' || *a == '0'))
418
while (blength && (*b == '+' || *b == '0'))
422
if (alength != blength)
423
return (alength < blength) ? -1 : 1;
426
return ((int) a[-1] - (int) b[-1]);
434
if (swap_flag) /* Restore pointers */
435
swap_variables(uchar*, a, b);
321
438
case HA_KEYTYPE_LONGLONG:
323
440
int64_t ll_a,ll_b;
548
if (keyseg->flag & HA_SPACE_PACK)
555
case HA_KEYTYPE_INT8:
556
case HA_KEYTYPE_SHORT_INT:
557
case HA_KEYTYPE_USHORT_INT:
429
558
case HA_KEYTYPE_LONG_INT:
430
559
case HA_KEYTYPE_ULONG_INT:
560
case HA_KEYTYPE_INT24:
431
561
case HA_KEYTYPE_UINT24:
432
562
case HA_KEYTYPE_LONGLONG:
433
563
case HA_KEYTYPE_ULONGLONG:
564
case HA_KEYTYPE_FLOAT:
434
565
case HA_KEYTYPE_DOUBLE:
568
case HA_KEYTYPE_END: /* purecov: inspected */
438
569
/* keep compiler happy */
580
Register handler error messages for usage with my_error()
583
This is safe to call multiple times as my_error_register()
584
will ignore calls to register already registered error numbers.
588
void my_handler_error_register(void)
591
If you got compilation error here about compile_time_assert array, check
592
that every HA_ERR_xxx constant has a corresponding error message in
593
handler_error_messages[] list (check mysys/ma_handler_errors.h and
596
compile_time_assert(HA_ERR_FIRST + array_elements(handler_error_messages) ==
598
my_error_register(handler_error_messages, HA_ERR_FIRST,
599
HA_ERR_FIRST+ array_elements(handler_error_messages)-1);
603
void my_handler_error_unregister(void)
605
my_error_unregister(HA_ERR_FIRST,
606
HA_ERR_FIRST+ array_elements(handler_error_messages)-1);