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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
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 : */
33 :
34 :
35 : int maria_rsame(MARIA_HA *info, uchar *record, int inx)
36 49166 : {
37 49166 : DBUG_ENTER("maria_rsame");
38 :
39 49166 : if (inx != -1 && ! maria_is_key_active(info->s->state.key_map, inx))
40 : {
41 0 : DBUG_PRINT("error", ("wrong index usage"));
42 0 : DBUG_RETURN(my_errno=HA_ERR_WRONG_INDEX);
43 : }
44 49166 : if (info->cur_row.lastpos == HA_OFFSET_ERROR ||
45 : info->update & HA_STATE_DELETED)
46 : {
47 0 : DBUG_PRINT("error", ("no current record"));
48 0 : DBUG_RETURN(my_errno=HA_ERR_KEY_NOT_FOUND); /* No current record */
49 : }
50 49166 : info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
51 :
52 : /* Read row from data file */
53 49166 : if (fast_ma_readinfo(info))
54 0 : DBUG_RETURN(my_errno);
55 :
56 49166 : if (inx >= 0)
57 : {
58 162 : MARIA_KEYDEF *keyinfo= info->s->keyinfo + inx;
59 162 : info->lastinx= inx;
60 162 : (*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 162 : if (info->s->lock_key_trees)
65 0 : rw_rdlock(&keyinfo->root_lock);
66 162 : VOID(_ma_search(info, &info->last_key, SEARCH_SAME,
67 : info->s->state.key_root[inx]));
68 162 : if (info->s->lock_key_trees)
69 0 : rw_unlock(&keyinfo->root_lock);
70 : }
71 :
72 49166 : if (!(*info->read_record)(info, record, info->cur_row.lastpos))
73 49166 : DBUG_RETURN(0);
74 0 : if (my_errno == HA_ERR_RECORD_DELETED)
75 0 : my_errno=HA_ERR_KEY_NOT_FOUND;
76 0 : DBUG_PRINT("error", ("my_errno: %d", my_errno));
77 0 : DBUG_RETURN(my_errno);
78 : } /* maria_rsame */
|