~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_statrec.c

Removed DBUG symbols and fixed TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#include "myisamdef.h"
19
19
 
20
 
int _mi_write_static_record(MI_INFO *info, const unsigned char *record)
 
20
 
 
21
int _mi_write_static_record(MI_INFO *info, const uchar *record)
21
22
{
22
 
  unsigned char temp[8];                                /* max pointer length */
 
23
  uchar temp[8];                                /* max pointer length */
23
24
  if (info->s->state.dellink != HA_OFFSET_ERROR &&
24
25
      !info->append_insert_at_end)
25
26
  {
52
53
        goto err;
53
54
      if (info->s->base.pack_reclength != info->s->base.reclength)
54
55
      {
55
 
        uint32_t length=info->s->base.pack_reclength - info->s->base.reclength;
56
 
        memset(temp, 0, length);
 
56
        uint length=info->s->base.pack_reclength - info->s->base.reclength;
 
57
        bzero(temp,length);
57
58
        if (my_b_write(&info->rec_cache, temp,length))
58
59
          goto err;
59
60
      }
67
68
        goto err;
68
69
      if (info->s->base.pack_reclength != info->s->base.reclength)
69
70
      {
70
 
        uint32_t length=info->s->base.pack_reclength - info->s->base.reclength;
71
 
        memset(temp, 0, length);
 
71
        uint length=info->s->base.pack_reclength - info->s->base.reclength;
 
72
        bzero(temp,length);
72
73
        if (info->s->file_write(info, temp,length,
73
74
                      info->state->data_file_length+
74
75
                      info->s->base.reclength,
84
85
  return 1;
85
86
}
86
87
 
87
 
int _mi_update_static_record(MI_INFO *info, my_off_t pos, const unsigned char *record)
 
88
int _mi_update_static_record(MI_INFO *info, my_off_t pos, const uchar *record)
88
89
{
89
90
  info->rec_cache.seek_not_done=1;              /* We have done a seek */
90
91
  return (info->s->file_write(info,
96
97
 
97
98
int _mi_delete_static_record(MI_INFO *info)
98
99
{
99
 
  unsigned char temp[9];                                /* 1+sizeof(uint32) */
 
100
  uchar temp[9];                                /* 1+sizeof(uint32) */
100
101
 
101
102
  info->state->del++;
102
103
  info->state->empty+=info->s->base.pack_reclength;
104
105
  _mi_dpointer(info,temp+1,info->s->state.dellink);
105
106
  info->s->state.dellink = info->lastpos;
106
107
  info->rec_cache.seek_not_done=1;
107
 
  return (info->s->file_write(info,(unsigned char*) temp, 1+info->s->rec_reflength,
 
108
  return (info->s->file_write(info,(uchar*) temp, 1+info->s->rec_reflength,
108
109
                    info->lastpos, MYF(MY_NABP)) != 0);
109
110
}
110
111
 
111
112
 
112
 
int _mi_cmp_static_record(register MI_INFO *info, register const unsigned char *old)
 
113
int _mi_cmp_static_record(register MI_INFO *info, register const uchar *old)
113
114
{
 
115
  DBUG_ENTER("_mi_cmp_static_record");
 
116
 
114
117
  if (info->opt_flag & WRITE_CACHE_USED)
115
118
  {
116
119
    if (flush_io_cache(&info->rec_cache))
117
120
    {
118
 
      return(-1);
 
121
      DBUG_RETURN(-1);
119
122
    }
120
123
    info->rec_cache.seek_not_done=1;            /* We have done a seek */
121
124
  }
126
129
    if (info->s->file_read(info, info->rec_buff, info->s->base.reclength,
127
130
                 info->lastpos,
128
131
                 MYF(MY_NABP)))
129
 
      return(-1);
 
132
      DBUG_RETURN(-1);
130
133
    if (memcmp(info->rec_buff, old,
131
134
               (uint) info->s->base.reclength))
132
135
    {
 
136
      DBUG_DUMP("read",old,info->s->base.reclength);
 
137
      DBUG_DUMP("disk",info->rec_buff,info->s->base.reclength);
133
138
      my_errno=HA_ERR_RECORD_CHANGED;           /* Record have changed */
134
 
      return(1);
 
139
      DBUG_RETURN(1);
135
140
    }
136
141
  }
137
 
  return(0);
 
142
  DBUG_RETURN(0);
138
143
}
139
144
 
140
145
 
141
146
int _mi_cmp_static_unique(MI_INFO *info, MI_UNIQUEDEF *def,
142
 
                          const unsigned char *record, my_off_t pos)
 
147
                          const uchar *record, my_off_t pos)
143
148
{
 
149
  DBUG_ENTER("_mi_cmp_static_unique");
 
150
 
144
151
  info->rec_cache.seek_not_done=1;              /* We have done a seek */
145
152
  if (info->s->file_read(info, info->rec_buff, info->s->base.reclength,
146
153
               pos, MYF(MY_NABP)))
147
 
    return(-1);
148
 
  return(mi_unique_comp(def, record, info->rec_buff,
 
154
    DBUG_RETURN(-1);
 
155
  DBUG_RETURN(mi_unique_comp(def, record, info->rec_buff,
149
156
                             def->null_are_equal));
150
157
}
151
158
 
156
163
        /*        MY_FILE_ERROR on read-error or locking-error */
157
164
 
158
165
int _mi_read_static_record(register MI_INFO *info, register my_off_t pos,
159
 
                           register unsigned char *record)
 
166
                           register uchar *record)
160
167
{
161
168
  int error;
162
169
 
189
196
 
190
197
 
191
198
 
192
 
int _mi_read_rnd_static_record(MI_INFO *info, unsigned char *buf,
 
199
int _mi_read_rnd_static_record(MI_INFO *info, uchar *buf,
193
200
                               register my_off_t filepos,
194
 
                               bool skip_deleted_blocks)
 
201
                               my_bool skip_deleted_blocks)
195
202
{
196
203
  int locked,error,cache_read;
197
 
  uint32_t cache_length;
 
204
  uint cache_length;
198
205
  MYISAM_SHARE *share=info->s;
 
206
  DBUG_ENTER("_mi_read_rnd_static_record");
199
207
 
200
208
  cache_read=0;
201
209
  cache_length=0;
202
210
  if (info->opt_flag & WRITE_CACHE_USED &&
203
211
      (info->rec_cache.pos_in_file <= filepos || skip_deleted_blocks) &&
204
212
      flush_io_cache(&info->rec_cache))
205
 
    return(my_errno);
 
213
    DBUG_RETURN(my_errno);
206
214
  if (info->opt_flag & READ_CACHE_USED)
207
215
  {                                             /* Cache in use */
208
216
    if (filepos == my_b_tell(&info->rec_cache) &&
220
228
    if (filepos >= info->state->data_file_length)
221
229
    {                                           /* Test if new records */
222
230
      if (_mi_readinfo(info,F_RDLCK,0))
223
 
        return(my_errno);
 
231
        DBUG_RETURN(my_errno);
224
232
      locked=1;
225
233
    }
226
234
    else
227
235
    {                                           /* We don't nead new info */
228
236
#ifndef UNSAFE_LOCKING
229
 
      locked=1;
 
237
      if ((! cache_read || share->base.reclength > cache_length) &&
 
238
          share->tot_locks == 0)
 
239
      {                                         /* record not in cache */
 
240
        if (my_lock(share->kfile,F_RDLCK,0L,F_TO_EOF,
 
241
                    MYF(MY_SEEK_NOT_DONE) | info->lock_wait))
 
242
          DBUG_RETURN(my_errno);
 
243
        locked=1;
 
244
      }
230
245
#else
231
246
      info->tmp_lock_type=F_RDLCK;
232
247
#endif
234
249
  }
235
250
  if (filepos >= info->state->data_file_length)
236
251
  {
 
252
    DBUG_PRINT("test",("filepos: %ld (%ld)  records: %ld  del: %ld",
 
253
                       (long) filepos/share->base.reclength, (long) filepos,
 
254
                       (long) info->state->records, (long) info->state->del));
237
255
    fast_mi_writeinfo(info);
238
 
    return(my_errno=HA_ERR_END_OF_FILE);
 
256
    DBUG_RETURN(my_errno=HA_ERR_END_OF_FILE);
239
257
  }
240
258
  info->lastpos= filepos;
241
259
  info->nextpos= filepos+share->base.pack_reclength;
249
267
      else
250
268
        error=my_errno;
251
269
    }
252
 
    return(error);
 
270
    DBUG_RETURN(error);
253
271
  }
254
272
 
255
273
        /* Read record with cacheing */
256
 
  error=my_b_read(&info->rec_cache,(unsigned char*) buf,share->base.reclength);
 
274
  error=my_b_read(&info->rec_cache,(uchar*) buf,share->base.reclength);
257
275
  if (info->s->base.pack_reclength != info->s->base.reclength && !error)
258
276
  {
259
277
    char tmp[8];                                /* Skill fill bytes */
260
 
    error=my_b_read(&info->rec_cache,(unsigned char*) tmp,
 
278
    error=my_b_read(&info->rec_cache,(uchar*) tmp,
261
279
                    info->s->base.pack_reclength - info->s->base.reclength);
262
280
  }
263
281
  if (locked)
264
 
    _mi_writeinfo(info,0);              /* Unlock keyfile */
 
282
    VOID(_mi_writeinfo(info,0));                /* Unlock keyfile */
265
283
  if (!error)
266
284
  {
267
285
    if (!buf[0])
268
286
    {                                           /* Record is removed */
269
 
      return(my_errno=HA_ERR_RECORD_DELETED);
 
287
      DBUG_RETURN(my_errno=HA_ERR_RECORD_DELETED);
270
288
    }
271
289
                                                /* Found and may be updated */
272
290
    info->update|= HA_STATE_AKTIV | HA_STATE_KEY_CHANGED;
273
 
    return(0);
 
291
    DBUG_RETURN(0);
274
292
  }
275
293
  /* my_errno should be set if rec_cache.error == -1 */
276
294
  if (info->rec_cache.error != -1 || my_errno == 0)
277
295
    my_errno=HA_ERR_WRONG_IN_RECORD;
278
 
  return(my_errno);                     /* Something wrong (EOF?) */
 
296
  DBUG_RETURN(my_errno);                        /* Something wrong (EOF?) */
279
297
}