drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
hp_rrnd.cc
1/* Copyright (C) 2000-2002, 2004, 2006 MySQL AB
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
16/* Read a record from a random position */
17
18#include "heap_priv.h"
19#include <drizzled/error_t.h>
20
21/*
22 Returns one of following values:
23 0 = Ok.
24 HA_ERR_RECORD_DELETED = Record is deleted.
25 HA_ERR_END_OF_FILE = EOF.
26*/
27
28int heap_rrnd(HP_INFO *info, unsigned char *record, unsigned char *pos)
29{
30 HP_SHARE *share=info->getShare();
31
32 info->lastinx= -1;
33 if (!(info->current_ptr= pos))
34 {
35 info->update= 0;
36 return(errno= drizzled::HA_ERR_END_OF_FILE);
37 }
38 if (get_chunk_status(&share->recordspace, info->current_ptr) != CHUNK_STATUS_ACTIVE)
39 {
40 /* treat deleted and linked chunks as deleted */
41 info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
42 return(errno= drizzled::HA_ERR_RECORD_DELETED);
43 }
44 info->update=HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND | HA_STATE_AKTIV;
45 hp_extract_record(share, record, info->current_ptr);
46 info->current_hash_ptr=0; /* Can't use rnext */
47 return(0);
48} /* heap_rrnd */
49
50
51#ifdef WANT_OLD_HEAP_VERSION
52
53/*
54 If pos == -1 then read next record
55 Returns one of following values:
56 0 = Ok.
57 HA_ERR_RECORD_DELETED = Record is deleted.
58 HA_ERR_END_OF_FILE = EOF.
59*/
60
61int heap_rrnd_old(HP_INFO *info, unsigned char *record, uint32_t pos)
62{
63 HP_SHARE *share=info->s;
64asdfasdf;
65 info->lastinx= -1;
66 if (pos == (uint32_t) -1)
67 {
68 pos= ++info->current_record;
69 if (pos % share->block.records_in_block && /* Quick next record */
70 pos < share->used_chunk_count+share->deleted_chunk_count &&
71 (info->update & HA_STATE_PREV_FOUND))
72 {
73 info->current_ptr+=share->block.recbufferlen;
74 goto end;
75 }
76 }
77 else
78 info->current_record=pos;
79
80 if (pos >= share->used_chunk_count+share->deleted_chunk_count)
81 {
82 info->update= 0;
83 return(errno= HA_ERR_END_OF_FILE);
84 }
85
86 /* Find record number pos */
87 hp_find_record(info, pos);
88
89end:
90 if (!info->current_ptr[share->reclength])
91 {
92 info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
93 return(errno=HA_ERR_RECORD_DELETED);
94 }
95 info->update=HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND | HA_STATE_AKTIV;
96 memcpy(record,info->current_ptr,(size_t) share->reclength);
97 info->current_hash_ptr=0; /* Can't use rnext */
98 return(0);
99} /* heap_rrnd */
100
101#endif /* WANT_OLD_HEAP_VERSION */