Drizzled Public API Documentation

hp_update.cc
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 /* Update current record in heap-database */
17 
18 #include "heap_priv.h"
19 #include <drizzled/error_t.h>
20 
21 using namespace drizzled;
22 
23 int heap_update(HP_INFO *info, const unsigned char *old_record, const unsigned char *new_record)
24 {
25  HP_KEYDEF *keydef, *end, *p_lastinx;
26  unsigned char *pos;
27  bool auto_key_changed= 0;
28  HP_SHARE *share= info->getShare();
29 
30  test_active(info);
31  pos=info->current_ptr;
32 
33  if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,old_record))
34  return(errno); /* Record changed */
35 
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  {
42  if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
43  {
44  if (hp_delete_key(info, keydef, old_record, pos, keydef == p_lastinx) ||
45  hp_write_key(info, keydef, new_record, pos))
46  {
47  goto err;
48  }
49  if (share->auto_key == (uint) (keydef - share->keydef + 1))
50  auto_key_changed= 1;
51  }
52  }
53  hp_copy_record_data_to_chunkset(share, new_record, pos);
54  if (++(share->records) == share->blength) share->blength+= share->blength;
55 
56  if (auto_key_changed)
57  heap_update_auto_increment(info, new_record);
58  return(0);
59 
60  err:
61  if (errno == HA_ERR_FOUND_DUPP_KEY)
62  {
63  info->errkey = (int) (keydef - share->keydef);
64  while (keydef >= share->keydef)
65  {
66  if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
67  {
68  if (hp_delete_key(info, keydef, new_record, pos, 0) ||
69  hp_write_key(info, keydef, old_record, pos))
70  break;
71  }
72  keydef--;
73  }
74  }
75 
76  if (++(share->records) == share->blength)
77  share->blength+= share->blength;
78 
79  return(errno);
80 } /* heap_update */
TODO: Rename this file - func.h is stupid.