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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "heap_priv.h"
18
18
#include <string.h>
20
using namespace drizzled;
22
20
/* Read prev record for key */
25
23
int heap_rprev(HP_INFO *info, unsigned char *record)
27
25
unsigned char *pos;
28
HP_SHARE *share=info->getShare();
26
HP_SHARE *share=info->s;
29
27
HP_KEYDEF *keyinfo;
31
29
if (info->lastinx < 0)
32
return(errno=HA_ERR_WRONG_INDEX);
30
return(my_errno=HA_ERR_WRONG_INDEX);
33
31
keyinfo = share->keydef + info->lastinx;
32
if (keyinfo->algorithm == HA_KEY_ALG_BTREE)
34
heap_rb_param custom_arg;
37
pos = tree_search_next(&keyinfo->rb_tree, &info->last_pos,
38
offsetof(TREE_ELEMENT, right),
39
offsetof(TREE_ELEMENT, left));
42
custom_arg.keyseg = keyinfo->seg;
43
custom_arg.key_length = keyinfo->length;
44
custom_arg.search_flag = SEARCH_SAME;
45
pos = tree_search_key(&keyinfo->rb_tree, info->lastkey, info->parents,
46
&info->last_pos, info->last_find_flag, &custom_arg);
50
memcpy(&pos, pos + (*keyinfo->get_key_length)(keyinfo, pos),
51
sizeof(unsigned char*));
52
info->current_ptr = pos;
56
my_errno = HA_ERR_KEY_NOT_FOUND;
35
61
if (info->current_ptr || (info->update & HA_STATE_NEXT_FOUND))
37
63
if ((info->update & HA_STATE_DELETED))
38
pos= hp_search(info, share->keydef + info->lastinx, &info->lastkey[0], 3);
64
pos= hp_search(info, share->keydef + info->lastinx, info->lastkey, 3);
40
pos= hp_search(info, share->keydef + info->lastinx, &info->lastkey[0], 2);
66
pos= hp_search(info, share->keydef + info->lastinx, info->lastkey, 2);
44
70
pos=0; /* Read next after last */
45
errno=HA_ERR_KEY_NOT_FOUND;
71
my_errno=HA_ERR_KEY_NOT_FOUND;
50
76
info->update=HA_STATE_PREV_FOUND; /* For heap_rprev */
51
if (errno == HA_ERR_KEY_NOT_FOUND)
52
errno=HA_ERR_END_OF_FILE;
77
if (my_errno == HA_ERR_KEY_NOT_FOUND)
78
my_errno=HA_ERR_END_OF_FILE;
55
81
hp_extract_record(share, record, pos);
56
82
info->update=HA_STATE_AKTIV | HA_STATE_PREV_FOUND;