mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / heap / hp_rrnd.c
blob1afdd10f104b24bb20a21d735a90eae0cdf168bd
1 /* Copyright (c) 2000-2002, 2004-2007 MySQL AB
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.
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.
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 Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 /* Read a record from a random position */
18 #include "heapdef.h"
21 Returns one of following values:
22 0 = Ok.
23 HA_ERR_RECORD_DELETED = Record is deleted.
24 HA_ERR_END_OF_FILE = EOF.
27 int heap_rrnd(register HP_INFO *info, uchar *record, uchar *pos)
29 HP_SHARE *share=info->s;
30 DBUG_ENTER("heap_rrnd");
31 DBUG_PRINT("enter",("info: 0x%lx pos: %lx",(long) info, (long) pos));
33 info->lastinx= -1;
34 if (!(info->current_ptr= pos))
36 info->update= 0;
37 DBUG_RETURN(my_errno= HA_ERR_END_OF_FILE);
39 if (!info->current_ptr[share->reclength])
41 info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
42 DBUG_RETURN(my_errno=HA_ERR_RECORD_DELETED);
44 info->update=HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND | HA_STATE_AKTIV;
45 memcpy(record,info->current_ptr,(size_t) share->reclength);
46 DBUG_PRINT("exit", ("found record at 0x%lx", (long) info->current_ptr));
47 info->current_hash_ptr=0; /* Can't use rnext */
48 DBUG_RETURN(0);
49 } /* heap_rrnd */
52 #ifdef WANT_OLD_HEAP_VERSION
55 If pos == -1 then read next record
56 Returns one of following values:
57 0 = Ok.
58 HA_ERR_RECORD_DELETED = Record is deleted.
59 HA_ERR_END_OF_FILE = EOF.
62 int heap_rrnd_old(register HP_INFO *info, uchar *record, ulong pos)
64 HP_SHARE *share=info->s;
65 DBUG_ENTER("heap_rrnd");
66 DBUG_PRINT("enter",("info: 0x%lx pos: %ld",info,pos));
68 info->lastinx= -1;
69 if (pos == (ulong) -1)
71 pos= ++info->current_record;
72 if (pos % share->block.records_in_block && /* Quick next record */
73 pos < share->records+share->deleted &&
74 (info->update & HA_STATE_PREV_FOUND))
76 info->current_ptr+=share->block.recbuffer;
77 goto end;
80 else
81 info->current_record=pos;
83 if (pos >= share->records+share->deleted)
85 info->update= 0;
86 DBUG_RETURN(my_errno= HA_ERR_END_OF_FILE);
89 /* Find record number pos */
90 hp_find_record(info, pos);
92 end:
93 if (!info->current_ptr[share->reclength])
95 info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
96 DBUG_RETURN(my_errno=HA_ERR_RECORD_DELETED);
98 info->update=HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND | HA_STATE_AKTIV;
99 memcpy(record,info->current_ptr,(size_t) share->reclength);
100 DBUG_PRINT("exit",("found record at 0x%lx",info->current_ptr));
101 info->current_hash_ptr=0; /* Can't use rnext */
102 DBUG_RETURN(0);
103 } /* heap_rrnd */
105 #endif /* WANT_OLD_HEAP_VERSION */