1/* Copyright (C) 2006 MySQL AB & MySQL Finland AB & TCX DataKonsult 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */
15
16#include "maria_def.h"
17
18/**
19 Find current row with read on position or read on key
20
21 @notes
22 If inx >= 0 find record using key else re-read row on last position
23
24 @warning
25 This function is not row version safe.
26 This is not crtical as this function is not used by MySQL
27
28 @return
29 @retval 0 Ok
30 @retval HA_ERR_KEY_NOT_FOUND Row is deleted
31 @retval HA_ERR_END_OF_FILE End of file
32 @retval HA_ERR_WRONG_INDEX Wrong inx argument
33*/
34
35
36int maria_rsame(MARIA_HA *info, uchar *record, int inx)
37{
38 DBUG_ENTER("maria_rsame");
39
40 if (inx >= 0 && _ma_check_index(info, inx) < 0)
41 {
42 DBUG_PRINT("error", ("wrong index usage"));
43 DBUG_RETURN(my_errno);
44 }
45 if (info->cur_row.lastpos == HA_OFFSET_ERROR ||
46 info->update & HA_STATE_DELETED)
47 {
48 DBUG_PRINT("error", ("no current record"));
49 DBUG_RETURN(my_errno=HA_ERR_KEY_NOT_FOUND); /* No current record */
50 }
51 info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
52
53 /* Read row from data file */
54 if (fast_ma_readinfo(info))
55 DBUG_RETURN(my_errno);
56
57 if (inx >= 0)
58 {
59 MARIA_KEYDEF *keyinfo= info->last_key.keyinfo;
60 (*keyinfo->make_key)(info, &info->last_key, (uint) inx,
61 info->lastkey_buff, record,
62 info->cur_row.lastpos,
63 info->cur_row.trid);
64 if (info->s->lock_key_trees)
65 mysql_rwlock_rdlock(&keyinfo->root_lock);
66 _ma_search(info, &info->last_key, SEARCH_SAME,
67 info->s->state.key_root[inx]);
68 if (info->s->lock_key_trees)
69 mysql_rwlock_unlock(&keyinfo->root_lock);
70 }
71
72 if (!(*info->read_record)(info, record, info->cur_row.lastpos))
73 DBUG_RETURN(0);
74 if (my_errno == HA_ERR_RECORD_DELETED)
75 my_errno=HA_ERR_KEY_NOT_FOUND;
76 DBUG_PRINT("error", ("my_errno: %d", my_errno));
77 DBUG_RETURN(my_errno);
78} /* maria_rsame */
79