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