~mysql/mysql-server/mysql-6.0

« back to all changes in this revision

Viewing changes to myisam/mi_rnext_same.c

  • Committer: bk at mysql
  • Date: 2000-07-31 19:29:14 UTC
  • Revision ID: sp1r-bk@work.mysql.com-20000731192914-08846
Import changeset

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
 
2
   
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; either version 2 of the License, or
 
6
   (at your option) any later version.
 
7
   
 
8
   This program is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
   GNU General Public License for more details.
 
12
   
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program; if not, write to the Free Software
 
15
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
16
 
 
17
#include "myisamdef.h"
 
18
 
 
19
        /*
 
20
           Read next row with the same key as previous read, but abort if
 
21
           the key changes.
 
22
           One may have done a write, update or delete of the previous row.
 
23
           NOTE! Even if one changes the previous row, the next read is done
 
24
           based on the position of the last used key!
 
25
        */
 
26
 
 
27
int mi_rnext_same(MI_INFO *info, byte *buf)
 
28
{
 
29
  int error;
 
30
  uint inx,flag,not_used;
 
31
  MI_KEYDEF *keyinfo;
 
32
  DBUG_ENTER("mi_rnext_same");
 
33
 
 
34
  if ((int) (inx=info->lastinx) < 0 || info->lastpos == HA_OFFSET_ERROR)
 
35
    DBUG_RETURN(my_errno=HA_ERR_WRONG_INDEX);
 
36
  keyinfo=info->s->keyinfo+inx;
 
37
  flag=SEARCH_BIGGER;                           /* Read next */
 
38
  if (_mi_readinfo(info,F_RDLCK,1))
 
39
    DBUG_RETURN(my_errno);
 
40
 
 
41
  memcpy(info->lastkey2,info->lastkey,info->last_rkey_length);
 
42
  if (info->s->concurrent_insert)
 
43
    rw_rdlock(&info->s->key_root_lock[inx]);
 
44
  for (;;)
 
45
  {
 
46
    if ((error=_mi_search_next(info,keyinfo,info->lastkey,
 
47
                               info->lastkey_length,flag,
 
48
                               info->s->state.key_root[inx])))
 
49
      break;
 
50
    if (_mi_key_cmp(keyinfo->seg,info->lastkey2,info->lastkey,
 
51
                    info->last_rkey_length, SEARCH_FIND, &not_used))
 
52
    {
 
53
      error=1;
 
54
      my_errno=HA_ERR_END_OF_FILE;
 
55
      info->lastpos= HA_OFFSET_ERROR;
 
56
      break;
 
57
    }
 
58
    /* Skip rows that are inserted by other threads since we got a lock */
 
59
    if (info->lastpos < info->state->data_file_length)
 
60
      break;
 
61
  }
 
62
  if (info->s->concurrent_insert)
 
63
    rw_unlock(&info->s->key_root_lock[inx]);
 
64
        /* Don't clear if database-changed */
 
65
  info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
 
66
  info->update|= HA_STATE_NEXT_FOUND;
 
67
 
 
68
  if (error)
 
69
  {
 
70
    if (my_errno == HA_ERR_KEY_NOT_FOUND)
 
71
      my_errno=HA_ERR_END_OF_FILE;
 
72
  }
 
73
  else if (!(*info->read_record)(info,info->lastpos,buf))
 
74
  {
 
75
    info->update|= HA_STATE_AKTIV;              /* Record is read */
 
76
    DBUG_RETURN(0);
 
77
  }
 
78
  DBUG_RETURN(my_errno);
 
79
} /* mi_rnext */