~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_rkey.c

  • Committer: Stewart Smith
  • Date: 2008-07-13 06:56:15 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713065615-vzok75kgnnviokl9
Move MD5() into a UDF

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,
 
16
#include "heapdef.h"
 
17
 
 
18
int heap_rkey(HP_INFO *info, uchar *record, int inx, const uchar *key, 
23
19
              key_part_map keypart_map, enum ha_rkey_function find_flag)
24
20
{
25
 
  unsigned char *pos;
 
21
  uchar *pos;
26
22
  HP_SHARE *share= info->s;
27
23
  HP_KEYDEF *keyinfo= share->keydef + inx;
 
24
  DBUG_ENTER("heap_rkey");
 
25
  DBUG_PRINT("enter",("info: 0x%lx  inx: %d", (long) info, inx));
28
26
 
29
27
  if ((uint) inx >= share->keys)
30
28
  {
31
 
    return(errno= HA_ERR_WRONG_INDEX);
 
29
    DBUG_RETURN(my_errno= HA_ERR_WRONG_INDEX);
32
30
  }
33
31
  info->lastinx= inx;
34
 
  info->current_record= UINT32_MAX;             /* For heap_rrnd() */
 
32
  info->current_record= (ulong) ~0L;            /* For heap_rrnd() */
35
33
 
36
34
  if (keyinfo->algorithm == HA_KEY_ALG_BTREE)
37
35
  {
38
36
    heap_rb_param custom_arg;
39
37
 
40
38
    custom_arg.keyseg= info->s->keydef[inx].seg;
41
 
    custom_arg.key_length= info->lastkey_len=
42
 
      hp_rb_pack_key(keyinfo, (unsigned char*) info->lastkey,
43
 
                     (unsigned char*) key, keypart_map);
 
39
    custom_arg.key_length= info->lastkey_len= 
 
40
      hp_rb_pack_key(keyinfo, (uchar*) info->lastkey,
 
41
                     (uchar*) key, keypart_map);
44
42
    custom_arg.search_flag= SEARCH_FIND | SEARCH_SAME;
45
43
    /* for next rkey() after deletion */
46
44
    if (find_flag == HA_READ_AFTER_KEY)
49
47
      info->last_find_flag= HA_READ_KEY_OR_PREV;
50
48
    else
51
49
      info->last_find_flag= find_flag;
52
 
    if (!(pos= (unsigned char *)tree_search_key(&keyinfo->rb_tree,
53
 
                                                info->lastkey, info->parents,
54
 
                                                &info->last_pos,
55
 
                                                find_flag, &custom_arg)))
 
50
    if (!(pos= tree_search_key(&keyinfo->rb_tree, info->lastkey, info->parents,
 
51
                               &info->last_pos, find_flag, &custom_arg)))
56
52
    {
57
53
      info->update= 0;
58
 
      return(errno= HA_ERR_KEY_NOT_FOUND);
 
54
      DBUG_RETURN(my_errno= HA_ERR_KEY_NOT_FOUND);
59
55
    }
60
 
    memcpy(&pos, pos + (*keyinfo->get_key_length)(keyinfo, pos), sizeof(unsigned char*));
 
56
    memcpy(&pos, pos + (*keyinfo->get_key_length)(keyinfo, pos), sizeof(uchar*));
61
57
    info->current_ptr= pos;
62
58
  }
63
59
  else
65
61
    if (!(pos= hp_search(info, share->keydef + inx, key, 0)))
66
62
    {
67
63
      info->update= 0;
68
 
      return(errno);
 
64
      DBUG_RETURN(my_errno);
69
65
    }
70
66
    if (!(keyinfo->flag & HA_NOSAME))
71
67
      memcpy(info->lastkey, key, (size_t) keyinfo->length);
72
68
  }
73
 
  hp_extract_record(share, record, pos);
 
69
  memcpy(record, pos, (size_t) share->reclength);
74
70
  info->update= HA_STATE_AKTIV;
75
 
  return(0);
 
71
  DBUG_RETURN(0);
76
72
}
77
73
 
78
74
 
79
75
        /* Quick find of record */
80
76
 
81
 
unsigned char* heap_find(HP_INFO *info, int inx, const unsigned char *key)
 
77
uchar* heap_find(HP_INFO *info, int inx, const uchar *key)
82
78
{
83
79
  return hp_search(info, info->s->keydef + inx, key, 0);
84
80
}