~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_update.c

  • Committer: Monty Taylor
  • Date: 2008-07-15 21:40:58 UTC
  • mfrom: (77.1.113 codestyle32)
  • mto: This revision was merged to the branch mainline in revision 176.
  • Revision ID: mordred@camelot-20080715214058-rm3phulldos9xehv
Merged from codestyle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
/* Update current record in heap-database */
17
17
 
18
 
#include "heap_priv.h"
19
 
 
20
 
using namespace drizzled;
21
 
 
22
 
int heap_update(HP_INFO *info, const unsigned char *old_record, const unsigned char *new_record)
 
18
#include "heapdef.h"
 
19
 
 
20
int heap_update(HP_INFO *info, const uchar *old, const uchar *heap_new)
23
21
{
24
22
  HP_KEYDEF *keydef, *end, *p_lastinx;
25
 
  unsigned char *pos;
26
 
  bool auto_key_changed= 0;
27
 
  HP_SHARE *share= info->getShare();
 
23
  uchar *pos;
 
24
  my_bool auto_key_changed= 0;
 
25
  HP_SHARE *share= info->s;
 
26
  DBUG_ENTER("heap_update");
28
27
 
29
28
  test_active(info);
30
29
  pos=info->current_ptr;
31
30
 
32
 
  if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,old_record))
33
 
    return(errno);                              /* Record changed */
34
 
 
 
31
  if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,old))
 
32
    DBUG_RETURN(my_errno);                              /* Record changed */
35
33
  if (--(share->records) < share->blength >> 1) share->blength>>= 1;
36
34
  share->changed=1;
37
35
 
38
36
  p_lastinx= share->keydef + info->lastinx;
39
37
  for (keydef= share->keydef, end= keydef + share->keys; keydef < end; keydef++)
40
38
  {
41
 
    if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
 
39
    if (hp_rec_key_cmp(keydef, old, heap_new, 0))
42
40
    {
43
 
      if (hp_delete_key(info, keydef, old_record, pos, keydef == p_lastinx) ||
44
 
          hp_write_key(info, keydef, new_record, pos))
45
 
      {
 
41
      if ((*keydef->delete_key)(info, keydef, old, pos, keydef == p_lastinx) ||
 
42
          (*keydef->write_key)(info, keydef, heap_new, pos))
46
43
        goto err;
47
 
      }
48
44
      if (share->auto_key == (uint) (keydef - share->keydef + 1))
49
45
        auto_key_changed= 1;
50
46
    }
51
47
  }
52
 
  hp_copy_record_data_to_chunkset(share, new_record, pos);
 
48
 
 
49
  memcpy(pos,heap_new,(size_t) share->reclength);
53
50
  if (++(share->records) == share->blength) share->blength+= share->blength;
54
51
 
 
52
#if !defined(DBUG_OFF) && defined(EXTRA_HEAP_DEBUG)
 
53
  DBUG_EXECUTE("check_heap",heap_check_heap(info, 0););
 
54
#endif
55
55
  if (auto_key_changed)
56
 
    heap_update_auto_increment(info, new_record);
57
 
  return(0);
 
56
    heap_update_auto_increment(info, heap_new);
 
57
  DBUG_RETURN(0);
58
58
 
59
59
 err:
60
 
  if (errno == HA_ERR_FOUND_DUPP_KEY)
 
60
  if (my_errno == HA_ERR_FOUND_DUPP_KEY)
61
61
  {
62
62
    info->errkey = (int) (keydef - share->keydef);
 
63
    if (keydef->algorithm == HA_KEY_ALG_BTREE)
 
64
    {
 
65
      /* we don't need to delete non-inserted key from rb-tree */
 
66
      if ((*keydef->write_key)(info, keydef, old, pos))
 
67
      {
 
68
        if (++(share->records) == share->blength)
 
69
          share->blength+= share->blength;
 
70
        DBUG_RETURN(my_errno);
 
71
      }
 
72
      keydef--;
 
73
    }
63
74
    while (keydef >= share->keydef)
64
75
    {
65
 
      if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
 
76
      if (hp_rec_key_cmp(keydef, old, heap_new, 0))
66
77
      {
67
 
        if (hp_delete_key(info, keydef, new_record, pos, 0) ||
68
 
            hp_write_key(info, keydef, old_record, pos))
 
78
        if ((*keydef->delete_key)(info, keydef, heap_new, pos, 0) ||
 
79
            (*keydef->write_key)(info, keydef, old, pos))
69
80
          break;
70
81
      }
71
82
      keydef--;
72
83
    }
73
84
  }
74
 
 
75
85
  if (++(share->records) == share->blength)
76
86
    share->blength+= share->blength;
77
 
 
78
 
  return(errno);
 
87
  DBUG_RETURN(my_errno);
79
88
} /* heap_update */