home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 January / Chip_2001-01_cd1.bin / tema / mysql / mysql-3.23.28g-win-source.exe / myisam / mi_rsame.c < prev    next >
C/C++ Source or Header  |  2000-08-31  |  2KB  |  66 lines

  1. /* Copyright (C) 2000 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; either version 2 of the License, or
  6.    (at your option) any later version.
  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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, byte *record, int inx)
  30. {
  31.   DBUG_ENTER("mi_rsame");
  32.  
  33.   if (inx != -1 && ! (((ulonglong) 1 << inx) & info->s->state.key_map))
  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 (_mi_readinfo(info,F_RDLCK,1))
  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.       rw_rdlock(&info->s->key_root_lock[inx]);
  54.     VOID(_mi_search(info,info->s->keyinfo+inx,info->lastkey,0,SEARCH_SAME,
  55.             info->s->state.key_root[inx]));
  56.     if (info->s->concurrent_insert)
  57.       rw_unlock(&info->s->key_root_lock[inx]);
  58.   }
  59.  
  60.   if (!(*info->read_record)(info,info->lastpos,record))
  61.     DBUG_RETURN(0);
  62.   if (my_errno == HA_ERR_RECORD_DELETED)
  63.     my_errno=HA_ERR_KEY_NOT_FOUND;
  64.   DBUG_RETURN(my_errno);
  65. } /* mi_rsame */
  66.