1 | /* Copyright (c) 2000-2002, 2005-2007 MySQL AB |
2 | Use is subject to license terms |
3 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by |
6 | the Free Software Foundation; version 2 of the License. |
7 | |
8 | This program is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | GNU General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU General Public License |
14 | along with this program; if not, write to the Free Software |
15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ |
16 | |
17 | /* Scan through all rows */ |
18 | |
19 | #include "heapdef.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 | |
28 | int heap_scan_init(register HP_INFO *info) |
29 | { |
30 | DBUG_ENTER("heap_scan_init" ); |
31 | info->lastinx= -1; |
32 | info->current_record= (ulong) ~0L; /* No current record */ |
33 | info->update=0; |
34 | info->next_block=0; |
35 | info->key_version= info->s->key_version; |
36 | info->file_version= info->s->file_version; |
37 | DBUG_RETURN(0); |
38 | } |
39 | |
40 | int heap_scan(register HP_INFO *info, uchar *record) |
41 | { |
42 | HP_SHARE *share=info->s; |
43 | ulong pos; |
44 | DBUG_ENTER("heap_scan" ); |
45 | |
46 | pos= ++info->current_record; |
47 | if (pos < info->next_block) |
48 | { |
49 | info->current_ptr+=share->block.recbuffer; |
50 | } |
51 | else |
52 | { |
53 | info->next_block+=share->block.records_in_block; |
54 | if (info->next_block >= share->records+share->deleted) |
55 | { |
56 | info->next_block= share->records+share->deleted; |
57 | if (pos >= info->next_block) |
58 | { |
59 | info->update= 0; |
60 | DBUG_RETURN(my_errno= HA_ERR_END_OF_FILE); |
61 | } |
62 | } |
63 | hp_find_record(info, pos); |
64 | } |
65 | if (!info->current_ptr[share->visible]) |
66 | { |
67 | DBUG_PRINT("warning" ,("Found deleted record" )); |
68 | info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND; |
69 | DBUG_RETURN(my_errno=HA_ERR_RECORD_DELETED); |
70 | } |
71 | info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND | HA_STATE_AKTIV; |
72 | memcpy(record,info->current_ptr,(size_t) share->reclength); |
73 | info->current_hash_ptr=0; /* Can't use read_next */ |
74 | DBUG_RETURN(0); |
75 | } /* heap_scan */ |
76 | |