home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 January / Chip_2001-01_cd1.bin / tema / mysql / mysql-3.23.28g-win-source.exe / isam / rprev.c < prev    next >
C/C++ Source or Header  |  2000-11-21  |  2KB  |  65 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. /* L{ser f|reg}ende post med samma isam-nyckel */
  18.  
  19. #include "isamdef.h"
  20.  
  21.     /*
  22.        L{ser f|reg}ende post med samma isamnyckel som f|reg}ende l{sning.
  23.        Man kan ha gjort write, update eller delete p} f|reg}ende post.
  24.        OBS! [ven om man {ndrade isamnyckeln p} f|reg}ende post l{ses
  25.        posten i avseende p} f|reg}ende isam-nyckel-l{sning !!
  26.     */
  27.  
  28. int nisam_rprev(N_INFO *info, byte *buf, int inx)
  29. {
  30.   int error,changed;
  31.   register uint flag;
  32.   DBUG_ENTER("nisam_rprev");
  33.  
  34.   if ((inx = _nisam_check_index(info,inx)) < 0)
  35.     DBUG_RETURN(-1);
  36.   flag=SEARCH_SMALLER;                /* Read previous */
  37.   if (info->lastpos == NI_POS_ERROR && info->update & HA_STATE_NEXT_FOUND)
  38.     flag=0;                    /* Read last */
  39.  
  40. #ifndef NO_LOCKING
  41.   if (_nisam_readinfo(info,F_RDLCK,1)) DBUG_RETURN(-1);
  42. #endif
  43.   changed=_nisam_test_if_changed(info);
  44.   if (!flag)
  45.     error=_nisam_search_last(info,info->s->keyinfo+inx,info->s->state.key_root[inx]);
  46.   else if (!changed)
  47.     error=_nisam_search_next(info,info->s->keyinfo+inx,info->lastkey,flag,
  48.               info->s->state.key_root[inx]);
  49.   else
  50.     error=_nisam_search(info,info->s->keyinfo+inx,info->lastkey,0,flag,
  51.              info->s->state.key_root[inx]);
  52.  
  53.   info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED |
  54.           HA_STATE_BUFF_SAVED);
  55.   info->update|= HA_STATE_PREV_FOUND;
  56.   if (error && my_errno == HA_ERR_KEY_NOT_FOUND)
  57.     my_errno=HA_ERR_END_OF_FILE;
  58.   if ((*info->read_record)(info,info->lastpos,buf) >=0)
  59.   {
  60.     info->update|= HA_STATE_AKTIV;        /* Record is read */
  61.     DBUG_RETURN(0);
  62.   }
  63.   DBUG_RETURN(-1);
  64. } /* nisam_rprev */
  65.