~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_rkey.c

  • Committer: Monty Taylor
  • Date: 2008-11-16 06:29:53 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116062953-ivdltjmfe009b5fr
Moved stuff into item/

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include "heap_priv.h"
17
 
 
18
 
#include <string.h>
19
 
 
20
 
using namespace drizzled;
21
 
 
22
 
int heap_rkey(HP_INFO *info, unsigned char *record, int inx, const unsigned char *key,
23
 
              key_part_map , enum ha_rkey_function )
 
16
#include "heapdef.h"
 
17
 
 
18
int heap_rkey(HP_INFO *info, unsigned char *record, int inx, const unsigned char *key, 
 
19
              key_part_map keypart_map, enum ha_rkey_function find_flag)
24
20
{
25
21
  unsigned char *pos;
26
 
  HP_SHARE *share= info->getShare();
 
22
  HP_SHARE *share= info->s;
27
23
  HP_KEYDEF *keyinfo= share->keydef + inx;
28
24
 
29
25
  if ((uint) inx >= share->keys)
30
26
  {
31
 
    return(errno= HA_ERR_WRONG_INDEX);
 
27
    return(my_errno= HA_ERR_WRONG_INDEX);
32
28
  }
33
29
  info->lastinx= inx;
34
30
  info->current_record= UINT32_MAX;             /* For heap_rrnd() */
 
31
 
 
32
  if (keyinfo->algorithm == HA_KEY_ALG_BTREE)
 
33
  {
 
34
    heap_rb_param custom_arg;
 
35
 
 
36
    custom_arg.keyseg= info->s->keydef[inx].seg;
 
37
    custom_arg.key_length= info->lastkey_len= 
 
38
      hp_rb_pack_key(keyinfo, (unsigned char*) info->lastkey,
 
39
                     (unsigned char*) key, keypart_map);
 
40
    custom_arg.search_flag= SEARCH_FIND | SEARCH_SAME;
 
41
    /* for next rkey() after deletion */
 
42
    if (find_flag == HA_READ_AFTER_KEY)
 
43
      info->last_find_flag= HA_READ_KEY_OR_NEXT;
 
44
    else if (find_flag == HA_READ_BEFORE_KEY)
 
45
      info->last_find_flag= HA_READ_KEY_OR_PREV;
 
46
    else
 
47
      info->last_find_flag= find_flag;
 
48
    if (!(pos= tree_search_key(&keyinfo->rb_tree, info->lastkey, info->parents,
 
49
                               &info->last_pos, find_flag, &custom_arg)))
 
50
    {
 
51
      info->update= 0;
 
52
      return(my_errno= HA_ERR_KEY_NOT_FOUND);
 
53
    }
 
54
    memcpy(&pos, pos + (*keyinfo->get_key_length)(keyinfo, pos), sizeof(unsigned char*));
 
55
    info->current_ptr= pos;
 
56
  }
 
57
  else
35
58
  {
36
59
    if (!(pos= hp_search(info, share->keydef + inx, key, 0)))
37
60
    {
38
61
      info->update= 0;
39
 
      return(errno);
 
62
      return(my_errno);
40
63
    }
41
64
    if (!(keyinfo->flag & HA_NOSAME))
42
 
      memcpy(&info->lastkey[0], key, (size_t) keyinfo->length);
 
65
      memcpy(info->lastkey, key, (size_t) keyinfo->length);
43
66
  }
44
67
  hp_extract_record(share, record, pos);
45
68
  info->update= HA_STATE_AKTIV;
51
74
 
52
75
unsigned char* heap_find(HP_INFO *info, int inx, const unsigned char *key)
53
76
{
54
 
  return hp_search(info, info->getShare()->keydef + inx, key, 0);
 
77
  return hp_search(info, info->s->keydef + inx, key, 0);
55
78
}