~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_update.c

  • Committer: Jim Winstead
  • Date: 2008-07-19 02:56:45 UTC
  • mto: (202.1.8 codestyle)
  • mto: This revision was merged to the branch mainline in revision 207.
  • Revision ID: jimw@mysql.com-20080719025645-w2pwytebgzusjzjb
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
Temporarily disables tab-completion in the drizzle client until an appropriate
autoconf check can be added/enabled.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
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 */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* Update an old row in a MyISAM table */
17
17
 
18
 
#include "myisam_priv.h"
19
 
#include <drizzled/util/test.h>
20
 
 
21
 
using namespace drizzled;
22
 
 
23
 
int mi_update(register MI_INFO *info, const unsigned char *oldrec, unsigned char *newrec)
 
18
#include "myisamdef.h"
 
19
 
 
20
int mi_update(register MI_INFO *info, const uchar *oldrec, uchar *newrec)
24
21
{
25
22
  int flag,key_changed,save_errno;
26
 
  register internal::my_off_t pos;
27
 
  uint32_t i;
28
 
  unsigned char old_key[MI_MAX_KEY_BUFF],*new_key;
29
 
  bool auto_key_changed=0;
 
23
  register my_off_t pos;
 
24
  uint i;
 
25
  uchar old_key[MI_MAX_KEY_BUFF],*new_key;
 
26
  my_bool auto_key_changed=0;
30
27
  uint64_t changed;
31
28
  MYISAM_SHARE *share= info->s;
32
 
  internal::ha_checksum old_checksum= 0;
 
29
  ha_checksum old_checksum= 0;
33
30
 
34
31
  if (!(info->update & HA_STATE_AKTIV))
35
32
  {
36
 
    return(errno=HA_ERR_KEY_NOT_FOUND);
 
33
    return(my_errno=HA_ERR_KEY_NOT_FOUND);
37
34
  }
38
35
  if (share->options & HA_OPTION_READ_ONLY_DATA)
39
36
  {
40
 
    return(errno=EACCES);
 
37
    return(my_errno=EACCES);
41
38
  }
42
39
  if (info->state->key_file_length >= share->base.margin_key_file_length)
43
40
  {
44
 
    return(errno=HA_ERR_INDEX_FILE_FULL);
 
41
    return(my_errno=HA_ERR_INDEX_FILE_FULL);
45
42
  }
46
43
  pos=info->lastpos;
47
44
  if (_mi_readinfo(info,F_WRLCK,1))
48
 
    return(errno);
 
45
    return(my_errno);
49
46
 
50
47
  if (share->calc_checksum)
51
48
    old_checksum=info->checksum=(*share->calc_checksum)(info,oldrec);
52
49
  if ((*share->compare_record)(info,oldrec))
53
50
  {
54
 
    save_errno=errno;
 
51
    save_errno=my_errno;
55
52
    goto err_end;                       /* Record has changed */
56
53
  }
57
54
 
65
62
        mi_check_unique(info, def, newrec, mi_unique_hash(def, newrec),
66
63
                        info->lastpos))
67
64
    {
68
 
      save_errno=errno;
 
65
      save_errno=my_errno;
69
66
      goto err_end;
70
67
    }
71
68
  }
72
69
  if (_mi_mark_file_changed(info))
73
70
  {
74
 
    save_errno=errno;
 
71
    save_errno=my_errno;
75
72
    goto err_end;
76
73
  }
77
74
 
84
81
    if (mi_is_key_active(share->state.key_map, i))
85
82
    {
86
83
      {
87
 
        uint32_t new_length=_mi_make_key(info,i,new_key,newrec,pos);
88
 
        uint32_t old_length=_mi_make_key(info,i,old_key,oldrec,pos);
 
84
        uint new_length=_mi_make_key(info,i,new_key,newrec,pos);
 
85
        uint old_length=_mi_make_key(info,i,old_key,oldrec,pos);
89
86
 
90
87
        /* The above changed info->lastkey2. Inform mi_rnext_same(). */
91
88
        info->update&= ~HA_STATE_RNEXT_SAME;
92
89
 
93
90
        if (new_length != old_length ||
94
 
            memcmp(old_key,new_key,new_length))
 
91
            memcmp((uchar*) old_key,(uchar*) new_key,new_length))
95
92
        {
96
93
          if ((int) i == info->lastinx)
97
94
            key_changed|=HA_STATE_WRITTEN;      /* Mark that keyfile changed */
125
122
    */
126
123
    MI_STATUS_INFO state;
127
124
    ha_rows org_split;
128
 
    internal::my_off_t org_delete_link;
 
125
    my_off_t org_delete_link;
129
126
 
130
 
    memcpy(&state, info->state, sizeof(state));
 
127
    memcpy((char*) &state, (char*) info->state, sizeof(state));
131
128
    org_split=       share->state.split;
132
129
    org_delete_link= share->state.dellink;
133
130
    if ((*share->update_record)(info,pos,newrec))
134
131
      goto err;
135
132
    if (!key_changed &&
136
 
        (memcmp(&state, info->state, sizeof(state)) ||
 
133
        (memcmp((char*) &state, (char*) info->state, sizeof(state)) ||
137
134
         org_split != share->state.split ||
138
135
         org_delete_link != share->state.dellink))
139
136
      key_changed|= HA_STATE_CHANGED;           /* Must update index file */
146
143
 
147
144
  info->update= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED | HA_STATE_AKTIV |
148
145
                 key_changed);
 
146
  myisam_log_record(MI_LOG_UPDATE,info,newrec,info->lastpos,0);
149
147
  /*
150
148
    Every myisam function that updates myisam table must end with
151
149
    call to _mi_writeinfo(). If operation (second param of
156
154
    mi_update() must always pass !0 value as operation, since even if
157
155
    there is no index change there could be data change.
158
156
  */
159
 
  _mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE);
 
157
  VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE));
 
158
  if (info->invalidator != 0)
 
159
  {
 
160
    (*info->invalidator)(info->filename);
 
161
    info->invalidator=0;
 
162
  }
160
163
  return(0);
161
164
 
162
165
err:
163
 
  save_errno=errno;
 
166
  save_errno=my_errno;
164
167
  if (changed)
165
168
    key_changed|= HA_STATE_CHANGED;
166
 
  if (errno == HA_ERR_FOUND_DUPP_KEY || errno == HA_ERR_OUT_OF_MEM ||
167
 
      errno == HA_ERR_RECORD_FILE_FULL)
 
169
  if (my_errno == HA_ERR_FOUND_DUPP_KEY || my_errno == HA_ERR_OUT_OF_MEM ||
 
170
      my_errno == HA_ERR_RECORD_FILE_FULL)
168
171
  {
169
172
    info->errkey= (int) i;
170
173
    flag=0;
173
176
      if (((uint64_t) 1 << i) & changed)
174
177
      {
175
178
        {
176
 
          uint32_t new_length=_mi_make_key(info,i,new_key,newrec,pos);
177
 
          uint32_t old_length= _mi_make_key(info,i,old_key,oldrec,pos);
 
179
          uint new_length=_mi_make_key(info,i,new_key,newrec,pos);
 
180
          uint old_length= _mi_make_key(info,i,old_key,oldrec,pos);
178
181
          if ((flag++ && _mi_ck_delete(info,i,new_key,new_length)) ||
179
182
              _mi_ck_write(info,i,old_key,old_length))
180
183
            break;
191
194
                 key_changed);
192
195
 
193
196
 err_end:
194
 
  _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
 
197
  myisam_log_record(MI_LOG_UPDATE,info,newrec,info->lastpos,my_errno);
 
198
  VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
195
199
  if (save_errno == HA_ERR_KEY_NOT_FOUND)
196
200
  {
197
201
    mi_print_error(info->s, HA_ERR_CRASHED);
198
202
    save_errno=HA_ERR_CRASHED;
199
203
  }
200
 
  return(errno=save_errno);
 
204
  return(my_errno=save_errno);
201
205
} /* mi_update */