~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2004 MySQL 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; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
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 */
15
16
#include "myisamdef.h"
17
18
	/*
19
	   Read next row with the same key as previous read
20
	   One may have done a write, update or delete of the previous row.
21
	   NOTE! Even if one changes the previous row, the next read is done
22
	   based on the position of the last used key!
23
	*/
24
25
int mi_rnext(MI_INFO *info, uchar *buf, int inx)
26
{
27
  int error,changed;
28
  uint flag;
29
  int res= 0;
30
31
  if ((inx = _mi_check_index(info,inx)) < 0)
51.1.109 by Jay Pipes
Removed/replaced DBUG
32
    return(my_errno);
1 by brian
clean slate
33
  flag=SEARCH_BIGGER;				/* Read next */
34
  if (info->lastpos == HA_OFFSET_ERROR && info->update & HA_STATE_PREV_FOUND)
35
    flag=0;					/* Read first */
36
37
  if (fast_mi_readinfo(info))
51.1.109 by Jay Pipes
Removed/replaced DBUG
38
    return(my_errno);
1 by brian
clean slate
39
  if (info->s->concurrent_insert)
40
    rw_rdlock(&info->s->key_root_lock[inx]);
41
  changed=_mi_test_if_changed(info);
42
  if (!flag)
43
  {
44
    switch(info->s->keyinfo[inx].key_alg){
45
    case HA_KEY_ALG_BTREE:
46
    default:
47
      error=_mi_search_first(info,info->s->keyinfo+inx,
48
			   info->s->state.key_root[inx]);
49
      break;
50
    }
51
  }
52
  else
53
  {
54
    switch (info->s->keyinfo[inx].key_alg) {
55
    case HA_KEY_ALG_BTREE:
56
    default:
57
      if (!changed)
58
	error= _mi_search_next(info,info->s->keyinfo+inx,info->lastkey,
59
			       info->lastkey_length,flag,
60
			       info->s->state.key_root[inx]);
61
      else
62
	error= _mi_search(info,info->s->keyinfo+inx,info->lastkey,
63
			  USE_WHOLE_KEY,flag, info->s->state.key_root[inx]);
64
    }
65
  }
66
67
  if (!error)
68
  {
69
    while ((info->s->concurrent_insert &&
70
            info->lastpos >= info->state->data_file_length) ||
71
           (info->index_cond_func &&
72
           !(res= mi_check_index_cond(info, inx, buf))))
73
    {
74
      /* Skip rows inserted by other threads since we got a lock */
75
      if  ((error=_mi_search_next(info,info->s->keyinfo+inx,
76
                                  info->lastkey,
77
                                  info->lastkey_length,
78
                                  SEARCH_BIGGER,
79
                                  info->s->state.key_root[inx])))
80
        break;
81
    }
82
    if (!error && res == 2)
83
    {
84
      if (info->s->concurrent_insert)
85
        rw_unlock(&info->s->key_root_lock[inx]);
86
      info->lastpos= HA_OFFSET_ERROR;
51.1.109 by Jay Pipes
Removed/replaced DBUG
87
      return(my_errno= HA_ERR_END_OF_FILE);
1 by brian
clean slate
88
    }
89
  }
90
  
91
  if (info->s->concurrent_insert)
92
    rw_unlock(&info->s->key_root_lock[inx]);
93
94
	/* Don't clear if database-changed */
95
  info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
96
  info->update|= HA_STATE_NEXT_FOUND;
97
98
  if (error)
99
  {
100
    if (my_errno == HA_ERR_KEY_NOT_FOUND)
101
      my_errno=HA_ERR_END_OF_FILE;
102
  }
103
  else if (!buf)
104
  {
51.1.109 by Jay Pipes
Removed/replaced DBUG
105
    return(info->lastpos==HA_OFFSET_ERROR ? my_errno : 0);
1 by brian
clean slate
106
  }
107
  else if (!(*info->read_record)(info,info->lastpos,buf))
108
  {
109
    info->update|= HA_STATE_AKTIV;		/* Record is read */
51.1.109 by Jay Pipes
Removed/replaced DBUG
110
    return(0);
1 by brian
clean slate
111
  }
51.1.109 by Jay Pipes
Removed/replaced DBUG
112
  return(my_errno);
1 by brian
clean slate
113
} /* mi_rnext */