~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2002, 2004-2005 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
/* Update current record in heap-database */
17
18
#include "heapdef.h"
19
20
int heap_update(HP_INFO *info, const uchar *old, const uchar *heap_new)
21
{
22
  HP_KEYDEF *keydef, *end, *p_lastinx;
23
  uchar *pos;
24
  my_bool auto_key_changed= 0;
25
  HP_SHARE *share= info->s;
26
27
  test_active(info);
28
  pos=info->current_ptr;
29
51.3.4 by Jay Pipes
Final removal from heap storage engine plus fixes from MontyT re: _mi_report_crashed()
30
  if (info->opt_flag & READ_CHECK_USED)
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
31
    return(my_errno);				/* Record changed */
1 by brian
clean slate
32
  if (--(share->records) < share->blength >> 1) share->blength>>= 1;
33
  share->changed=1;
34
35
  p_lastinx= share->keydef + info->lastinx;
36
  for (keydef= share->keydef, end= keydef + share->keys; keydef < end; keydef++)
37
  {
38
    if (hp_rec_key_cmp(keydef, old, heap_new, 0))
39
    {
40
      if ((*keydef->delete_key)(info, keydef, old, pos, keydef == p_lastinx) ||
41
          (*keydef->write_key)(info, keydef, heap_new, pos))
42
        goto err;
43
      if (share->auto_key == (uint) (keydef - share->keydef + 1))
44
        auto_key_changed= 1;
45
    }
46
  }
47
48
  memcpy(pos,heap_new,(size_t) share->reclength);
49
  if (++(share->records) == share->blength) share->blength+= share->blength;
50
51
  if (auto_key_changed)
52
    heap_update_auto_increment(info, heap_new);
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
53
  return(0);
1 by brian
clean slate
54
55
 err:
56
  if (my_errno == HA_ERR_FOUND_DUPP_KEY)
57
  {
58
    info->errkey = (int) (keydef - share->keydef);
59
    if (keydef->algorithm == HA_KEY_ALG_BTREE)
60
    {
61
      /* we don't need to delete non-inserted key from rb-tree */
62
      if ((*keydef->write_key)(info, keydef, old, pos))
63
      {
64
        if (++(share->records) == share->blength)
65
	  share->blength+= share->blength;
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
66
        return(my_errno);
1 by brian
clean slate
67
      }
68
      keydef--;
69
    }
70
    while (keydef >= share->keydef)
71
    {
72
      if (hp_rec_key_cmp(keydef, old, heap_new, 0))
73
      {
74
	if ((*keydef->delete_key)(info, keydef, heap_new, pos, 0) ||
75
	    (*keydef->write_key)(info, keydef, old, pos))
76
	  break;
77
      }
78
      keydef--;
79
    }
80
  }
81
  if (++(share->records) == share->blength)
82
    share->blength+= share->blength;
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
83
  return(my_errno);
1 by brian
clean slate
84
} /* heap_update */