~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_update.c

  • Committer: Monty Taylor
  • Date: 2008-08-02 00:06:32 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080802000632-jsse0zdd9r6ic5ku
Actually turn gettext on...

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* Update current record in heap-database */
17
17
 
18
 
#include "heap_priv.h"
19
 
 
20
 
using namespace drizzled;
21
 
 
22
 
int heap_update(HP_INFO *info, const unsigned char *old_record, const unsigned char *new_record)
 
18
#include "heapdef.h"
 
19
 
 
20
int heap_update(HP_INFO *info, const uchar *old, const uchar *heap_new)
23
21
{
24
22
  HP_KEYDEF *keydef, *end, *p_lastinx;
25
 
  unsigned char *pos;
26
 
  bool auto_key_changed= 0;
27
 
  HP_SHARE *share= info->getShare();
 
23
  uchar *pos;
 
24
  my_bool auto_key_changed= 0;
 
25
  HP_SHARE *share= info->s;
28
26
 
29
27
  test_active(info);
30
28
  pos=info->current_ptr;
31
29
 
32
 
  if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,old_record))
33
 
    return(errno);                              /* Record changed */
34
 
 
 
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;
36
33
  share->changed=1;
37
34
 
38
35
  p_lastinx= share->keydef + info->lastinx;
39
36
  for (keydef= share->keydef, end= keydef + share->keys; keydef < end; keydef++)
40
37
  {
41
 
    if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
 
38
    if (hp_rec_key_cmp(keydef, old, heap_new, 0))
42
39
    {
43
 
      if (hp_delete_key(info, keydef, old_record, pos, keydef == p_lastinx) ||
44
 
          hp_write_key(info, keydef, new_record, pos))
45
 
      {
 
40
      if ((*keydef->delete_key)(info, keydef, old, pos, keydef == p_lastinx) ||
 
41
          (*keydef->write_key)(info, keydef, heap_new, pos))
46
42
        goto err;
47
 
      }
48
43
      if (share->auto_key == (uint) (keydef - share->keydef + 1))
49
44
        auto_key_changed= 1;
50
45
    }
51
46
  }
52
 
  hp_copy_record_data_to_chunkset(share, new_record, pos);
 
47
 
 
48
  memcpy(pos,heap_new,(size_t) share->reclength);
53
49
  if (++(share->records) == share->blength) share->blength+= share->blength;
54
50
 
55
51
  if (auto_key_changed)
56
 
    heap_update_auto_increment(info, new_record);
 
52
    heap_update_auto_increment(info, heap_new);
57
53
  return(0);
58
54
 
59
55
 err:
60
 
  if (errno == HA_ERR_FOUND_DUPP_KEY)
 
56
  if (my_errno == HA_ERR_FOUND_DUPP_KEY)
61
57
  {
62
58
    info->errkey = (int) (keydef - share->keydef);
 
59
    if (keydef->algorithm == HA_KEY_ALG_BTREE)
 
60
    {
 
61
      /* we don't need to delete non-inserted key from rb-tree */
 
62
      if ((*keydef->write_key)(info, keydef, old, pos))
 
63
      {
 
64
        if (++(share->records) == share->blength)
 
65
          share->blength+= share->blength;
 
66
        return(my_errno);
 
67
      }
 
68
      keydef--;
 
69
    }
63
70
    while (keydef >= share->keydef)
64
71
    {
65
 
      if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
 
72
      if (hp_rec_key_cmp(keydef, old, heap_new, 0))
66
73
      {
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))
69
76
          break;
70
77
      }
71
78
      keydef--;
72
79
    }
73
80
  }
74
 
 
75
81
  if (++(share->records) == share->blength)
76
82
    share->blength+= share->blength;
77
 
 
78
 
  return(errno);
 
83
  return(my_errno);
79
84
} /* heap_update */