~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2006 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
/* Functions to handle keys */
17
18
#include "myisamdef.h"
212.5.18 by Monty Taylor
Moved m_ctype, m_string and my_bitmap. Removed t_ctype.
19
#include <mystrings/m_ctype.h>
1 by brian
clean slate
20
#ifdef HAVE_IEEEFP_H
21
#include <ieeefp.h>
22
#endif
23
24
#define CHECK_KEYS                              /* Enable safety checks */
25
26
#define FIX_LENGTH(cs, pos, length, char_length)                            \
27
            do {                                                            \
28
              if (length > char_length)                                     \
29
                char_length= my_charpos(cs, pos, pos+length, char_length);  \
30
              set_if_smaller(char_length,length);                           \
31
            } while(0)
32
482 by Brian Aker
Remove uint.
33
static int _mi_put_key_in_record(MI_INFO *info,uint32_t keynr,unsigned char *record);
1 by brian
clean slate
34
35
/*
36
  Make a intern key from a record
37
38
  SYNOPSIS
39
    _mi_make_key()
40
    info		MyiSAM handler
41
    keynr		key number
42
    key			Store created key here
43
    record		Record
44
    filepos		Position to record in the data file
45
46
  RETURN
47
    Length of key
48
*/
49
482 by Brian Aker
Remove uint.
50
uint32_t _mi_make_key(register MI_INFO *info, uint32_t keynr, unsigned char *key,
481 by Brian Aker
Remove all of uchar.
51
		  const unsigned char *record, my_off_t filepos)
1 by brian
clean slate
52
{
481 by Brian Aker
Remove all of uchar.
53
  unsigned char *pos;
54
  unsigned char *start;
1 by brian
clean slate
55
  register HA_KEYSEG *keyseg;
56
57
  start=key;
58
  for (keyseg=info->s->keyinfo[keynr].seg ; keyseg->type ;keyseg++)
59
  {
60
    enum ha_base_keytype type=(enum ha_base_keytype) keyseg->type;
482 by Brian Aker
Remove uint.
61
    uint32_t length=keyseg->length;
62
    uint32_t char_length;
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
63
    const CHARSET_INFO * const cs=keyseg->charset;
1 by brian
clean slate
64
65
    if (keyseg->null_bit)
66
    {
67
      if (record[keyseg->null_pos] & keyseg->null_bit)
68
      {
69
	*key++= 0;				/* NULL in key */
70
	continue;
71
      }
72
      *key++=1;					/* Not NULL */
73
    }
74
249 by Brian Aker
Random key cleanup (it is a friday...)
75
    char_length= ((cs && cs->mbmaxlen > 1) ? length/cs->mbmaxlen :
1 by brian
clean slate
76
                  length);
77
481 by Brian Aker
Remove all of uchar.
78
    pos= (unsigned char*) record+keyseg->start;
1 by brian
clean slate
79
    if (type == HA_KEYTYPE_BIT)
80
    {
81
      if (keyseg->bit_length)
82
      {
481 by Brian Aker
Remove all of uchar.
83
        unsigned char bits= get_rec_bits((unsigned char*) record + keyseg->bit_pos,
1 by brian
clean slate
84
                                 keyseg->bit_start, keyseg->bit_length);
85
        *key++= bits;
86
        length--;
87
      }
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
88
      memcpy(key, pos, length);
1 by brian
clean slate
89
      key+= length;
90
      continue;
91
    }
92
    if (keyseg->flag & HA_SPACE_PACK)
93
    {
94
      if (type != HA_KEYTYPE_NUM)
95
      {
96
        length= cs->cset->lengthsp(cs, (char*) pos, length);
97
      }
98
      else
99
      {
481 by Brian Aker
Remove all of uchar.
100
        unsigned char *end= pos + length;
1 by brian
clean slate
101
	while (pos < end && pos[0] == ' ')
102
	  pos++;
103
	length=(uint) (end-pos);
104
      }
105
      FIX_LENGTH(cs, pos, length, char_length);
106
      store_key_length_inc(key,char_length);
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
107
      memcpy(key, pos, char_length);
1 by brian
clean slate
108
      key+=char_length;
109
      continue;
110
    }
111
    if (keyseg->flag & HA_VAR_LENGTH_PART)
112
    {
482 by Brian Aker
Remove uint.
113
      uint32_t pack_length= (keyseg->bit_start == 1 ? 1 : 2);
114
      uint32_t tmp_length= (pack_length == 1 ? (uint) *(unsigned char*) pos :
1 by brian
clean slate
115
                        uint2korr(pos));
116
      pos+= pack_length;			/* Skip VARCHAR length */
117
      set_if_smaller(length,tmp_length);
118
      FIX_LENGTH(cs, pos, length, char_length);
119
      store_key_length_inc(key,char_length);
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
120
      memcpy(key, pos, char_length);
1 by brian
clean slate
121
      key+= char_length;
122
      continue;
123
    }
124
    else if (keyseg->flag & HA_BLOB_PART)
125
    {
482 by Brian Aker
Remove uint.
126
      uint32_t tmp_length=_mi_calc_blob_length(keyseg->bit_start,pos);
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
127
      memcpy(&pos, pos+keyseg->bit_start, sizeof(char*));
1 by brian
clean slate
128
      set_if_smaller(length,tmp_length);
129
      FIX_LENGTH(cs, pos, length, char_length);
130
      store_key_length_inc(key,char_length);
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
131
      memcpy(key, pos, char_length);
1 by brian
clean slate
132
      key+= char_length;
133
      continue;
134
    }
135
    else if (keyseg->flag & HA_SWAP_KEY)
136
    {						/* Numerical column */
137
#ifdef HAVE_ISNAN
138
      if (type == HA_KEYTYPE_FLOAT)
139
      {
140
	float nr;
141
	float4get(nr,pos);
142
	if (isnan(nr))
143
	{
144
	  /* Replace NAN with zero */
212.6.1 by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file.
145
	  memset(key, 0, length);
1 by brian
clean slate
146
	  key+=length;
147
	  continue;
148
	}
149
      }
150
      else if (type == HA_KEYTYPE_DOUBLE)
151
      {
152
	double nr;
153
	float8get(nr,pos);
154
	if (isnan(nr))
155
	{
212.6.1 by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file.
156
	  memset(key, 0, length);
1 by brian
clean slate
157
	  key+=length;
158
	  continue;
159
	}
160
      }
161
#endif
162
      pos+=length;
163
      while (length--)
164
      {
165
	*key++ = *--pos;
166
      }
167
      continue;
168
    }
169
    FIX_LENGTH(cs, pos, length, char_length);
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
170
    memcpy(key, pos, char_length);
1 by brian
clean slate
171
    if (length > char_length)
172
      cs->cset->fill(cs, (char*) key+char_length, length-char_length, ' ');
173
    key+= length;
174
  }
175
  _mi_dpointer(info,key,filepos);
51.1.101 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
176
  return((uint) (key-start));		/* Return keylength */
1 by brian
clean slate
177
} /* _mi_make_key */
178
179
180
/*
181
  Pack a key to intern format from given format (c_rkey)
182
183
  SYNOPSIS
184
    _mi_pack_key()
185
    info		MyISAM handler
482 by Brian Aker
Remove uint.
186
    uint32_t keynr		key number
1 by brian
clean slate
187
    key			Store packed key here
188
    old			Not packed key
189
    keypart_map         bitmap of used keyparts
190
    last_used_keyseg	out parameter.  May be NULL
191
192
   RETURN
193
     length of packed key
194
195
     last_use_keyseg    Store pointer to the keyseg after the last used one
196
*/
197
482 by Brian Aker
Remove uint.
198
uint32_t _mi_pack_key(register MI_INFO *info, uint32_t keynr, unsigned char *key, unsigned char *old,
1 by brian
clean slate
199
                  key_part_map keypart_map, HA_KEYSEG **last_used_keyseg)
200
{
481 by Brian Aker
Remove all of uchar.
201
  unsigned char *start_key=key;
1 by brian
clean slate
202
  HA_KEYSEG *keyseg;
203
204
  /* only key prefixes are supported */
51.1.101 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
205
  assert(((keypart_map+1) & keypart_map) == 0);
1 by brian
clean slate
206
207
  for (keyseg= info->s->keyinfo[keynr].seg ; keyseg->type && keypart_map;
208
       old+= keyseg->length, keyseg++)
209
  {
210
    enum ha_base_keytype type= (enum ha_base_keytype) keyseg->type;
482 by Brian Aker
Remove uint.
211
    uint32_t length= keyseg->length;
212
    uint32_t char_length;
481 by Brian Aker
Remove all of uchar.
213
    unsigned char *pos;
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
214
    const CHARSET_INFO * const cs=keyseg->charset;
1 by brian
clean slate
215
    keypart_map>>= 1;
216
    if (keyseg->null_bit)
217
    {
218
      if (!(*key++= (char) 1-*old++))			/* Copy null marker */
219
      {
220
        if (keyseg->flag & (HA_VAR_LENGTH_PART | HA_BLOB_PART))
221
          old+= 2;
222
	continue;					/* Found NULL */
223
      }
224
    }
249 by Brian Aker
Random key cleanup (it is a friday...)
225
    char_length= (cs && cs->mbmaxlen > 1) ? length/cs->mbmaxlen : length;
1 by brian
clean slate
226
    pos=old;
227
    if (keyseg->flag & HA_SPACE_PACK)
228
    {
481 by Brian Aker
Remove all of uchar.
229
      unsigned char *end=pos+length;
1 by brian
clean slate
230
      if (type == HA_KEYTYPE_NUM)
231
      {
232
	while (pos < end && pos[0] == ' ')
233
	  pos++;
234
      }
235
      else if (type != HA_KEYTYPE_BINARY)
236
      {
237
	while (end > pos && end[-1] == ' ')
238
	  end--;
239
      }
240
      length=(uint) (end-pos);
241
      FIX_LENGTH(cs, pos, length, char_length);
242
      store_key_length_inc(key,char_length);
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
243
      memcpy(key, pos, char_length);
1 by brian
clean slate
244
      key+= char_length;
245
      continue;
246
    }
247
    else if (keyseg->flag & (HA_VAR_LENGTH_PART | HA_BLOB_PART))
248
    {
249
      /* Length of key-part used with mi_rkey() always 2 */
482 by Brian Aker
Remove uint.
250
      uint32_t tmp_length=uint2korr(pos);
1 by brian
clean slate
251
      pos+=2;
252
      set_if_smaller(length,tmp_length);	/* Safety */
253
      FIX_LENGTH(cs, pos, length, char_length);
254
      store_key_length_inc(key,char_length);
255
      old+=2;					/* Skip length */
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
256
      memcpy(key, pos, char_length);
1 by brian
clean slate
257
      key+= char_length;
258
      continue;
259
    }
260
    else if (keyseg->flag & HA_SWAP_KEY)
261
    {						/* Numerical column */
262
      pos+=length;
263
      while (length--)
264
	*key++ = *--pos;
265
      continue;
266
    }
267
    FIX_LENGTH(cs, pos, length, char_length);
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
268
    memcpy(key, pos, char_length);
1 by brian
clean slate
269
    if (length > char_length)
270
      cs->cset->fill(cs, (char*) key+char_length, length-char_length, ' ');
271
    key+= length;
272
  }
273
  if (last_used_keyseg)
274
    *last_used_keyseg= keyseg;
275
51.1.101 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
276
  return((uint) (key-start_key));
1 by brian
clean slate
277
} /* _mi_pack_key */
278
279
280
281
/*
282
  Store found key in record
283
284
  SYNOPSIS
285
    _mi_put_key_in_record()
286
    info		MyISAM handler
287
    keynr		Key number that was used
288
    record 		Store key here
289
290
    Last read key is in info->lastkey
291
292
 NOTES
293
   Used when only-keyread is wanted
294
295
 RETURN
296
   0   ok
297
   1   error
298
*/
299
482 by Brian Aker
Remove uint.
300
static int _mi_put_key_in_record(register MI_INFO *info, uint32_t keynr,
481 by Brian Aker
Remove all of uchar.
301
				 unsigned char *record)
1 by brian
clean slate
302
{
481 by Brian Aker
Remove all of uchar.
303
  register unsigned char *key;
304
  unsigned char *pos,*key_end;
1 by brian
clean slate
305
  register HA_KEYSEG *keyseg;
481 by Brian Aker
Remove all of uchar.
306
  unsigned char *blob_ptr;
1 by brian
clean slate
307
481 by Brian Aker
Remove all of uchar.
308
  blob_ptr= (unsigned char*) info->lastkey2;             /* Place to put blob parts */
309
  key=(unsigned char*) info->lastkey;                    /* KEy that was read */
1 by brian
clean slate
310
  key_end=key+info->lastkey_length;
311
  for (keyseg=info->s->keyinfo[keynr].seg ; keyseg->type ;keyseg++)
312
  {
313
    if (keyseg->null_bit)
314
    {
315
      if (!*key++)
316
      {
317
	record[keyseg->null_pos]|= keyseg->null_bit;
318
	continue;
319
      }
320
      record[keyseg->null_pos]&= ~keyseg->null_bit;
321
    }
322
    if (keyseg->type == HA_KEYTYPE_BIT)
323
    {
482 by Brian Aker
Remove uint.
324
      uint32_t length= keyseg->length;
1 by brian
clean slate
325
326
      if (keyseg->bit_length)
327
      {
481 by Brian Aker
Remove all of uchar.
328
        unsigned char bits= *key++;
1 by brian
clean slate
329
        set_rec_bits(bits, record + keyseg->bit_pos, keyseg->bit_start,
330
                     keyseg->bit_length);
331
        length--;
332
      }
333
      else
334
      {
335
        clr_rec_bits(record + keyseg->bit_pos, keyseg->bit_start,
336
                     keyseg->bit_length);
337
      }
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
338
      memcpy(record + keyseg->start, key, length);
1 by brian
clean slate
339
      key+= length;
340
      continue;
341
    }
342
    if (keyseg->flag & HA_SPACE_PACK)
343
    {
482 by Brian Aker
Remove uint.
344
      uint32_t length;
1 by brian
clean slate
345
      get_key_length(length,key);
346
#ifdef CHECK_KEYS
347
      if (length > keyseg->length || key+length > key_end)
348
	goto err;
349
#endif
350
      pos= record+keyseg->start;
351
      if (keyseg->type != (int) HA_KEYTYPE_NUM)
352
      {
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
353
        memcpy(pos, key, length);
1 by brian
clean slate
354
        keyseg->charset->cset->fill(keyseg->charset,
355
                                    (char*) pos + length,
356
                                    keyseg->length - length,
357
                                    ' ');
358
      }
359
      else
360
      {
212.6.3 by Mats Kindahl
Removing deprecated functions from code and replacing them with C99 equivalents:
361
	memset(pos, ' ', keyseg->length-length);
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
362
	memcpy(pos+keyseg->length-length, key, length);
1 by brian
clean slate
363
      }
364
      key+=length;
365
      continue;
366
    }
367
368
    if (keyseg->flag & HA_VAR_LENGTH_PART)
369
    {
482 by Brian Aker
Remove uint.
370
      uint32_t length;
1 by brian
clean slate
371
      get_key_length(length,key);
372
#ifdef CHECK_KEYS
373
      if (length > keyseg->length || key+length > key_end)
374
	goto err;
375
#endif
376
      /* Store key length */
377
      if (keyseg->bit_start == 1)
481 by Brian Aker
Remove all of uchar.
378
        *(unsigned char*) (record+keyseg->start)= (unsigned char) length;
1 by brian
clean slate
379
      else
380
        int2store(record+keyseg->start, length);
381
      /* And key data */
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
382
      memcpy(record+keyseg->start + keyseg->bit_start, key, length);
1 by brian
clean slate
383
      key+= length;
384
    }
385
    else if (keyseg->flag & HA_BLOB_PART)
386
    {
482 by Brian Aker
Remove uint.
387
      uint32_t length;
1 by brian
clean slate
388
      get_key_length(length,key);
389
#ifdef CHECK_KEYS
390
      if (length > keyseg->length || key+length > key_end)
391
	goto err;
392
#endif
393
      memcpy(record+keyseg->start+keyseg->bit_start,
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
394
	     &blob_ptr,sizeof(char*));
1 by brian
clean slate
395
      memcpy(blob_ptr,key,length);
396
      blob_ptr+=length;
397
398
      /* The above changed info->lastkey2. Inform mi_rnext_same(). */
399
      info->update&= ~HA_STATE_RNEXT_SAME;
400
401
      _my_store_blob_length(record+keyseg->start,
402
			    (uint) keyseg->bit_start,length);
403
      key+=length;
404
    }
405
    else if (keyseg->flag & HA_SWAP_KEY)
406
    {
481 by Brian Aker
Remove all of uchar.
407
      unsigned char *to=  record+keyseg->start+keyseg->length;
408
      unsigned char *end= key+keyseg->length;
1 by brian
clean slate
409
#ifdef CHECK_KEYS
410
      if (end > key_end)
411
	goto err;
412
#endif
413
      do
414
      {
415
	 *--to= *key++;
416
      } while (key != end);
417
      continue;
418
    }
419
    else
420
    {
421
#ifdef CHECK_KEYS
422
      if (key+keyseg->length > key_end)
423
	goto err;
424
#endif
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
425
      memcpy(record+keyseg->start, key, keyseg->length);
1 by brian
clean slate
426
      key+= keyseg->length;
427
    }
428
  }
51.1.101 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
429
  return(0);
1 by brian
clean slate
430
431
err:
51.1.101 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
432
  return(1);				/* Crashed row */
1 by brian
clean slate
433
} /* _mi_put_key_in_record */
434
435
436
	/* Here when key reads are used */
437
481 by Brian Aker
Remove all of uchar.
438
int _mi_read_key_record(MI_INFO *info, my_off_t filepos, unsigned char *buf)
1 by brian
clean slate
439
{
440
  fast_mi_writeinfo(info);
441
  if (filepos != HA_OFFSET_ERROR)
442
  {
443
    if (info->lastinx >= 0)
444
    {				/* Read only key */
445
      if (_mi_put_key_in_record(info,(uint) info->lastinx,buf))
446
      {
447
        mi_print_error(info->s, HA_ERR_CRASHED);
448
	my_errno=HA_ERR_CRASHED;
449
	return -1;
450
      }
451
      info->update|= HA_STATE_AKTIV; /* We should find a record */
452
      return 0;
453
    }
454
    my_errno=HA_ERR_WRONG_INDEX;
455
  }
456
  return(-1);				/* Wrong data to read */
457
}
458
459
460
/*
461
  Save current key tuple to record and call index condition check function
462
463
  SYNOPSIS
464
    mi_check_index_cond()
465
      info    MyISAM handler
466
      keynr   Index we're running a scan on
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
467
      record  Record buffer to use (it is assumed that index check function
1 by brian
clean slate
468
              will look for column values there)
469
470
  RETURN
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
471
    -1  Error
1 by brian
clean slate
472
    0   Index condition is not satisfied, continue scanning
473
    1   Index condition is satisfied
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
474
    2   Index condition is not satisfied, end the scan.
1 by brian
clean slate
475
*/
476
482 by Brian Aker
Remove uint.
477
int mi_check_index_cond(register MI_INFO *info, uint32_t keynr, unsigned char *record)
1 by brian
clean slate
478
{
479
  if (_mi_put_key_in_record(info, keynr, record))
480
  {
481
    mi_print_error(info->s, HA_ERR_CRASHED);
482
    my_errno=HA_ERR_CRASHED;
483
    return -1;
484
  }
485
  return info->index_cond_func(info->index_cond_func_arg);
486
}
487
488
489
/*
490
  Retrieve auto_increment info
491
492
  SYNOPSIS
493
    retrieve_auto_increment()
494
    info			MyISAM handler
495
    record			Row to update
496
497
  IMPLEMENTATION
498
    For signed columns we don't retrieve the auto increment value if it's
499
    less than zero.
500
*/
501
481 by Brian Aker
Remove all of uchar.
502
uint64_t retrieve_auto_increment(MI_INFO *info,const unsigned char *record)
1 by brian
clean slate
503
{
151 by Brian Aker
Ulonglong to uint64_t
504
  uint64_t value= 0;			/* Store unsigned values here */
152 by Brian Aker
longlong replacement
505
  int64_t s_value= 0;			/* Store signed values here */
1 by brian
clean slate
506
  HA_KEYSEG *keyseg= info->s->keyinfo[info->s->base.auto_key-1].seg;
481 by Brian Aker
Remove all of uchar.
507
  const unsigned char *key= (unsigned char*) record + keyseg->start;
1 by brian
clean slate
508
509
  switch (keyseg->type) {
510
  case HA_KEYTYPE_INT8:
152 by Brian Aker
longlong replacement
511
    s_value= (int64_t) *(char*)key;
1 by brian
clean slate
512
    break;
513
  case HA_KEYTYPE_BINARY:
481 by Brian Aker
Remove all of uchar.
514
    value=(uint64_t)  *(unsigned char*) key;
1 by brian
clean slate
515
    break;
516
  case HA_KEYTYPE_SHORT_INT:
152 by Brian Aker
longlong replacement
517
    s_value= (int64_t) sint2korr(key);
1 by brian
clean slate
518
    break;
519
  case HA_KEYTYPE_USHORT_INT:
151 by Brian Aker
Ulonglong to uint64_t
520
    value=(uint64_t) uint2korr(key);
1 by brian
clean slate
521
    break;
522
  case HA_KEYTYPE_LONG_INT:
152 by Brian Aker
longlong replacement
523
    s_value= (int64_t) sint4korr(key);
1 by brian
clean slate
524
    break;
525
  case HA_KEYTYPE_ULONG_INT:
151 by Brian Aker
Ulonglong to uint64_t
526
    value=(uint64_t) uint4korr(key);
1 by brian
clean slate
527
    break;
528
  case HA_KEYTYPE_INT24:
152 by Brian Aker
longlong replacement
529
    s_value= (int64_t) sint3korr(key);
1 by brian
clean slate
530
    break;
531
  case HA_KEYTYPE_UINT24:
151 by Brian Aker
Ulonglong to uint64_t
532
    value=(uint64_t) uint3korr(key);
1 by brian
clean slate
533
    break;
534
  case HA_KEYTYPE_FLOAT:                        /* This shouldn't be used */
535
  {
536
    float f_1;
537
    float4get(f_1,key);
538
    /* Ignore negative values */
151 by Brian Aker
Ulonglong to uint64_t
539
    value = (f_1 < (float) 0.0) ? 0 : (uint64_t) f_1;
1 by brian
clean slate
540
    break;
541
  }
542
  case HA_KEYTYPE_DOUBLE:                       /* This shouldn't be used */
543
  {
544
    double f_1;
545
    float8get(f_1,key);
546
    /* Ignore negative values */
151 by Brian Aker
Ulonglong to uint64_t
547
    value = (f_1 < 0.0) ? 0 : (uint64_t) f_1;
1 by brian
clean slate
548
    break;
549
  }
550
  case HA_KEYTYPE_LONGLONG:
551
    s_value= sint8korr(key);
552
    break;
553
  case HA_KEYTYPE_ULONGLONG:
554
    value= uint8korr(key);
555
    break;
556
  default:
51.1.101 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
557
    assert(0);
1 by brian
clean slate
558
    value=0;                                    /* Error */
559
    break;
560
  }
561
562
  /*
563
    The following code works becasue if s_value < 0 then value is 0
564
    and if s_value == 0 then value will contain either s_value or the
565
    correct value.
566
  */
151 by Brian Aker
Ulonglong to uint64_t
567
  return (s_value > 0) ? (uint64_t) s_value : value;
1 by brian
clean slate
568
}