~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_delete.c

  • Committer: Monty Taylor
  • Date: 2008-08-01 22:33:44 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080801223344-vzhlflfmtijp1imv
First pass at gettexizing the error messages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2002, 2004-2006 MySQL AB
 
1
/* Copyright (C) 2000-2002, 2004-200 MySQL AB
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* remove current record in heap-database */
17
17
 
18
 
#include "heap_priv.h"
 
18
#include "heapdef.h"
19
19
 
20
 
int heap_delete(HP_INFO *info, const unsigned char *record)
 
20
int heap_delete(HP_INFO *info, const uchar *record)
21
21
{
22
 
  unsigned char *pos;
23
 
  HP_SHARE *share=info->getShare();
 
22
  uchar *pos;
 
23
  HP_SHARE *share=info->s;
24
24
  HP_KEYDEF *keydef, *end, *p_lastinx;
25
25
 
26
26
  test_active(info);
27
27
 
28
28
  if (info->opt_flag & READ_CHECK_USED)
29
 
    return(errno);   /* Record changed */
 
29
    return(my_errno);                   /* Record changed */
30
30
  share->changed=1;
31
31
 
32
32
  if ( --(share->records) < share->blength >> 1) share->blength>>=1;
33
33
  pos=info->current_ptr;
34
34
 
35
35
  p_lastinx = share->keydef + info->lastinx;
36
 
  for (keydef = share->keydef, end = keydef + share->keys; keydef < end;
 
36
  for (keydef = share->keydef, end = keydef + share->keys; keydef < end; 
37
37
       keydef++)
38
38
  {
39
 
    if (hp_delete_key(info, keydef, record, pos, keydef == p_lastinx))
 
39
    if ((*keydef->delete_key)(info, keydef, record, pos, keydef == p_lastinx))
40
40
      goto err;
41
41
  }
42
42
 
43
43
  info->update=HA_STATE_DELETED;
44
 
  hp_free_chunks(&share->recordspace, pos);
 
44
  *((uchar**) pos)=share->del_link;
 
45
  share->del_link=pos;
 
46
  pos[share->reclength]=0;              /* Record deleted */
 
47
  share->deleted++;
45
48
  info->current_hash_ptr=0;
46
49
 
47
50
  return(0);
48
51
err:
49
52
  if (++(share->records) == share->blength)
50
53
    share->blength+= share->blength;
51
 
  return(errno);
 
54
  return(my_errno);
 
55
}
 
56
 
 
57
 
 
58
/*
 
59
  Remove one key from rb-tree
 
60
*/
 
61
 
 
62
int hp_rb_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo,
 
63
                   const uchar *record, uchar *recpos, int flag)
 
64
{
 
65
  heap_rb_param custom_arg;
 
66
  uint old_allocated;
 
67
  int res;
 
68
 
 
69
  if (flag) 
 
70
    info->last_pos= NULL; /* For heap_rnext/heap_rprev */
 
71
 
 
72
  custom_arg.keyseg= keyinfo->seg;
 
73
  custom_arg.key_length= hp_rb_make_key(keyinfo, info->recbuf, record, recpos);
 
74
  custom_arg.search_flag= SEARCH_SAME;
 
75
  old_allocated= keyinfo->rb_tree.allocated;
 
76
  res= tree_delete(&keyinfo->rb_tree, info->recbuf, custom_arg.key_length,
 
77
                   &custom_arg);
 
78
  info->s->index_length-= (old_allocated - keyinfo->rb_tree.allocated);
 
79
  return res;
52
80
}
53
81
 
54
82
 
69
97
*/
70
98
 
71
99
int hp_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo,
72
 
                  const unsigned char *record, unsigned char *recpos, int flag)
 
100
                  const uchar *record, uchar *recpos, int flag)
73
101
{
74
 
  uint32_t blength,pos2,pos_hashnr,lastpos_hashnr;
 
102
  ulong blength,pos2,pos_hashnr,lastpos_hashnr;
75
103
  HASH_INFO *lastpos,*gpos,*pos,*pos3,*empty,*last_ptr;
76
 
  HP_SHARE *share=info->getShare();
 
104
  HP_SHARE *share=info->s;
77
105
 
78
106
  blength=share->blength;
79
107
  if (share->records+1 == blength)
80
108
    blength+= blength;
81
 
 
82
 
  /* find the very last HASH_INFO pointer in the index */
83
 
  /* note that records has already been decremented */
84
109
  lastpos=hp_find_hash(&keyinfo->block,share->records);
85
110
  last_ptr=0;
86
111
 
97
122
    gpos=pos;
98
123
    if (!(pos=pos->next_key))
99
124
    {
100
 
      return(errno= drizzled::HA_ERR_CRASHED);  /* This shouldn't happend */
 
125
      return(my_errno=HA_ERR_CRASHED);  /* This shouldn't happend */
101
126
    }
102
127
  }
103
128
 
110
135
    info->current_ptr = last_ptr ? last_ptr->ptr_to_rec : 0;
111
136
  }
112
137
  empty=pos;
113
 
  if (gpos) {
114
 
    /* gpos says we have previous HASH_INFO, change previous to point to next, this way unlinking "empty" */
115
 
    gpos->next_key=pos->next_key;
116
 
  }
 
138
  if (gpos)
 
139
    gpos->next_key=pos->next_key;       /* unlink current ptr */
117
140
  else if (pos->next_key)
118
141
  {
119
 
    /* no previous gpos, this pos is the first in the list and it has pointer to "next" */
120
 
    /* move next HASH_INFO data to our pos, to free up space at the next position */
121
 
    /* remember next pos as "empty", nobody refers to "empty" at this point */
122
142
    empty=pos->next_key;
123
143
    pos->ptr_to_rec=empty->ptr_to_rec;
124
144
    pos->next_key=empty->next_key;
125
145
  }
126
146
  else
127
 
  {
128
 
    /* this was the only HASH_INFO at this position */
129
147
    keyinfo->hash_buckets--;
130
 
  }
131
148
 
132
149
  if (empty == lastpos)                 /* deleted last hash key */
133
150
    return (0);