myrg_rprev.c
Upload User: tsgydb
Upload Date: 2007-04-14
Package Size: 10674k
Code Size: 2k
Category:

MySQL

Development Platform:

Visual C++

  1. /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. #include "mymrgdef.h"
  14. /*
  15.    Read previous row with the same key as previous read
  16. */
  17. int myrg_rprev(MYRG_INFO *info, byte *buf, int inx)
  18. {
  19.   int err;
  20.   MI_INFO *mi;
  21.   /* at first, do rprev for the table found before */
  22.   if ((err=mi_rprev(info->current_table->table,NULL,inx)))
  23.   {
  24.     if (err == HA_ERR_END_OF_FILE)
  25.       queue_remove(&(info->by_key),0);
  26.     else
  27.       return err;
  28.   }
  29.   else
  30.   {
  31.     /* Found here, adding to queue */
  32.     queue_top(&(info->by_key))=(byte *)(info->current_table);
  33.     queue_replaced(&(info->by_key));
  34.   }
  35.   /* next, let's finish myrg_rkey's initial scan */
  36.   if ((err=_myrg_finish_scan(info, inx, HA_READ_KEY_OR_PREV)))
  37.     return err;
  38.   if (!info->by_key.elements)
  39.     return HA_ERR_END_OF_FILE;
  40.   /* now, mymerge's read_prev is as simple as one queue_top */
  41.   mi=(info->current_table=(MYRG_TABLE *)queue_top(&(info->by_key)))->table;
  42.   return mi_rrnd(mi,buf,mi->lastpos);
  43. }