Drizzled Public API Documentation

hp_rnext.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 next record with the same key */
00024 
00025 int heap_rnext(HP_INFO *info, unsigned char *record)
00026 {
00027   unsigned char *pos;
00028   HP_SHARE *share=info->getShare();
00029   HP_KEYDEF *keyinfo;
00030 
00031   if (info->lastinx < 0)
00032     return(errno=HA_ERR_WRONG_INDEX);
00033 
00034   keyinfo = share->keydef + info->lastinx;
00035   {
00036     if (info->current_hash_ptr)
00037       pos= hp_search_next(info, keyinfo, &info->lastkey[0],
00038          info->current_hash_ptr);
00039     else
00040     {
00041       if (!info->current_ptr && (info->update & HA_STATE_NEXT_FOUND))
00042       {
00043   pos=0;          /* Read next after last */
00044   errno=HA_ERR_KEY_NOT_FOUND;
00045       }
00046       else if (!info->current_ptr)    /* Deleted or first call */
00047   pos= hp_search(info, keyinfo, &info->lastkey[0], 0);
00048       else
00049   pos= hp_search(info, keyinfo, &info->lastkey[0], 1);
00050     }
00051   }
00052   if (!pos)
00053   {
00054     info->update=HA_STATE_NEXT_FOUND;   /* For heap_rprev */
00055     if (errno == HA_ERR_KEY_NOT_FOUND)
00056       errno=HA_ERR_END_OF_FILE;
00057     return(errno);
00058   }
00059   hp_extract_record(share, record, pos);
00060   info->update=HA_STATE_AKTIV | HA_STATE_NEXT_FOUND;
00061   return(0);
00062 }