Drizzled Public API Documentation

hp_rrnd.cc

00001 /* Copyright (C) 2000-2002, 2004, 2006 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 /* Read a record from a random position */
00017 
00018 #include "heap_priv.h"
00019 
00020 /*
00021      Returns one of following values:
00022      0 = Ok.
00023      HA_ERR_RECORD_DELETED = Record is deleted.
00024      HA_ERR_END_OF_FILE = EOF.
00025 */
00026 
00027 int heap_rrnd(register HP_INFO *info, unsigned char *record, unsigned char *pos)
00028 {
00029   HP_SHARE *share=info->getShare();
00030 
00031   info->lastinx= -1;
00032   if (!(info->current_ptr= pos))
00033   {
00034     info->update= 0;
00035     return(errno=  drizzled::HA_ERR_END_OF_FILE);
00036   }
00037   if (get_chunk_status(&share->recordspace, info->current_ptr) != CHUNK_STATUS_ACTIVE)
00038   {
00039     /* treat deleted and linked chunks as deleted */
00040     info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
00041     return(errno= drizzled::HA_ERR_RECORD_DELETED);
00042   }
00043   info->update=HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND | HA_STATE_AKTIV;
00044   hp_extract_record(share, record, info->current_ptr);
00045   info->current_hash_ptr=0;     /* Can't use rnext */
00046   return(0);
00047 } /* heap_rrnd */
00048 
00049 
00050 #ifdef WANT_OLD_HEAP_VERSION
00051 
00052 /*
00053      If pos == -1 then read next record
00054      Returns one of following values:
00055      0 = Ok.
00056      HA_ERR_RECORD_DELETED = Record is deleted.
00057      HA_ERR_END_OF_FILE = EOF.
00058 */
00059 
00060 int heap_rrnd_old(register HP_INFO *info, unsigned char *record, uint32_t pos)
00061 {
00062   HP_SHARE *share=info->s;
00063 asdfasdf;
00064   info->lastinx= -1;
00065   if (pos == (uint32_t) -1)
00066   {
00067     pos= ++info->current_record;
00068     if (pos % share->block.records_in_block &&  /* Quick next record */
00069       pos < share->used_chunk_count+share->deleted_chunk_count &&
00070       (info->update & HA_STATE_PREV_FOUND))
00071     {
00072       info->current_ptr+=share->block.recbufferlen;
00073       goto end;
00074     }
00075   }
00076   else
00077     info->current_record=pos;
00078 
00079   if (pos >= share->used_chunk_count+share->deleted_chunk_count)
00080   {
00081     info->update= 0;
00082     return(errno= HA_ERR_END_OF_FILE);
00083   }
00084 
00085   /* Find record number pos */
00086   hp_find_record(info, pos);
00087 
00088 end:
00089   if (!info->current_ptr[share->reclength])
00090   {
00091     info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
00092     return(errno=HA_ERR_RECORD_DELETED);
00093   }
00094   info->update=HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND | HA_STATE_AKTIV;
00095   memcpy(record,info->current_ptr,(size_t) share->reclength);
00096   info->current_hash_ptr=0;     /* Can't use rnext */
00097   return(0);
00098 } /* heap_rrnd */
00099 
00100 #endif /* WANT_OLD_HEAP_VERSION */