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