mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Fix a bug in the reverse scan logic that comes up when the table being
scanned is empty. Add additional tests for the reverse scan. (CVS 797) FossilOrigin-Name: 0051c87d5e8d07fae09da2eb7b0d8cbd1bbd3c8e
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** $Id: btree.c,v 1.74 2002/12/04 13:40:26 drh Exp $
|
||||
** $Id: btree.c,v 1.75 2002/12/04 22:29:28 drh Exp $
|
||||
**
|
||||
** This file implements a external (disk-based) database using BTrees.
|
||||
** For a detailed discussion of BTrees, refer to
|
||||
@@ -1495,7 +1495,8 @@ int sqliteBtreeLast(BtCursor *pCur, int *pRes){
|
||||
** this value is as follows:
|
||||
**
|
||||
** *pRes<0 The cursor is left pointing at an entry that
|
||||
** is smaller than pKey.
|
||||
** is smaller than pKey or if the table is empty
|
||||
** and the cursor is therefore left point to nothing.
|
||||
**
|
||||
** *pRes==0 The cursor is left pointing at an entry that
|
||||
** exactly matches pKey.
|
||||
@@ -1513,7 +1514,7 @@ int sqliteBtreeMoveto(BtCursor *pCur, const void *pKey, int nKey, int *pRes){
|
||||
int lwr, upr;
|
||||
Pgno chldPg;
|
||||
MemPage *pPage = pCur->pPage;
|
||||
int c = -1;
|
||||
int c = -1; /* pRes return if table is empty must be -1 */
|
||||
lwr = 0;
|
||||
upr = pPage->nCell-1;
|
||||
while( lwr<=upr ){
|
||||
|
16
src/vdbe.c
16
src/vdbe.c
@@ -36,7 +36,7 @@
|
||||
** in this file for details. If in doubt, do not deviate from existing
|
||||
** commenting and indentation practices when changing or adding code.
|
||||
**
|
||||
** $Id: vdbe.c,v 1.186 2002/12/04 20:01:06 drh Exp $
|
||||
** $Id: vdbe.c,v 1.187 2002/12/04 22:29:29 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -3394,9 +3394,17 @@ case OP_MoveTo: {
|
||||
if( res && pOp->p2>0 ){
|
||||
pc = pOp->p2 - 1;
|
||||
}
|
||||
}else if( oc==OP_MoveLt && res>=0 ){
|
||||
sqliteBtreePrevious(pC->pCursor, &res);
|
||||
pC->recnoIsValid = 0;
|
||||
}else if( oc==OP_MoveLt ){
|
||||
if( res>=0 ){
|
||||
sqliteBtreePrevious(pC->pCursor, &res);
|
||||
pC->recnoIsValid = 0;
|
||||
}else{
|
||||
/* res might be negative because the table is empty. Check to
|
||||
** see if this is the case.
|
||||
*/
|
||||
int keysize;
|
||||
res = sqliteBtreeKeySize(pC->pCursor,&keysize)!=0 || keysize==0;
|
||||
}
|
||||
if( res && pOp->p2>0 ){
|
||||
pc = pOp->p2 - 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user