~drizzle-trunk/drizzle/development

1 by brian
clean slate
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
/* Read a record from a random position */
17
18
#include "heapdef.h"
19
20
/*
21
	   Returns one of following values:
22
	   0 = Ok.
23
	   HA_ERR_RECORD_DELETED = Record is deleted.
24
	   HA_ERR_END_OF_FILE = EOF.
25
*/
26
27
int heap_rrnd(register HP_INFO *info, uchar *record, uchar *pos)
28
{
29
  HP_SHARE *share=info->s;
30
31
  info->lastinx= -1;
32
  if (!(info->current_ptr= pos))
33
  {
34
    info->update= 0;
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
35
    return(my_errno= HA_ERR_END_OF_FILE);
1 by brian
clean slate
36
  }
37
  if (!info->current_ptr[share->reclength])
38
  {
39
    info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
40
    return(my_errno=HA_ERR_RECORD_DELETED);
1 by brian
clean slate
41
  }
42
  info->update=HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND | HA_STATE_AKTIV;
43
  memcpy(record,info->current_ptr,(size_t) share->reclength);
44
  info->current_hash_ptr=0;			/* Can't use rnext */
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
45
  return(0);
1 by brian
clean slate
46
} /* heap_rrnd */
47
48
49
#ifdef WANT_OLD_HEAP_VERSION
50
51
/*
52
	   If pos == -1 then read next record
53
	   Returns one of following values:
54
	   0 = Ok.
55
	   HA_ERR_RECORD_DELETED = Record is deleted.
56
	   HA_ERR_END_OF_FILE = EOF.
57
*/
58
59
int heap_rrnd_old(register HP_INFO *info, uchar *record, ulong pos)
60
{
61
  HP_SHARE *share=info->s;
62
63
  info->lastinx= -1;
64
  if (pos == (ulong) -1)
65
  {
66
    pos= ++info->current_record;
67
    if (pos % share->block.records_in_block &&	/* Quick next record */
68
	pos < share->records+share->deleted &&
69
	(info->update & HA_STATE_PREV_FOUND))
70
    {
71
      info->current_ptr+=share->block.recbuffer;
72
      goto end;
73
    }
74
  }
75
  else
76
    info->current_record=pos;
77
78
  if (pos >= share->records+share->deleted)
79
  {
80
    info->update= 0;
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
81
    return(my_errno= HA_ERR_END_OF_FILE);
1 by brian
clean slate
82
  }
83
84
	/* Find record number pos */
85
  hp_find_record(info, pos);
86
87
end:
88
  if (!info->current_ptr[share->reclength])
89
  {
90
    info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
91
    return(my_errno=HA_ERR_RECORD_DELETED);
1 by brian
clean slate
92
  }
93
  info->update=HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND | HA_STATE_AKTIV;
94
  memcpy(record,info->current_ptr,(size_t) share->reclength);
95
  info->current_hash_ptr=0;			/* Can't use rnext */
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
96
  return(0);
1 by brian
clean slate
97
} /* heap_rrnd */
98
99
#endif /* WANT_OLD_HEAP_VERSION */