16
16
/* Update current record in heap-database */
18
#include "heap_priv.h"
20
using namespace drizzled;
22
int heap_update(HP_INFO *info, const unsigned char *old_record, const unsigned char *new_record)
20
int heap_update(HP_INFO *info, const uchar *old, const uchar *heap_new)
24
22
HP_KEYDEF *keydef, *end, *p_lastinx;
26
bool auto_key_changed= 0;
27
HP_SHARE *share= info->getShare();
24
my_bool auto_key_changed= 0;
25
HP_SHARE *share= info->s;
30
28
pos=info->current_ptr;
32
if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,old_record))
33
return(errno); /* Record changed */
30
if (info->opt_flag & READ_CHECK_USED)
31
return(my_errno); /* Record changed */
35
32
if (--(share->records) < share->blength >> 1) share->blength>>= 1;
38
35
p_lastinx= share->keydef + info->lastinx;
39
36
for (keydef= share->keydef, end= keydef + share->keys; keydef < end; keydef++)
41
if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
38
if (hp_rec_key_cmp(keydef, old, heap_new, 0))
43
if (hp_delete_key(info, keydef, old_record, pos, keydef == p_lastinx) ||
44
hp_write_key(info, keydef, new_record, pos))
40
if ((*keydef->delete_key)(info, keydef, old, pos, keydef == p_lastinx) ||
41
(*keydef->write_key)(info, keydef, heap_new, pos))
48
43
if (share->auto_key == (uint) (keydef - share->keydef + 1))
49
44
auto_key_changed= 1;
52
hp_copy_record_data_to_chunkset(share, new_record, pos);
48
memcpy(pos,heap_new,(size_t) share->reclength);
53
49
if (++(share->records) == share->blength) share->blength+= share->blength;
55
51
if (auto_key_changed)
56
heap_update_auto_increment(info, new_record);
52
heap_update_auto_increment(info, heap_new);
60
if (errno == HA_ERR_FOUND_DUPP_KEY)
56
if (my_errno == HA_ERR_FOUND_DUPP_KEY)
62
58
info->errkey = (int) (keydef - share->keydef);
59
if (keydef->algorithm == HA_KEY_ALG_BTREE)
61
/* we don't need to delete non-inserted key from rb-tree */
62
if ((*keydef->write_key)(info, keydef, old, pos))
64
if (++(share->records) == share->blength)
65
share->blength+= share->blength;
63
70
while (keydef >= share->keydef)
65
if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
72
if (hp_rec_key_cmp(keydef, old, heap_new, 0))
67
if (hp_delete_key(info, keydef, new_record, pos, 0) ||
68
hp_write_key(info, keydef, old_record, pos))
74
if ((*keydef->delete_key)(info, keydef, heap_new, pos, 0) ||
75
(*keydef->write_key)(info, keydef, old, pos))
75
81
if (++(share->records) == share->blength)
76
82
share->blength+= share->blength;
79
84
} /* heap_update */