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, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
23 
24 #include "myisamdef.h"
25 
26 	/*
27 	** Find current row with read on position or read on key
28 	** If inx >= 0 find record using key
29 	** Return values:
30 	** 0 = Ok.
31 	** HA_ERR_KEY_NOT_FOUND = Row is deleted
32 	** HA_ERR_END_OF_FILE   = End of file
33 	*/
34 
35 
mi_rsame(MI_INFO * info,uchar * record,int inx)36 int mi_rsame(MI_INFO *info, uchar *record, int inx)
37 {
38   DBUG_ENTER("mi_rsame");
39 
40   if (inx != -1 && ! mi_is_key_active(info->s->state.key_map, inx))
41   {
42     DBUG_RETURN(my_errno=HA_ERR_WRONG_INDEX);
43   }
44   if (info->lastpos == HA_OFFSET_ERROR || info->update & HA_STATE_DELETED)
45   {
46     DBUG_RETURN(my_errno=HA_ERR_KEY_NOT_FOUND);	/* No current record */
47   }
48   info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
49 
50   /* Read row from data file */
51   if (fast_mi_readinfo(info))
52     DBUG_RETURN(my_errno);
53 
54   if (inx >= 0)
55   {
56     info->lastinx=inx;
57     info->lastkey_length=_mi_make_key(info,(uint) inx,info->lastkey,record,
58 				      info->lastpos);
59     if (info->s->concurrent_insert)
60       mysql_rwlock_rdlock(&info->s->key_root_lock[inx]);
61     (void) _mi_search(info,info->s->keyinfo+inx,info->lastkey, USE_WHOLE_KEY,
62 		    SEARCH_SAME,
63 		    info->s->state.key_root[inx]);
64     if (info->s->concurrent_insert)
65       mysql_rwlock_unlock(&info->s->key_root_lock[inx]);
66   }
67 
68   if (!(*info->read_record)(info,info->lastpos,record))
69     DBUG_RETURN(0);
70   if (my_errno == HA_ERR_RECORD_DELETED)
71     my_errno=HA_ERR_KEY_NOT_FOUND;
72   DBUG_RETURN(my_errno);
73 } /* mi_rsame */
74