Simplify the number processing code. Fix for ticket #281. (CVS 910)

FossilOrigin-Name: 4326b52a39cad4632dc2db37aa53a285a31af138
This commit is contained in:
drh 2003-04-16 02:17:35 +00:00
parent 144f9eadf6
commit bb07e9a34f
9 changed files with 67 additions and 65 deletions

View File

@ -1,5 +1,5 @@
C Remove\ssome\sunnecessary\scode\sand\scomplication\sfrom\sthe\sbtree\sinterface.\s(CVS\s909)
D 2003-04-16T01:28:16
C Simplify\sthe\snumber\sprocessing\scode.\s\sFix\sfor\sticket\s#281.\s(CVS\s910)
D 2003-04-16T02:17:35
F Makefile.in df3a4db41a7450468b5fe934d9dd8f723b631249
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@ -47,19 +47,19 @@ F src/select.c 14e2e2a512f4edfc75fb310ebcb502ff3ee87402
F src/shell.c 97f397c0c108176ccbc52ea5b8ec688f995eba7a
F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
F src/sqlite.h.in f49c2cdec7d24cb03e496a1ca519e16306495ee1
F src/sqliteInt.h c34ae7f78cb3c2f8e7136ff091155f97f7ec9327
F src/sqliteInt.h b3d4e485ab646970e8b0d268771486683aceab12
F src/table.c eed2098c9b577aa17f8abe89313a9c4413f57d63
F src/tclsqlite.c 7a072c3c8ba9796edc25e5ffa62b68558134e192
F src/test1.c 7ad4e6308dde0bf5a0f0775ce20cb2ec37a328f8
F src/test2.c 5014337d8576b731cce5b5a14bec4f0daf432700
F src/test3.c 30985ebdfaf3ee1462a9b0652d3efbdc8d9798f5
F src/threadtest.c d641a5219e718e18a1a80a50eb9bb549f451f42e
F src/tokenize.c 675b4718d17c69fe7609dc8e85e426ef002be811
F src/tokenize.c a88cfb6f698d047e14d5064fa6c4ecb709bf8fa4
F src/trigger.c 4ca4499d367548385b8e9fc67eb360cd1ca95b8a
F src/update.c a60470d07cdd4ff3c11c5418f8055f2f41b3d751
F src/util.c 8953c612a036e30f24c1c1f5a1498176173daa37
F src/util.c 13c338a7d0e1e6290ca227edb0d6d7be6a7c7127
F src/vacuum.c ac65e9578506a0cdf70ece2668e5b22f4895477c
F src/vdbe.c 6738153dc8ebd68cf5d6ccf7e1e08d608f5420c6
F src/vdbe.c 45f7167eebd82f52dd73501f2a30ecb398f5d154
F src/vdbe.h 985c24f312d10f9ef8f9a8b8ea62fcdf68e82f21
F src/where.c e5733f7d5e9cc4ed3590dc3401f779e7b7bb8127
F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
@ -75,13 +75,13 @@ F test/capi2.test fb94bed9e236074c5e255cfd25e3e32344e24855
F test/conflict.test 80cf3780c8686b92db4ce0f60bca46a000537327
F test/copy.test 73df5ed3112e858e006a8b7ddb4c9bab6a25d0fb
F test/delete.test 5821a95a66061ae09723a88938f23d10d8a881ad
F test/expr.test 290e2617b89b5c5e3bf71f19367d285102128be4
F test/expr.test 48bc6400627532ec97e233809e33d336468bc84c
F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7
F test/format3.test 64ab6c4db132b28a645996d413530f7b2a462cc2
F test/func.test 000515779001ac6899eec4b54e65c6e2501279d4
F test/hook.test 7a4c97b886801d265c981dc4ec123c77af642a9d
F test/in.test 3171a2b3170a8223665c1a4f26be5f3eda36cc4b
F test/index.test faeb1bcf776e3ff9ba1b4be1eadd1fece708aa7b
F test/index.test 90ef4c426865f15937858bd433cc82b9c11af913
F test/insert.test 5697ba098e4d8a6f0151f281b7e39dec9c439e05
F test/insert2.test c288375a64dad3295044714f0dfed4a193cf067f
F test/intpkey.test 39f49fd993350f7f3ab255e5cfbf9a09d8f8800e
@ -89,7 +89,7 @@ F test/ioerr.test 45c8feebe608d7f456fea27ff27a0aaaf0b9c636
F test/join.test c97267c19294bf1fa4e81087edad179828bced88
F test/limit.test 9ffb965a0f5bf7152187ef3d8d1249b96e5620bf
F test/lock.test 388a3a10962d2d571c0c1821cc35bf069ee73473
F test/main.test c66b564554b770ee7fdbf6a66c0cd90329bc2c85
F test/main.test 8108ac48302027bbe4296c30b913adbe6d5d984b
F test/malloc.test 7ba32a9ebd3aeed52ae4aaa6d42ca37e444536fd
F test/memleak.test a18e6810cae96d2f6f5136920267adbefc8e1e90
F test/minmax.test 29bc5727c3e4c792d5c4745833dd4b505905819e
@ -162,7 +162,7 @@ F www/speed.tcl cb4c10a722614aea76d2c51f32ee43400d5951be
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
P 0b996959b8d8bc2c82eab9cccc190befd0056505
R 9b9a6e33d11cf491ef2a5576ee3b5a64
P 35cc7c7d37d9ca486e7f300efe80a78a7f1064e2
R 909d0687af9c3ff27bb06570bec6a9fa
U drh
Z ff418746ff7b6d08e8d28734401a85c5
Z d786241d64fb8801e2ebebb18c866f00

View File

@ -1 +1 @@
35cc7c7d37d9ca486e7f300efe80a78a7f1064e2
4326b52a39cad4632dc2db37aa53a285a31af138

View File

@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.173 2003/04/15 19:22:24 drh Exp $
** @(#) $Id: sqliteInt.h,v 1.174 2003/04/16 02:17:35 drh Exp $
*/
#include "config.h"
#include "sqlite.h"
@ -981,6 +981,7 @@ extern int always_code_trigger_setup;
int sqliteStrICmp(const char *, const char *);
int sqliteStrNICmp(const char *, const char *, int);
int sqliteHashNoCase(const char *, int);
int sqliteIsNumber(const char*);
int sqliteCompare(const char *, const char *);
int sqliteSortCompare(const char *, const char *);
void sqliteRealToSortable(double r, char *);
@ -1127,4 +1128,5 @@ void sqliteDeferForeignKey(Parse*, int);
#endif
void sqliteAttach(Parse*, Token*, Token*);
void sqliteDetach(Parse*, Token*);
int sqliteBtreeFactory(const sqlite *db, const char *zFilename, int mode, int nPg, Btree **ppBtree);
int sqliteBtreeFactory(const sqlite *db, const char *zFilename,
int mode, int nPg, Btree **ppBtree);

View File

@ -15,7 +15,7 @@
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
**
** $Id: tokenize.c,v 1.56 2003/03/20 01:16:59 drh Exp $
** $Id: tokenize.c,v 1.57 2003/04/16 02:17:36 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -352,18 +352,15 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
return i;
}
case '.': {
if( !isdigit(z[1]) ){
*tokenType = TK_DOT;
return 1;
}
/* Fall thru into the next case */
*tokenType = TK_DOT;
return 1;
}
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': {
*tokenType = TK_INTEGER;
for(i=1; isdigit(z[i]); i++){}
if( z[i]=='.' ){
i++;
if( z[i]=='.' && isdigit(z[i+1]) ){
i += 2;
while( isdigit(z[i]) ){ i++; }
*tokenType = TK_FLOAT;
}
@ -375,8 +372,6 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
i += 2;
while( isdigit(z[i]) ){ i++; }
*tokenType = TK_FLOAT;
}else if( z[0]=='.' ){
*tokenType = TK_FLOAT;
}
return i;
}

View File

@ -14,7 +14,7 @@
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.60 2003/03/31 13:36:09 drh Exp $
** $Id: util.c,v 1.61 2003/04/16 02:17:36 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@ -797,12 +797,12 @@ static int sortStrCmp(const char *atext, const char *btext, int useCase){
** Return TRUE if z is a pure numeric string. Return FALSE if the
** string contains any character which is not part of a number.
**
** Am empty string is considered numeric.
** Am empty string is considered non-numeric.
*/
static int sqliteIsNumber(const char *z){
int sqliteIsNumber(const char *z){
if( *z=='-' || *z=='+' ) z++;
if( !isdigit(*z) ){
return *z==0;
return 0;
}
z++;
while( isdigit(*z) ){ z++; }
@ -810,12 +810,12 @@ static int sqliteIsNumber(const char *z){
z++;
if( !isdigit(*z) ) return 0;
while( isdigit(*z) ){ z++; }
if( *z=='e' || *z=='E' ){
z++;
if( *z=='+' || *z=='-' ) z++;
if( !isdigit(*z) ) return 0;
while( isdigit(*z) ){ z++; }
}
}
if( *z=='e' || *z=='E' ){
z++;
if( *z=='+' || *z=='-' ) z++;
if( !isdigit(*z) ) return 0;
while( isdigit(*z) ){ z++; }
}
return *z==0;
}

View File

@ -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.215 2003/04/15 19:22:24 drh Exp $
** $Id: vdbe.c,v 1.216 2003/04/16 02:17:36 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -485,6 +485,7 @@ int sqliteVdbeAddOpList(Vdbe *p, int nOp, VdbeOp const *aOp){
return addr;
}
#if 0 /* NOT USED */
/*
** Change the value of the P1 operand for a specific instruction.
** This routine is useful when a large program is loaded from a
@ -497,6 +498,7 @@ void sqliteVdbeChangeP1(Vdbe *p, int addr, int val){
p->aOp[addr].p1 = val;
}
}
#endif /* NOT USED */
/*
** Change the value of the P2 operand for a specific instruction.
@ -1089,27 +1091,6 @@ static void PopStack(Vdbe *p, int N){
if( aStack[p->tos].flags & STK_Dyn ) sqliteFree(zStack[p->tos]); \
p->tos--;
/*
** Return TRUE if zNum is a floating-point or integer number.
*/
static int isNumber(const char *zNum){
if( *zNum=='-' || *zNum=='+' ) zNum++;
if( !isdigit(*zNum) ) return 0;
while( isdigit(*zNum) ) zNum++;
if( *zNum==0 ) return 1;
if( *zNum!='.' ) return 0;
zNum++;
if( !isdigit(*zNum) ) return 0;
while( isdigit(*zNum) ) zNum++;
if( *zNum==0 ) return 1;
if( *zNum!='e' && *zNum!='E' ) return 0;
zNum++;
if( *zNum=='-' || *zNum=='+' ) zNum++;
if( !isdigit(*zNum) ) return 0;
while( isdigit(*zNum) ) zNum++;
return *zNum==0;
}
/*
** Delete a keylist
*/
@ -3082,7 +3063,7 @@ case OP_MakeKey: {
Stringify(p, i);
aStack[i].flags &= ~(STK_Int|STK_Real);
nByte += aStack[i].n+1;
}else if( (flags & (STK_Real|STK_Int))!=0 || isNumber(zStack[i]) ){
}else if( (flags & (STK_Real|STK_Int))!=0 || sqliteIsNumber(zStack[i]) ){
if( (flags & (STK_Real|STK_Int))==STK_Int ){
aStack[i].r = aStack[i].i;
}else if( (flags & (STK_Real|STK_Int))==0 ){

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing expressions.
#
# $Id: expr.test,v 1.28 2003/01/14 00:44:09 drh Exp $
# $Id: expr.test,v 1.29 2003/04/16 02:17:36 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -126,6 +126,8 @@ test_expr expr-1.96 {i1=NULL, i2=3} {coalesce(i1<<i2,99)} 99
test_expr expr-1.97 {i1=32, i2=NULL} {coalesce(i1>>i2,99)} 99
test_expr expr-1.98 {i1=NULL, i2=NULL} {coalesce(i1|i2,99)} 99
test_expr expr-1.99 {i1=32, i2=NULL} {coalesce(i1&i2,99)} 99
test_expr expr-1.100 {i1=1, i2=''} {i1=i2} 0
test_expr expr-1.101 {i1=0, i2=''} {i1=i2} 0
test_expr expr-2.1 {r1=1.23, r2=2.34} {r1+r2} 3.57
test_expr expr-2.2 {r1=1.23, r2=2.34} {r1-r2} -1.11

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the CREATE INDEX statement.
#
# $Id: index.test,v 1.21 2003/03/30 00:19:50 drh Exp $
# $Id: index.test,v 1.22 2003/04/16 02:17:36 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -480,5 +480,27 @@ do_test index-14.11 {
}
} {3 5}
do_test index-15.1 {
execsql {
DELETE FROM t1;
SELECT * FROM t1;
}
} {}
do_test index-15.2 {
execsql {
INSERT INTO t1 VALUES('1.234e5',1);
INSERT INTO t1 VALUES('12.33e04',2);
INSERT INTO t1 VALUES('12.35E4',3);
INSERT INTO t1 VALUES('12.34e',4);
INSERT INTO t1 VALUES('12.32e+4',5);
INSERT INTO t1 VALUES('12.36E+04',6);
INSERT INTO t1 VALUES('12.36E+',7);
INSERT INTO t1 VALUES('+123.10000E+0003',8);
INSERT INTO t1 VALUES('+',9);
INSERT INTO t1 VALUES('+12347.E+02',10);
INSERT INTO t1 VALUES('+12347E+02',11);
SELECT b FROM t1 ORDER BY a;
}
} {8 5 2 1 3 6 11 9 10 4 7}
finish_test

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is exercising the code in main.c.
#
# $Id: main.test,v 1.11 2002/05/15 14:17:45 drh Exp $
# $Id: main.test,v 1.12 2003/04/16 02:17:36 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -198,16 +198,16 @@ do_test main-3.3 {
sqlite db testdb
execsql {
create table T1(X REAL);
insert into T1 values(.5);
insert into T1 values(0.5);
insert into T1 values(0.5e2);
insert into T1 values(0.5e-002);
insert into T1 values(5e-002);
insert into T1 values(-5.0e-2);
insert into T1 values(-5.1e-2);
insert into T1 values(.5e2);
insert into T1 values(.5E+02);
insert into T1 values(0.5e2);
insert into T1 values(0.5E+02);
insert into T1 values(5E+02);
insert into T1 values(5.E+03);
insert into T1 values(5.0E+03);
select x*10 from T1 order by x*5;
}
} {-0.51 -0.5 0.05 0.5 5 500 500 500 5000 50000}