00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "heap_priv.h"
00019
00020 using namespace drizzled;
00021
00022 int heap_update(HP_INFO *info, const unsigned char *old_record, const unsigned char *new_record)
00023 {
00024 HP_KEYDEF *keydef, *end, *p_lastinx;
00025 unsigned char *pos;
00026 bool auto_key_changed= 0;
00027 HP_SHARE *share= info->getShare();
00028
00029 test_active(info);
00030 pos=info->current_ptr;
00031
00032 if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,old_record))
00033 return(errno);
00034
00035 if (--(share->records) < share->blength >> 1) share->blength>>= 1;
00036 share->changed=1;
00037
00038 p_lastinx= share->keydef + info->lastinx;
00039 for (keydef= share->keydef, end= keydef + share->keys; keydef < end; keydef++)
00040 {
00041 if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
00042 {
00043 if (hp_delete_key(info, keydef, old_record, pos, keydef == p_lastinx) ||
00044 hp_write_key(info, keydef, new_record, pos))
00045 {
00046 goto err;
00047 }
00048 if (share->auto_key == (uint) (keydef - share->keydef + 1))
00049 auto_key_changed= 1;
00050 }
00051 }
00052 hp_copy_record_data_to_chunkset(share, new_record, pos);
00053 if (++(share->records) == share->blength) share->blength+= share->blength;
00054
00055 if (auto_key_changed)
00056 heap_update_auto_increment(info, new_record);
00057 return(0);
00058
00059 err:
00060 if (errno == HA_ERR_FOUND_DUPP_KEY)
00061 {
00062 info->errkey = (int) (keydef - share->keydef);
00063 while (keydef >= share->keydef)
00064 {
00065 if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
00066 {
00067 if (hp_delete_key(info, keydef, new_record, pos, 0) ||
00068 hp_write_key(info, keydef, old_record, pos))
00069 break;
00070 }
00071 keydef--;
00072 }
00073 }
00074
00075 if (++(share->records) == share->blength)
00076 share->blength+= share->blength;
00077
00078 return(errno);
00079 }