~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_statrec.cc

  • Committer: Daniel Nichter
  • Date: 2011-10-23 16:01:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2448.
  • Revision ID: daniel@percona.com-20111023160137-7ac3blgz8z4tf8za
Add Administration Getting Started and Logging.  Capitalize SQL clause keywords.

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
16
        /* Functions to handle fixed-length-records */
17
17
 
18
 
#include "myisamdef.h"
 
18
#include "myisam_priv.h"
 
19
 
 
20
using namespace drizzled;
19
21
 
20
22
int _mi_write_static_record(MI_INFO *info, const unsigned char *record)
21
23
{
23
25
  if (info->s->state.dellink != HA_OFFSET_ERROR &&
24
26
      !info->append_insert_at_end)
25
27
  {
26
 
    my_off_t filepos=info->s->state.dellink;
 
28
    internal::my_off_t filepos=info->s->state.dellink;
27
29
    info->rec_cache.seek_not_done=1;            /* We have done a seek */
28
30
    if (info->s->file_read(info, &temp[0],info->s->base.rec_reflength,
29
31
                info->s->state.dellink+1,
42
44
    if (info->state->data_file_length > info->s->base.max_data_file_length-
43
45
        info->s->base.pack_reclength)
44
46
    {
45
 
      my_errno=HA_ERR_RECORD_FILE_FULL;
 
47
      errno=HA_ERR_RECORD_FILE_FULL;
46
48
      return(2);
47
49
    }
48
50
    if (info->opt_flag & WRITE_CACHE_USED)
49
51
    {                           /* Cash in use */
50
 
      if (my_b_write(&info->rec_cache, record,
51
 
                     info->s->base.reclength))
 
52
      if (info->rec_cache.write(record, info->s->base.reclength))
52
53
        goto err;
53
54
      if (info->s->base.pack_reclength != info->s->base.reclength)
54
55
      {
55
56
        uint32_t length=info->s->base.pack_reclength - info->s->base.reclength;
56
57
        memset(temp, 0, length);
57
 
        if (my_b_write(&info->rec_cache, temp,length))
 
58
        if (info->rec_cache.write(temp,length))
58
59
          goto err;
59
60
      }
60
61
    }
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, internal::my_off_t pos, const unsigned char *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,
113
114
{
114
115
  if (info->opt_flag & WRITE_CACHE_USED)
115
116
  {
116
 
    if (flush_io_cache(&info->rec_cache))
 
117
    if (info->rec_cache.flush())
117
118
    {
118
119
      return(-1);
119
120
    }
130
131
    if (memcmp(info->rec_buff, old,
131
132
               (uint) info->s->base.reclength))
132
133
    {
133
 
      my_errno=HA_ERR_RECORD_CHANGED;           /* Record have changed */
 
134
      errno=HA_ERR_RECORD_CHANGED;              /* Record have changed */
134
135
      return(1);
135
136
    }
136
137
  }
139
140
 
140
141
 
141
142
int _mi_cmp_static_unique(MI_INFO *info, MI_UNIQUEDEF *def,
142
 
                          const unsigned char *record, my_off_t pos)
 
143
                          const unsigned char *record, internal::my_off_t pos)
143
144
{
144
145
  info->rec_cache.seek_not_done=1;              /* We have done a seek */
145
146
  if (info->s->file_read(info, info->rec_buff, info->s->base.reclength,
155
156
        /*         1 if record is deleted */
156
157
        /*        MY_FILE_ERROR on read-error or locking-error */
157
158
 
158
 
int _mi_read_static_record(register MI_INFO *info, register my_off_t pos,
 
159
int _mi_read_static_record(register MI_INFO *info, register internal::my_off_t pos,
159
160
                           register unsigned char *record)
160
161
{
161
 
  int error;
162
 
 
163
162
  if (pos != HA_OFFSET_ERROR)
164
163
  {
165
164
    if (info->opt_flag & WRITE_CACHE_USED &&
166
165
        info->rec_cache.pos_in_file <= pos &&
167
 
        flush_io_cache(&info->rec_cache))
 
166
        info->rec_cache.flush())
168
167
      return(-1);
169
168
    info->rec_cache.seek_not_done=1;            /* We have done a seek */
170
169
 
171
 
    error=info->s->file_read(info, record, info->s->base.reclength,
172
 
                   pos,MYF(MY_NABP)) != 0;
 
170
    int error= info->s->file_read(info, record, info->s->base.reclength, pos,MYF(MY_NABP)) != 0;
173
171
    fast_mi_writeinfo(info);
174
172
    if (! error)
175
173
    {
176
174
      if (!*record)
177
175
      {
178
 
        my_errno=HA_ERR_RECORD_DELETED;
 
176
        errno=HA_ERR_RECORD_DELETED;
179
177
        return(1);                              /* Record is deleted */
180
178
      }
181
179
      info->update|= HA_STATE_AKTIV;            /* Record is read */
190
188
 
191
189
 
192
190
int _mi_read_rnd_static_record(MI_INFO *info, unsigned char *buf,
193
 
                               register my_off_t filepos,
 
191
                               register internal::my_off_t filepos,
194
192
                               bool skip_deleted_blocks)
195
193
{
196
194
  int locked,error,cache_read;
197
 
  uint32_t cache_length;
198
195
  MYISAM_SHARE *share=info->s;
199
196
 
200
197
  cache_read=0;
201
 
  cache_length=0;
202
198
  if (info->opt_flag & WRITE_CACHE_USED &&
203
199
      (info->rec_cache.pos_in_file <= filepos || skip_deleted_blocks) &&
204
 
      flush_io_cache(&info->rec_cache))
205
 
    return(my_errno);
 
200
      info->rec_cache.flush())
 
201
    return(errno);
206
202
  if (info->opt_flag & READ_CACHE_USED)
207
203
  {                                             /* Cache in use */
208
 
    if (filepos == my_b_tell(&info->rec_cache) &&
 
204
    if (filepos == info->rec_cache.tell() &&
209
205
        (skip_deleted_blocks || !filepos))
210
206
    {
211
207
      cache_read=1;                             /* Read record using cache */
212
 
      cache_length=(uint) (info->rec_cache.read_end - info->rec_cache.read_pos);
213
208
    }
214
209
    else
215
210
      info->rec_cache.seek_not_done=1;          /* Filepos is changed */
220
215
    if (filepos >= info->state->data_file_length)
221
216
    {                                           /* Test if new records */
222
217
      if (_mi_readinfo(info,F_RDLCK,0))
223
 
        return(my_errno);
 
218
        return(errno);
224
219
      locked=1;
225
220
    }
226
221
    else
235
230
  if (filepos >= info->state->data_file_length)
236
231
  {
237
232
    fast_mi_writeinfo(info);
238
 
    return(my_errno=HA_ERR_END_OF_FILE);
 
233
    return(errno=HA_ERR_END_OF_FILE);
239
234
  }
240
235
  info->lastpos= filepos;
241
236
  info->nextpos= filepos+share->base.pack_reclength;
245
240
    if ((error=_mi_read_static_record(info,filepos,buf)))
246
241
    {
247
242
      if (error > 0)
248
 
        error=my_errno=HA_ERR_RECORD_DELETED;
 
243
        error=errno=HA_ERR_RECORD_DELETED;
249
244
      else
250
 
        error=my_errno;
 
245
        error=errno;
251
246
    }
252
247
    return(error);
253
248
  }
254
249
 
255
250
        /* Read record with cacheing */
256
 
  error=my_b_read(&info->rec_cache,(unsigned char*) buf,share->base.reclength);
 
251
  error= info->rec_cache.read(buf, share->base.reclength);
257
252
  if (info->s->base.pack_reclength != info->s->base.reclength && !error)
258
253
  {
259
254
    char tmp[8];                                /* Skill fill bytes */
260
 
    error=my_b_read(&info->rec_cache,(unsigned char*) tmp,
261
 
                    info->s->base.pack_reclength - info->s->base.reclength);
 
255
    error= info->rec_cache.read(tmp, info->s->base.pack_reclength - info->s->base.reclength);
262
256
  }
263
257
  if (locked)
264
258
    _mi_writeinfo(info,0);              /* Unlock keyfile */
266
260
  {
267
261
    if (!buf[0])
268
262
    {                                           /* Record is removed */
269
 
      return(my_errno=HA_ERR_RECORD_DELETED);
 
263
      return(errno=HA_ERR_RECORD_DELETED);
270
264
    }
271
265
                                                /* Found and may be updated */
272
266
    info->update|= HA_STATE_AKTIV | HA_STATE_KEY_CHANGED;
273
267
    return(0);
274
268
  }
275
 
  /* my_errno should be set if rec_cache.error == -1 */
276
 
  if (info->rec_cache.error != -1 || my_errno == 0)
277
 
    my_errno=HA_ERR_WRONG_IN_RECORD;
278
 
  return(my_errno);                     /* Something wrong (EOF?) */
 
269
  /* errno should be set if rec_cache.error == -1 */
 
270
  if (info->rec_cache.error != -1 || errno == 0)
 
271
    errno=HA_ERR_WRONG_IN_RECORD;
 
272
  return(errno);                        /* Something wrong (EOF?) */
279
273
}