~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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
16
/* Update current record in heap-database */
17
1130.3.28 by Monty Taylor
Moved heapdef.h and myisamdef.h to *_priv.h for easier filtering for include guard check.
18
#include "heap_priv.h"
2241.4.5 by Stewart Smith
remove two #includes from heap_priv.h - include error_t.h only where needed
19
#include <drizzled/error_t.h>
1 by brian
clean slate
20
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
21
using namespace drizzled;
22
481 by Brian Aker
Remove all of uchar.
23
int heap_update(HP_INFO *info, const unsigned char *old_record, const unsigned char *new_record)
1 by brian
clean slate
24
{
25
  HP_KEYDEF *keydef, *end, *p_lastinx;
481 by Brian Aker
Remove all of uchar.
26
  unsigned char *pos;
280 by Brian Aker
Removed my_bool from heap engine.
27
  bool auto_key_changed= 0;
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
28
  HP_SHARE *share= info->getShare();
1 by brian
clean slate
29
30
  test_active(info);
31
  pos=info->current_ptr;
32
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
33
  if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,old_record))
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
34
    return(errno);				/* Record changed */
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
35
1 by brian
clean slate
36
  if (--(share->records) < share->blength >> 1) share->blength>>= 1;
37
  share->changed=1;
38
39
  p_lastinx= share->keydef + info->lastinx;
40
  for (keydef= share->keydef, end= keydef + share->keys; keydef < end; keydef++)
41
  {
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
42
    if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
1 by brian
clean slate
43
    {
1749.3.3 by Brian Aker
Remove another layer of dead code in heap.
44
      if (hp_delete_key(info, keydef, old_record, pos, keydef == p_lastinx) ||
45
          hp_write_key(info, keydef, new_record, pos))
46
      {
1 by brian
clean slate
47
        goto err;
1749.3.3 by Brian Aker
Remove another layer of dead code in heap.
48
      }
1 by brian
clean slate
49
      if (share->auto_key == (uint) (keydef - share->keydef + 1))
50
        auto_key_changed= 1;
51
    }
52
  }
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
53
  hp_copy_record_data_to_chunkset(share, new_record, pos);
1 by brian
clean slate
54
  if (++(share->records) == share->blength) share->blength+= share->blength;
55
56
  if (auto_key_changed)
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
57
    heap_update_auto_increment(info, new_record);
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
58
  return(0);
1 by brian
clean slate
59
60
 err:
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
61
  if (errno == HA_ERR_FOUND_DUPP_KEY)
1 by brian
clean slate
62
  {
63
    info->errkey = (int) (keydef - share->keydef);
64
    while (keydef >= share->keydef)
65
    {
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
66
      if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
1 by brian
clean slate
67
      {
1749.3.3 by Brian Aker
Remove another layer of dead code in heap.
68
	if (hp_delete_key(info, keydef, new_record, pos, 0) ||
69
	    hp_write_key(info, keydef, old_record, pos))
1 by brian
clean slate
70
	  break;
71
      }
72
      keydef--;
73
    }
74
  }
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
75
1 by brian
clean slate
76
  if (++(share->records) == share->blength)
77
    share->blength+= share->blength;
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
78
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
79
  return(errno);
1 by brian
clean slate
80
} /* heap_update */