1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
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.
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.
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 */
17
#include "myisamdef.h"
20
Read next row with the same key as previous read, but abort if
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!
27
int mi_rnext_same(MI_INFO *info, byte *buf)
30
uint inx,flag,not_used;
32
DBUG_ENTER("mi_rnext_same");
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);
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]);
46
if ((error=_mi_search_next(info,keyinfo,info->lastkey,
47
info->lastkey_length,flag,
48
info->s->state.key_root[inx])))
50
if (_mi_key_cmp(keyinfo->seg,info->lastkey2,info->lastkey,
51
info->last_rkey_length, SEARCH_FIND, ¬_used))
54
my_errno=HA_ERR_END_OF_FILE;
55
info->lastpos= HA_OFFSET_ERROR;
58
/* Skip rows that are inserted by other threads since we got a lock */
59
if (info->lastpos < info->state->data_file_length)
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;
70
if (my_errno == HA_ERR_KEY_NOT_FOUND)
71
my_errno=HA_ERR_END_OF_FILE;
73
else if (!(*info->read_record)(info,info->lastpos,buf))
75
info->update|= HA_STATE_AKTIV; /* Record is read */
78
DBUG_RETURN(my_errno);