00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "heap_priv.h"
00017
00018 #include <string.h>
00019 #include <drizzled/error_t.h>
00020
00021 using namespace drizzled;
00022
00023
00024
00025
00026 int heap_rprev(HP_INFO *info, unsigned char *record)
00027 {
00028 unsigned char *pos;
00029 HP_SHARE *share=info->getShare();
00030
00031 if (info->lastinx < 0)
00032 return(errno=HA_ERR_WRONG_INDEX);
00033 {
00034 if (info->current_ptr || (info->update & HA_STATE_NEXT_FOUND))
00035 {
00036 if ((info->update & HA_STATE_DELETED))
00037 pos= hp_search(info, share->keydef + info->lastinx, &info->lastkey[0], 3);
00038 else
00039 pos= hp_search(info, share->keydef + info->lastinx, &info->lastkey[0], 2);
00040 }
00041 else
00042 {
00043 pos=0;
00044 errno=HA_ERR_KEY_NOT_FOUND;
00045 }
00046 }
00047 if (!pos)
00048 {
00049 info->update=HA_STATE_PREV_FOUND;
00050 if (errno == HA_ERR_KEY_NOT_FOUND)
00051 errno=HA_ERR_END_OF_FILE;
00052 return(errno);
00053 }
00054 hp_extract_record(share, record, pos);
00055 info->update=HA_STATE_AKTIV | HA_STATE_PREV_FOUND;
00056 return(0);
00057 }