Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Simplify the number processing code. Fix for ticket #281. (CVS 910) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
4326b52a39cad4632dc2db37aa53a285 |
User & Date: | drh 2003-04-16 02:17:35.000 |
Context
2003-04-16
| ||
20:24 | Fix the authorizer so that it correctly interprets attempts to read the OLD and NEW pseudo-tables of a trigger. (CVS 911) (check-in: f04bd43254 user: drh tags: trunk) | |
02:17 | Simplify the number processing code. Fix for ticket #281. (CVS 910) (check-in: 4326b52a39 user: drh tags: trunk) | |
01:28 | Remove some unnecessary code and complication from the btree interface. (CVS 909) (check-in: 35cc7c7d37 user: drh tags: trunk) | |
Changes
Changes to src/sqliteInt.h.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** ** @(#) $Id: sqliteInt.h,v 1.174 2003/04/16 02:17:35 drh Exp $ */ #include "config.h" #include "sqlite.h" #include "hash.h" #include "vdbe.h" #include "parse.h" #include "btree.h" |
︙ | ︙ | |||
977 978 979 980 981 982 983 984 985 986 987 988 989 990 | /* ** Internal function prototypes */ int sqliteStrICmp(const char *, const char *); int sqliteStrNICmp(const char *, const char *, int); int sqliteHashNoCase(const char *, int); int sqliteCompare(const char *, const char *); int sqliteSortCompare(const char *, const char *); void sqliteRealToSortable(double r, char *); #ifdef MEMORY_DEBUG void *sqliteMalloc_(int,int,char*,int); void sqliteFree_(void*,char*,int); void *sqliteRealloc_(void*,int,char*,int); | > | 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 | /* ** Internal function prototypes */ 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 *); #ifdef MEMORY_DEBUG void *sqliteMalloc_(int,int,char*,int); void sqliteFree_(void*,char*,int); void *sqliteRealloc_(void*,int,char*,int); |
︙ | ︙ | |||
1123 1124 1125 1126 1127 1128 1129 | int sqliteAuthCheck(Parse*,int, const char*, const char*); #else # define sqliteAuthRead(a,b,c,d) # define sqliteAuthCheck(a,b,c,d) SQLITE_OK #endif void sqliteAttach(Parse*, Token*, Token*); void sqliteDetach(Parse*, Token*); | | > | 1124 1125 1126 1127 1128 1129 1130 1131 1132 | int sqliteAuthCheck(Parse*,int, const char*, const char*); #else # define sqliteAuthRead(a,b,c,d) # define sqliteAuthCheck(a,b,c,d) SQLITE_OK #endif void sqliteAttach(Parse*, Token*, Token*); void sqliteDetach(Parse*, Token*); int sqliteBtreeFactory(const sqlite *db, const char *zFilename, int mode, int nPg, Btree **ppBtree); |
Changes to src/tokenize.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ************************************************************************* ** An tokenizer for SQL ** ** This file contains C code that splits an SQL input string up into ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ************************************************************************* ** An tokenizer for SQL ** ** This file contains C code that splits an SQL input string up into ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** ** $Id: tokenize.c,v 1.57 2003/04/16 02:17:36 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include <stdlib.h> /* |
︙ | ︙ | |||
348 349 350 351 352 353 354 | } } if( z[i] ) i++; *tokenType = TK_STRING; return i; } case '.': { | < | | < < | | < < | 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | } } if( z[i] ) i++; *tokenType = TK_STRING; return i; } 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]=='.' && isdigit(z[i+1]) ){ i += 2; while( isdigit(z[i]) ){ i++; } *tokenType = TK_FLOAT; } if( (z[i]=='e' || z[i]=='E') && ( isdigit(z[i+1]) || ((z[i+1]=='+' || z[i+1]=='-') && isdigit(z[i+2])) ) ){ i += 2; while( isdigit(z[i]) ){ i++; } *tokenType = TK_FLOAT; } return i; } case '[': { for(i=1; z[i] && z[i-1]!=']'; i++){} *tokenType = TK_ID; |
︙ | ︙ |
Changes to src/util.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ** ************************************************************************* ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** ** $Id: util.c,v 1.61 2003/04/16 02:17:36 drh Exp $ */ #include "sqliteInt.h" #include <stdarg.h> #include <ctype.h> /* ** If malloc() ever fails, this global variable gets set to 1. |
︙ | ︙ | |||
793 794 795 796 797 798 799 | } #endif /* NOT USED */ /* ** Return TRUE if z is a pure numeric string. Return FALSE if the ** string contains any character which is not part of a number. ** | | | | > | | | | | < | 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 | } #endif /* NOT USED */ /* ** 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 non-numeric. */ int sqliteIsNumber(const char *z){ if( *z=='-' || *z=='+' ) z++; if( !isdigit(*z) ){ return 0; } z++; while( isdigit(*z) ){ z++; } if( *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; } /* This comparison routine is what we use for comparison operations ** between numeric values in an SQL expression. "Numeric" is a little ** bit misleading here. What we mean is that the strings have a |
︙ | ︙ |
Changes to src/vdbe.c.
︙ | ︙ | |||
32 33 34 35 36 37 38 | ** ** Various scripts scan this source file in order to generate HTML ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | ** ** Various scripts scan this source file in order to generate HTML ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** 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.216 2003/04/16 02:17:36 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> /* ** The makefile scans this source file and creates the following ** array of string constants which are the names of all VDBE opcodes. |
︙ | ︙ | |||
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | #endif } p->nOp += nOp; } return addr; } /* ** Change the value of the P1 operand for a specific instruction. ** This routine is useful when a large program is loaded from a ** static array using sqliteVdbeAddOpList but we want to make a ** few minor changes to the program. */ void sqliteVdbeChangeP1(Vdbe *p, int addr, int val){ assert( p->magic==VDBE_MAGIC_INIT ); if( p && addr>=0 && p->nOp>addr && p->aOp ){ p->aOp[addr].p1 = val; } } /* ** Change the value of the P2 operand for a specific instruction. ** This routine is useful for setting a jump destination. */ void sqliteVdbeChangeP2(Vdbe *p, int addr, int val){ assert( val>=0 ); | > > | 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | #endif } p->nOp += nOp; } 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 ** static array using sqliteVdbeAddOpList but we want to make a ** few minor changes to the program. */ void sqliteVdbeChangeP1(Vdbe *p, int addr, int val){ assert( p->magic==VDBE_MAGIC_INIT ); if( p && addr>=0 && p->nOp>addr && p->aOp ){ p->aOp[addr].p1 = val; } } #endif /* NOT USED */ /* ** Change the value of the P2 operand for a specific instruction. ** This routine is useful for setting a jump destination. */ void sqliteVdbeChangeP2(Vdbe *p, int addr, int val){ assert( val>=0 ); |
︙ | ︙ | |||
1085 1086 1087 1088 1089 1090 1091 | ** function. */ #define POPSTACK \ assert(p->tos>=0); \ if( aStack[p->tos].flags & STK_Dyn ) sqliteFree(zStack[p->tos]); \ p->tos--; | < < < < < < < < < < < < < < < < < < < < < | 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 | ** function. */ #define POPSTACK \ assert(p->tos>=0); \ if( aStack[p->tos].flags & STK_Dyn ) sqliteFree(zStack[p->tos]); \ p->tos--; /* ** Delete a keylist */ static void KeylistFree(Keylist *p){ while( p ){ Keylist *pNext = p->pNext; sqliteFree(p); |
︙ | ︙ | |||
3078 3079 3080 3081 3082 3083 3084 | if( flags & STK_Null ){ nByte += 2; containsNull = 1; }else if( pOp->p3 && pOp->p3[j]=='t' ){ Stringify(p, i); aStack[i].flags &= ~(STK_Int|STK_Real); nByte += aStack[i].n+1; | | | 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 | if( flags & STK_Null ){ nByte += 2; containsNull = 1; }else if( pOp->p3 && pOp->p3[j]=='t' ){ Stringify(p, i); aStack[i].flags &= ~(STK_Int|STK_Real); nByte += aStack[i].n+1; }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 ){ aStack[i].r = atof(zStack[i]); } Release(p, i); z = aStack[i].z; |
︙ | ︙ |
Changes to test/expr.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2001 September 15 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing expressions. # | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # 2001 September 15 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing expressions. # # $Id: expr.test,v 1.29 2003/04/16 02:17:36 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a table to work with. # execsql {CREATE TABLE test1(i1 int, i2 int, r1 real, r2 real, t1 text, t2 text)} |
︙ | ︙ | |||
122 123 124 125 126 127 128 129 130 131 132 133 134 135 | test_expr expr-1.95 {i1=NULL, i2=8} {2 not between i1 and i2} {{}} test_expr expr-1.94 {i1=NULL, i2=8} {55 between i1 and i2} 0 test_expr expr-1.95 {i1=NULL, i2=8} {55 not between i1 and i2} 1 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-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 test_expr expr-2.3 {r1=1.23, r2=2.34} {r1*r2} 2.8782 test_expr expr-2.4 {r1=1.23, r2=2.34} {r1/r2} 0.525641025641026 test_expr expr-2.5 {r1=1.23, r2=2.34} {r2/r1} 1.90243902439024 test_expr expr-2.6 {r1=1.23, r2=2.34} {r2<r1} 0 | > > | 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | test_expr expr-1.95 {i1=NULL, i2=8} {2 not between i1 and i2} {{}} test_expr expr-1.94 {i1=NULL, i2=8} {55 between i1 and i2} 0 test_expr expr-1.95 {i1=NULL, i2=8} {55 not between i1 and i2} 1 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 test_expr expr-2.3 {r1=1.23, r2=2.34} {r1*r2} 2.8782 test_expr expr-2.4 {r1=1.23, r2=2.34} {r1/r2} 0.525641025641026 test_expr expr-2.5 {r1=1.23, r2=2.34} {r2/r1} 1.90243902439024 test_expr expr-2.6 {r1=1.23, r2=2.34} {r2<r1} 0 |
︙ | ︙ |
Changes to test/index.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2001 September 15 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the CREATE INDEX statement. # | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # 2001 September 15 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the CREATE INDEX statement. # # $Id: index.test,v 1.22 2003/04/16 02:17:36 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a basic index and verify it is added to sqlite_master # do_test index-1.1 { |
︙ | ︙ | |||
476 477 478 479 480 481 482 | } {3 5 2 1} do_test index-14.11 { execsql { SELECT c FROM t6 WHERE a<''; } } {3 5} | > > > > | > > > > > > > > > > > > > > > > > > | 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | } {3 5 2 1} do_test index-14.11 { execsql { SELECT c FROM t6 WHERE a<''; } } {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 |
Changes to test/main.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2001 September 15 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is exercising the code in main.c. # | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # 2001 September 15 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # 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.12 2003/04/16 02:17:36 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Tests of the sqlite_complete() function. # do_test main-1.1 { |
︙ | ︙ | |||
194 195 196 197 198 199 200 | do_test main-3.3 { catch {db close} foreach f [glob -nocomplain testdb/*] {file delete -force $f} file delete -force testdb sqlite db testdb execsql { create table T1(X REAL); | | | | | | 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | do_test main-3.3 { catch {db close} foreach f [glob -nocomplain testdb/*] {file delete -force $f} file delete -force testdb sqlite db testdb execsql { create table T1(X REAL); 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(0.5e2); insert into T1 values(0.5E+02); insert into T1 values(5E+02); 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} do_test main-3.4 { set v [catch {execsql {create bogus}} msg] lappend v $msg } {1 {near "bogus": syntax error}} do_test main-3.5 { set v [catch {execsql {create}} msg] lappend v $msg } {1 {near "create": syntax error}} finish_test |