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, Inc.
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;
30
#define swap_variables(TYPE, a, b) \
38
#define CMP_NUM(a,b) (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
40
41
int ha_compare_text(const CHARSET_INFO * const charset_info, unsigned char *a, uint32_t a_length,
52
53
static int compare_bin(unsigned char *a, uint32_t a_length, unsigned char *b, uint32_t b_length,
53
54
bool part_key, bool skip_end_space)
55
uint32_t length= min(a_length,b_length);
56
uint32_t length= cmin(a_length,b_length);
56
57
unsigned char *end= a+ length;
104
105
next_flag How keys should be compared
105
106
If bit SEARCH_FIND is not set the keys includes the row
106
107
position and this should also be compared
107
diff_pos OUT Number of first keypart where values differ, counting
108
diff_pos OUT Number of first keypart where values differ, counting
109
110
diff_pos[1] OUT (b + diff_pos[1]) points to first value in tuple b
110
111
that is different from corresponding value in tuple a.
113
114
Example1: if the function is called for tuples
114
115
('aaa','bbb') and ('eee','fff'), then
115
116
diff_pos[0] = 1 (as 'aaa' != 'eee')
290
case HA_KEYTYPE_INT8:
292
int i_1= (int) *((signed char*) a);
293
int i_2= (int) *((signed char*) b);
294
if (piks && (flag = CMP_NUM(i_1,i_2)))
295
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
300
case HA_KEYTYPE_SHORT_INT:
301
s_1= mi_sint2korr(a);
302
s_2= mi_sint2korr(b);
303
if (piks && (flag = CMP_NUM(s_1,s_2)))
304
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
306
b+= 2; /* sizeof(short int); */
308
case HA_KEYTYPE_USHORT_INT:
311
us_1= mi_sint2korr(a);
312
us_2= mi_sint2korr(b);
313
if (piks && (flag = CMP_NUM(us_1,us_2)))
314
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
316
b+=2; /* sizeof(short int); */
284
319
case HA_KEYTYPE_LONG_INT:
285
320
l_1= mi_sint4korr(a);
286
321
l_2= mi_sint4korr(b);
298
333
b+= 4; /* sizeof(long int); */
335
case HA_KEYTYPE_INT24:
338
if (piks && (flag = CMP_NUM(l_1,l_2)))
339
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
343
case HA_KEYTYPE_UINT24:
346
if (piks && (flag = CMP_NUM(l_1,l_2)))
347
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
351
case HA_KEYTYPE_FLOAT:
355
The following may give a compiler warning about floating point
356
comparison not being safe, but this is ok in this context as
357
we are bascily doing sorting
359
if (piks && (flag = CMP_NUM(f_1,f_2)))
360
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
362
b+= 4; /* sizeof(float); */
300
364
case HA_KEYTYPE_DOUBLE:
301
365
mi_float8get(d_1,a);
302
366
mi_float8get(d_2,b);
311
375
b+= 8; /* sizeof(double); */
377
case HA_KEYTYPE_NUM: /* Numeric key */
382
if (keyseg->flag & HA_REVERSE_SORT)
384
swap_variables(unsigned char*, a, b);
385
swap_flag=1; /* Remember swap of a & b */
386
end= a+ (int) (end-b);
388
if (keyseg->flag & HA_SPACE_PACK)
390
alength= *a++; blength= *b++;
392
next_key_length=key_length-blength-1;
396
alength= (int) (end-a);
397
blength=keyseg->length;
398
/* remove pre space from keys */
399
for ( ; alength && *a == ' ' ; a++, alength--) ;
400
for ( ; blength && *b == ' ' ; b++, blength--) ;
409
swap_variables(unsigned char*, a, b);
410
swap_variables(int, alength, blength);
411
swap_flag=1-swap_flag;
412
alength--; blength--;
417
while (alength && (*a == '+' || *a == '0'))
421
while (blength && (*b == '+' || *b == '0'))
425
if (alength != blength)
426
return (alength < blength) ? -1 : 1;
429
return ((int) a[-1] - (int) b[-1]);
437
if (swap_flag) /* Restore pointers */
438
swap_variables(unsigned char*, a, b);
313
441
case HA_KEYTYPE_LONGLONG:
315
443
int64_t ll_a,ll_b;
551
if (keyseg->flag & HA_SPACE_PACK)
558
case HA_KEYTYPE_INT8:
559
case HA_KEYTYPE_SHORT_INT:
560
case HA_KEYTYPE_USHORT_INT:
421
561
case HA_KEYTYPE_LONG_INT:
422
562
case HA_KEYTYPE_ULONG_INT:
563
case HA_KEYTYPE_INT24:
564
case HA_KEYTYPE_UINT24:
423
565
case HA_KEYTYPE_LONGLONG:
424
566
case HA_KEYTYPE_ULONGLONG:
567
case HA_KEYTYPE_FLOAT:
425
568
case HA_KEYTYPE_DOUBLE:
571
case HA_KEYTYPE_END: /* purecov: inspected */
429
572
/* keep compiler happy */
583
Register handler error messages for usage with my_error()
586
This is safe to call multiple times as my_error_register()
587
will ignore calls to register already registered error numbers.
591
void my_handler_error_register(void)
594
If you got compilation error here about compile_time_assert array, check
595
that every HA_ERR_xxx constant has a corresponding error message in
596
handler_error_messages[] list (check mysys/ma_handler_errors.h and
599
TODO: Remove fix the handler_error_messages so that this hack isn't
603
char compile_time_assert[(HA_ERR_FIRST +
604
array_elements(handler_error_messages) ==
605
HA_ERR_LAST + 1) ? 1 : -1]
606
__attribute__ ((__unused__));
608
my_error_register(handler_error_messages, HA_ERR_FIRST,
609
HA_ERR_FIRST+ array_elements(handler_error_messages)-1);
613
void my_handler_error_unregister(void)
615
my_error_unregister(HA_ERR_FIRST,
616
HA_ERR_FIRST+ array_elements(handler_error_messages)-1);