MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mi_rsame.c
1 /* Copyright (c) 2000, 2001, 2005-2007 MySQL AB, 2009 Sun Microsystems, Inc.
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 St, Fifth Floor, Boston, MA 02110-1301 USA */
16 
17 #include "myisamdef.h"
18 
19  /*
20  ** Find current row with read on position or read on key
21  ** If inx >= 0 find record using key
22  ** Return values:
23  ** 0 = Ok.
24  ** HA_ERR_KEY_NOT_FOUND = Row is deleted
25  ** HA_ERR_END_OF_FILE = End of file
26  */
27 
28 
29 int mi_rsame(MI_INFO *info, uchar *record, int inx)
30 {
31  DBUG_ENTER("mi_rsame");
32 
33  if (inx != -1 && ! mi_is_key_active(info->s->state.key_map, inx))
34  {
35  DBUG_RETURN(my_errno=HA_ERR_WRONG_INDEX);
36  }
37  if (info->lastpos == HA_OFFSET_ERROR || info->update & HA_STATE_DELETED)
38  {
39  DBUG_RETURN(my_errno=HA_ERR_KEY_NOT_FOUND); /* No current record */
40  }
41  info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
42 
43  /* Read row from data file */
44  if (fast_mi_readinfo(info))
45  DBUG_RETURN(my_errno);
46 
47  if (inx >= 0)
48  {
49  info->lastinx=inx;
50  info->lastkey_length=_mi_make_key(info,(uint) inx,info->lastkey,record,
51  info->lastpos);
52  if (info->s->concurrent_insert)
53  mysql_rwlock_rdlock(&info->s->key_root_lock[inx]);
54  (void) _mi_search(info,info->s->keyinfo+inx,info->lastkey, USE_WHOLE_KEY,
55  SEARCH_SAME,
56  info->s->state.key_root[inx]);
57  if (info->s->concurrent_insert)
58  mysql_rwlock_unlock(&info->s->key_root_lock[inx]);
59  }
60 
61  if (!(*info->read_record)(info,info->lastpos,record))
62  DBUG_RETURN(0);
63  if (my_errno == HA_ERR_RECORD_DELETED)
64  my_errno=HA_ERR_KEY_NOT_FOUND;
65  DBUG_RETURN(my_errno);
66 } /* mi_rsame */