Drizzled Public API Documentation

hp_rprev.cc
00001 /* Copyright (C) 2000-2002 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 #include "heap_priv.h"
00017 
00018 #include <string.h>
00019 #include <drizzled/error_t.h>
00020 
00021 using namespace drizzled;
00022 
00023   /* Read prev record for key */
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;          /* Read next after last */
00044       errno=HA_ERR_KEY_NOT_FOUND;
00045     }
00046   }
00047   if (!pos)
00048   {
00049     info->update=HA_STATE_PREV_FOUND;   /* For heap_rprev */
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 }