1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-08 03:22:21 +03:00

Enhance the ORDER BY clause so that an integer term means to sort by the

corresponding column. (CVS 602)

FossilOrigin-Name: 7acbf84b492202d8b5a05276a95b475027eb5f58
This commit is contained in:
drh
2002-06-02 16:09:01 +00:00
parent 1288c9561d
commit e4de1feb3e
7 changed files with 187 additions and 35 deletions

View File

@@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.66 2002/05/31 15:51:25 drh Exp $
** $Id: expr.c,v 1.67 2002/06/02 16:09:02 drh Exp $
*/
#include "sqliteInt.h"
@@ -335,6 +335,41 @@ int sqliteExprIsConstant(Expr *p){
return 0;
}
/*
** If the given expression codes a constant integer, return 1 and put
** the value of the integer in *pValue. If the expression is not an
** integer, return 0 and leave *pValue unchanged.
*/
int sqliteExprIsInteger(Expr *p, int *pValue){
switch( p->op ){
case TK_INTEGER: {
*pValue = atoi(p->token.z);
return 1;
}
case TK_STRING: {
char *z = p->token.z;
int n = p->token.n;
if( n>0 && z=='-' ){ z++; n--; }
while( n>0 && *z && isdigit(*z) ){ z++; n--; }
if( n==0 ){
*pValue = atoi(p->token.z);
return 1;
}
break;
}
case TK_UMINUS: {
int v;
if( sqliteExprIsInteger(p->pLeft, &v) ){
*pValue = -v;
return 1;
}
break;
}
default: break;
}
return 0;
}
/*
** Return TRUE if the given string is a row-id column name.
*/