~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
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"
1 by brian
clean slate
19
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
20
using namespace drizzled;
21
481 by Brian Aker
Remove all of uchar.
22
int heap_update(HP_INFO *info, const unsigned char *old_record, const unsigned char *new_record)
1 by brian
clean slate
23
{
24
  HP_KEYDEF *keydef, *end, *p_lastinx;
481 by Brian Aker
Remove all of uchar.
25
  unsigned char *pos;
280 by Brian Aker
Removed my_bool from heap engine.
26
  bool auto_key_changed= 0;
1 by brian
clean slate
27
  HP_SHARE *share= info->s;
482 by Brian Aker
Remove uint.
28
  uint32_t old_length, new_length;
29
  uint32_t old_chunk_count, new_chunk_count;
1 by brian
clean slate
30
31
  test_active(info);
32
  pos=info->current_ptr;
33
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
34
  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.
35
    return(errno);				/* Record changed */
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
36
37
  old_length = hp_get_encoded_data_length(share, old_record, &old_chunk_count);
38
  new_length = hp_get_encoded_data_length(share, new_record, &new_chunk_count);
39
40
  if (new_chunk_count > old_chunk_count) {
41
    /* extend the old chunkset size as necessary, but do not shrink yet */
42
    if (hp_reallocate_chunkset(&share->recordspace, new_chunk_count, pos)) {
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
43
      return(errno);                          /* Out of memory or table space */
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
44
    }
45
  }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
46
1 by brian
clean slate
47
  if (--(share->records) < share->blength >> 1) share->blength>>= 1;
48
  share->changed=1;
49
50
  p_lastinx= share->keydef + info->lastinx;
51
  for (keydef= share->keydef, end= keydef + share->keys; keydef < end; keydef++)
52
  {
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
53
    if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
1 by brian
clean slate
54
    {
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
55
      if ((*keydef->delete_key)(info, keydef, old_record, pos, keydef == p_lastinx) ||
56
          (*keydef->write_key)(info, keydef, new_record, pos))
1 by brian
clean slate
57
        goto err;
58
      if (share->auto_key == (uint) (keydef - share->keydef + 1))
59
        auto_key_changed= 1;
60
    }
61
  }
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
62
  hp_copy_record_data_to_chunkset(share, new_record, pos);
1 by brian
clean slate
63
  if (++(share->records) == share->blength) share->blength+= share->blength;
64
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
65
  if (new_chunk_count < old_chunk_count) {
66
    /* Shrink the chunkset to its new size */
67
    hp_reallocate_chunkset(&share->recordspace, new_chunk_count, pos);
68
  }
69
1 by brian
clean slate
70
  if (auto_key_changed)
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
71
    heap_update_auto_increment(info, new_record);
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
72
  return(0);
1 by brian
clean slate
73
74
 err:
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
75
  if (errno == HA_ERR_FOUND_DUPP_KEY)
1 by brian
clean slate
76
  {
77
    info->errkey = (int) (keydef - share->keydef);
78
    if (keydef->algorithm == HA_KEY_ALG_BTREE)
79
    {
80
      /* we don't need to delete non-inserted key from rb-tree */
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
81
      if ((*keydef->write_key)(info, keydef, old_record, pos))
1 by brian
clean slate
82
      {
83
        if (++(share->records) == share->blength)
84
	  share->blength+= share->blength;
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
85
        return(errno);
1 by brian
clean slate
86
      }
87
      keydef--;
88
    }
89
    while (keydef >= share->keydef)
90
    {
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
91
      if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
1 by brian
clean slate
92
      {
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
93
	if ((*keydef->delete_key)(info, keydef, new_record, pos, 0) ||
94
	    (*keydef->write_key)(info, keydef, old_record, pos))
1 by brian
clean slate
95
	  break;
96
      }
97
      keydef--;
98
    }
99
  }
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
100
1 by brian
clean slate
101
  if (++(share->records) == share->blength)
102
    share->blength+= share->blength;
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
103
104
  if (new_chunk_count > old_chunk_count) {
105
    /* Shrink the chunkset to its original size */
106
    hp_reallocate_chunkset(&share->recordspace, old_chunk_count, pos);
107
  }
108
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
109
  return(errno);
1 by brian
clean slate
110
} /* heap_update */