Drizzled Public API Documentation

mi_rnext.cc
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #include "myisam_priv.h"
17 
18 using namespace drizzled;
19 
20  /*
21  Read next row with the same key as previous read
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(MI_INFO *info, unsigned char *buf, int inx)
28 {
29  int error,changed;
30  uint32_t flag;
31 
32  if ((inx = _mi_check_index(info,inx)) < 0)
33  return(errno);
34  flag=SEARCH_BIGGER; /* Read next */
35  if (info->lastpos == HA_OFFSET_ERROR && info->update & HA_STATE_PREV_FOUND)
36  flag=0; /* Read first */
37 
38  if (fast_mi_readinfo(info))
39  return(errno);
40  changed=_mi_test_if_changed(info);
41  if (!flag)
42  {
43  switch(info->s->keyinfo[inx].key_alg){
44  case HA_KEY_ALG_BTREE:
45  default:
46  error=_mi_search_first(info,info->s->keyinfo+inx,
47  info->s->state.key_root[inx]);
48  break;
49  }
50  }
51  else
52  {
53  switch (info->s->keyinfo[inx].key_alg) {
54  case HA_KEY_ALG_BTREE:
55  default:
56  if (!changed)
57  error= _mi_search_next(info,info->s->keyinfo+inx,info->lastkey,
58  info->lastkey_length,flag,
59  info->s->state.key_root[inx]);
60  else
61  error= _mi_search(info,info->s->keyinfo+inx,info->lastkey,
62  USE_WHOLE_KEY,flag, info->s->state.key_root[inx]);
63  }
64  }
65 
66  if (!error)
67  {
68  int res= 0;
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  info->lastpos= HA_OFFSET_ERROR;
85  return(errno= HA_ERR_END_OF_FILE);
86  }
87  }
88 
89  /* Don't clear if database-changed */
90  info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
91  info->update|= HA_STATE_NEXT_FOUND;
92 
93  if (error)
94  {
95  if (errno == HA_ERR_KEY_NOT_FOUND)
96  errno=HA_ERR_END_OF_FILE;
97  }
98  else if (!buf)
99  {
100  return(info->lastpos==HA_OFFSET_ERROR ? errno : 0);
101  }
102  else if (!(*info->read_record)(info,info->lastpos,buf))
103  {
104  info->update|= HA_STATE_AKTIV; /* Record is read */
105  return(0);
106  }
107  return(errno);
108 } /* mi_rnext */