/ Check-in [729d6586]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment::-) (CVS 47)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:729d6586b8377d0e6cefa64c8cf3d883e9f0ddc3
User & Date: drh 2000-06-03 19:19:41
Context
2000-06-03
19:28
:-) (CVS 48) check-in: f7665641 user: drh tags: trunk
19:19
:-) (CVS 47) check-in: 729d6586 user: drh tags: trunk
18:06
added default values (CVS 46) check-in: 27c06786 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

   211    211   publish:	$(PUBLISH)
   212    212   	scp $(PUBLISH) hwaci@oak.he.net:public_html/sw/sqlite
   213    213   
   214    214   clean:	
   215    215   	rm -f *.o sqlite libsqlite.a sqlite.h
   216    216   	rm -f lemon lempar.c parse.* sqlite.tar.gz
   217    217   	rm -f $(PUBLISH)
          218  +	rm -f *.da *.bb *.bbg gmon.out

Changes to src/expr.c.

    19     19   ** Author contact information:
    20     20   **   drh@hwaci.com
    21     21   **   http://www.hwaci.com/drh/
    22     22   **
    23     23   *************************************************************************
    24     24   ** This file contains C code routines used for processing expressions
    25     25   **
    26         -** $Id: expr.c,v 1.3 2000/06/03 18:06:53 drh Exp $
           26  +** $Id: expr.c,v 1.4 2000/06/03 19:19:41 drh Exp $
    27     27   */
    28     28   #include "sqliteInt.h"
    29     29   
    30     30   /*
    31     31   ** This routine walks an expression tree and resolves references to
    32     32   ** table fields.  Nodes of the form ID.ID or ID resolve into an
    33     33   ** index to the table in the table list and a field offset.  The opcode
................................................................................
   360    360         sqliteExprCode(pParse, pExpr->pLeft);
   361    361         sqliteVdbeAddOp(v, op, 0, 0, 0, 0);
   362    362         break;
   363    363       }
   364    364       case TK_ISNULL:
   365    365       case TK_NOTNULL: {
   366    366         int dest;
   367         -      sqliteVdbeAddOp(v, OP_Integer, 0, 0, 0, 0);
          367  +      sqliteVdbeAddOp(v, OP_Integer, 1, 0, 0, 0);
   368    368         sqliteExprCode(pParse, pExpr->pLeft);
   369    369         dest = sqliteVdbeCurrentAddr(v) + 2;
   370    370         sqliteVdbeAddOp(v, op, 0, dest, 0, 0);
   371         -      sqliteVdbeAddOp(v, OP_AddImm, 1, 0, 0, 0);
          371  +      sqliteVdbeAddOp(v, OP_AddImm, -1, 0, 0, 0);
   372    372         break;
   373    373       }
   374    374       case TK_FUNCTION: {
   375    375         int id = sqliteFuncId(&pExpr->token);
   376    376         int op;
   377    377         int i;
   378    378         ExprList *pList = pExpr->pList;

Changes to src/parse.y.

    22     22   **
    23     23   *************************************************************************
    24     24   ** This file contains SQLite's grammar for SQL.  Process this file
    25     25   ** using the lemon parser generator to generate C code that runs
    26     26   ** the parser.  Lemon will also generate a header file containing
    27     27   ** numeric codes for all of the tokens.
    28     28   **
    29         -** @(#) $Id: parse.y,v 1.7 2000/06/03 18:06:53 drh Exp $
           29  +** @(#) $Id: parse.y,v 1.8 2000/06/03 19:19:41 drh Exp $
    30     30   */
    31     31   %token_prefix TK_
    32     32   %token_type {Token}
    33     33   %extra_argument {Parse *pParse}
    34     34   %syntax_error {
    35     35     sqliteSetNString(&pParse->zErrMsg,"syntax error near \"",0,TOKEN.z,TOKEN.n,
    36     36                      "\"", 1, 0);
................................................................................
   238    238   item(A) ::= PLUS FLOAT(X).   {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
   239    239   item(A) ::= MINUS FLOAT(X).  {
   240    240     A = sqliteExpr(TK_FLOAT, 0, 0, 0);
   241    241     A->token.z = 0;
   242    242     sqliteSetNString(&A->token.z, "-", 1, X.z, X.n, 0);
   243    243   }
   244    244   item(A) ::= STRING(X).       {A = sqliteExpr(TK_STRING, 0, 0, &X);}
          245  +item(A) ::= NULL.            {A = sqliteExpr(TK_NULL, 0, 0, 0);}
   245    246   
   246    247   %type fieldlist_opt {IdList*}
   247    248   %destructor fieldlist_opt {sqliteIdListDelete($$);}
   248    249   %type fieldlist {IdList*}
   249    250   %destructor fieldlist {sqliteIdListDelete($$);}
   250    251   
   251    252   fieldlist_opt(A) ::= .                    {A = 0;}
   252    253   fieldlist_opt(A) ::= LP fieldlist(X) RP.  {A = X;}
   253    254   fieldlist(A) ::= fieldlist(X) COMMA ID(Y). {A = sqliteIdListAppend(X,&Y);}
   254    255   fieldlist(A) ::= ID(Y).                    {A = sqliteIdListAppend(0,&Y);}
   255    256   
   256    257   %left OR.
   257    258   %left AND.
          259  +%right NOT.
   258    260   %left EQ NE ISNULL NOTNULL IS LIKE GLOB.
   259    261   %left GT GE LT LE.
   260    262   %left PLUS MINUS.
   261    263   %left STAR SLASH PERCENT.
   262         -%right NOT.
          264  +%right UMINUS.
   263    265   
   264    266   %type expr {Expr*}
   265    267   %destructor expr {sqliteExprDelete($$);}
   266    268   
   267    269   expr(A) ::= LP expr(X) RP.   {A = X;}
   268    270   expr(A) ::= ID(X).           {A = sqliteExpr(TK_ID, 0, 0, &X);}
   269    271   expr(A) ::= NULL.            {A = sqliteExpr(TK_NULL, 0, 0, 0);}
................................................................................
   289    291   expr(A) ::= expr(X) PLUS expr(Y).  {A = sqliteExpr(TK_PLUS, X, Y, 0);}
   290    292   expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);}
   291    293   expr(A) ::= expr(X) STAR expr(Y).  {A = sqliteExpr(TK_STAR, X, Y, 0);}
   292    294   expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);}
   293    295   expr(A) ::= expr(X) ISNULL.        {A = sqliteExpr(TK_ISNULL, X, 0, 0);}
   294    296   expr(A) ::= expr(X) NOTNULL.       {A = sqliteExpr(TK_NOTNULL, X, 0, 0);}
   295    297   expr(A) ::= NOT expr(X).           {A = sqliteExpr(TK_NOT, X, 0, 0);}
   296         -expr(A) ::= MINUS expr(X). [NOT]   {A = sqliteExpr(TK_UMINUS, X, 0, 0);}
   297         -expr(A) ::= PLUS expr(X). [NOT]    {A = X;}
          298  +expr(A) ::= MINUS expr(X). [UMINUS]   {A = sqliteExpr(TK_UMINUS, X, 0, 0);}
          299  +expr(A) ::= PLUS expr(X). [UMINUS]    {A = X;}
   298    300   
   299    301   %type exprlist {ExprList*}
   300    302   %destructor exprlist {sqliteExprListDelete($$);}
   301    303   %type expritem {Expr*}
   302    304   %destructor expritem {sqliteExprDelete($$);}
   303    305   
   304    306   exprlist(A) ::= exprlist(X) COMMA expritem(Y). 

Changes to test/delete.test.

    19     19   #   drh@hwaci.com
    20     20   #   http://www.hwaci.com/drh/
    21     21   #
    22     22   #***********************************************************************
    23     23   # This file implements regression tests for SQLite library.  The
    24     24   # focus of this file is testing the DELETE FROM statement.
    25     25   #
    26         -# $Id: delete.test,v 1.3 2000/06/03 18:06:53 drh Exp $
           26  +# $Id: delete.test,v 1.4 2000/06/03 19:19:42 drh Exp $
    27     27   
    28     28   set testdir [file dirname $argv0]
    29     29   source $testdir/tester.tcl
    30     30   
    31     31   # Try to delete from a non-existant table.
    32     32   #
    33     33   do_test delete-1.1 {
................................................................................
    62     62     execsql {SELECT * FROM table1 ORDER BY f1}
    63     63   } {1 2 2 4 4 16}
    64     64   do_test delete-3.1d {
    65     65     execsql {DELETE FROM table1 WHERE f1=2}
    66     66     execsql {SELECT * FROM table1 ORDER BY f1}
    67     67   } {1 2 4 16}
    68     68   
           69  +# Semantic errors in the WHERE clause
           70  +#
           71  +do_test delete-4.1 {
           72  +  execsql {CREATE TABLE table2(f1 int, f2 int)}
           73  +  set v [catch {execsql {DELETE FROM table2 WHERE f3=5}} msg]
           74  +  lappend v $msg
           75  +} {1 {no such field: f3}}
           76  +
           77  +do_test delete-4.2 {
           78  +  set v [catch {execsql {DELETE FROM table2 WHERE xyzzy(f1+4)}} msg]
           79  +  lappend v $msg
           80  +} {1 {no such function: xyzzy}}
    69     81   
    70     82   finish_test

Changes to test/expr.test.

    19     19   #   drh@hwaci.com
    20     20   #   http://www.hwaci.com/drh/
    21     21   #
    22     22   #***********************************************************************
    23     23   # This file implements regression tests for SQLite library.  The
    24     24   # focus of this file is testing expressions.
    25     25   #
    26         -# $Id: expr.test,v 1.3 2000/05/31 18:33:10 drh Exp $
           26  +# $Id: expr.test,v 1.4 2000/06/03 19:19:42 drh Exp $
    27     27   
    28     28   set testdir [file dirname $argv0]
    29     29   source $testdir/tester.tcl
    30     30   
    31     31   # Create a table to work with.
    32     32   #
    33     33   execsql {CREATE TABLE test1(i1 int, i2 int, r1 real, r2 real, t1 text, t2 text)}
................................................................................
    60     60   test_expr expr-1.19 {i1=20, i2=20} {i2=i1} 1
    61     61   test_expr expr-1.20 {i1=20, i2=20} {i2<>i1} 0
    62     62   test_expr expr-1.21 {i1=20, i2=20} {i2==i1} 1
    63     63   test_expr expr-1.22 {i1=1, i2=2, r1=3.0} {i1+i2*r1} {7}
    64     64   test_expr expr-1.23 {i1=1, i2=2, r1=3.0} {(i1+i2)*r1} {9}
    65     65   test_expr expr-1.24 {i1=1, i2=2} {min(i1,i2,i1+i2,i1-i2)} {-1}
    66     66   test_expr expr-1.25 {i1=1, i2=2} {max(i1,i2,i1+i2,i1-i2)} {3}
    67         -
           67  +test_expr expr-1.26 {i1=1, i2=2} {max(i1,i2,i1+i2,i1-i2)} {3}
           68  +test_expr expr-1.27 {i1=1, i2=2} {i1==1 AND i2=2} {1}
           69  +test_expr expr-1.28 {i1=1, i2=2} {i1=2 AND i2=1} {0}
           70  +test_expr expr-1.29 {i1=1, i2=2} {i1=1 AND i2=1} {0}
           71  +test_expr expr-1.30 {i1=1, i2=2} {i1=2 AND i2=2} {0}
           72  +test_expr expr-1.31 {i1=1, i2=2} {i1==1 OR i2=2} {1}
           73  +test_expr expr-1.32 {i1=1, i2=2} {i1=2 OR i2=1} {0}
           74  +test_expr expr-1.33 {i1=1, i2=2} {i1=1 OR i2=1} {1}
           75  +test_expr expr-1.34 {i1=1, i2=2} {i1=2 OR i2=2} {1}
           76  +test_expr expr-1.35 {i1=1, i2=2} {i1-i2=-1} {1}
           77  +test_expr expr-1.36 {i1=1, i2=0} {not i1} {0}
           78  +test_expr expr-1.37 {i1=1, i2=NULL} {not i2} {1}
    68     79   
    69     80   test_expr expr-2.1 {r1=1.23, r2=2.34} {r1+r2} 3.57
    70     81   test_expr expr-2.2 {r1=1.23, r2=2.34} {r1-r2} -1.11
    71     82   test_expr expr-2.3 {r1=1.23, r2=2.34} {r1*r2} 2.8782
    72     83   test_expr expr-2.4 {r1=1.23, r2=2.34} {r1/r2} 0.525641
    73     84   test_expr expr-2.5 {r1=1.23, r2=2.34} {r2/r1} 1.90244
    74     85   test_expr expr-2.6 {r1=1.23, r2=2.34} {r2<r1} 0
................................................................................
   110    121   test_expr expr-3.18 {t1='abc', t2='abc'} {t1==t2} 1
   111    122   test_expr expr-3.19 {t1='abc', t2='xyz'} {t1<>t2} 1
   112    123   test_expr expr-3.20 {t1='xyz', t2='abc'} {t1<>t2} 1
   113    124   test_expr expr-3.21 {t1='abc', t2='abc'} {t1<>t2} 0
   114    125   test_expr expr-3.22 {t1='abc', t2='xyz'} {t1!=t2} 1
   115    126   test_expr expr-3.23 {t1='xyz', t2='abc'} {t1!=t2} 1
   116    127   test_expr expr-3.24 {t1='abc', t2='abc'} {t1!=t2} 0
          128  +test_expr expr-3.25 {t1=NULL, t2='hi'} {t1 isnull} 1
          129  +test_expr expr-3.26 {t1=NULL, t2='hi'} {t2 isnull} 0
          130  +test_expr expr-3.27 {t1=NULL, t2='hi'} {t1 notnull} 0
          131  +test_expr expr-3.28 {t1=NULL, t2='hi'} {t2 notnull} 1
   117    132   
   118    133   test_expr expr-4.1 {t1='abc', t2='Abc'} {t1<t2} 0
   119    134   test_expr expr-4.2 {t1='abc', t2='Abc'} {t1>t2} 1
   120    135   test_expr expr-4.3 {t1='abc', t2='Bbc'} {t1<t2} 1
   121    136   test_expr expr-4.4 {t1='abc', t2='Bbc'} {t1>t2} 0
   122    137   
   123    138   test_expr expr-5.1 {t1='abc', t2='xyz'} {t1 LIKE t2} 0
................................................................................
   125    140   test_expr expr-5.3 {t1='abc', t2='A_C'} {t1 LIKE t2} 1
   126    141   test_expr expr-5.4 {t1='abc', t2='abc_'} {t1 LIKE t2} 0
   127    142   test_expr expr-5.5 {t1='abc', t2='A%C'} {t1 LIKE t2} 1
   128    143   test_expr expr-5.6 {t1='abxyzzyc', t2='A%C'} {t1 LIKE t2} 1
   129    144   test_expr expr-5.7 {t1='abxyzzy', t2='A%C'} {t1 LIKE t2} 0
   130    145   test_expr expr-5.8 {t1='abxyzzycx', t2='A%C'} {t1 LIKE t2} 0
   131    146   
          147  +test_expr expr-6.1 {t1='abc', t2='xyz'} {t1 GLOB t2} 0
          148  +test_expr expr-6.2 {t1='abc', t2='ABC'} {t1 GLOB t2} 0
          149  +test_expr expr-6.3 {t1='abc', t2='A?C'} {t1 GLOB t2} 0
          150  +test_expr expr-6.4 {t1='abc', t2='a?c'} {t1 GLOB t2} 1
          151  +test_expr expr-6.5 {t1='abc', t2='abc?'} {t1 GLOB t2} 0
          152  +test_expr expr-6.6 {t1='abc', t2='A*C'} {t1 GLOB t2} 0
          153  +test_expr expr-6.7 {t1='abc', t2='a*c'} {t1 GLOB t2} 1
          154  +test_expr expr-6.8 {t1='abxyzzyc', t2='a*c'} {t1 GLOB t2} 1
          155  +test_expr expr-6.9 {t1='abxyzzy', t2='a*c'} {t1 GLOB t2} 0
          156  +test_expr expr-6.10 {t1='abxyzzycx', t2='a*c'} {t1 GLOB t2} 0
          157  +
          158  +
          159  +# The sqliteExprIfFalse and sqliteExprIfTrue routines are only
          160  +# executed as part of a WHERE clause.  Create a table suitable
          161  +# for testing these functions.
          162  +#
          163  +execsql {DROP TABLE test1}
          164  +execsql {CREATE TABLE test1(a int, b int);}
          165  +for {set i 1} {$i<=20} {incr i} {
          166  +  execsql "INSERT INTO test1 VALUES($i,[expr {int(pow(2,$i))}])"
          167  +}
          168  +execsql "INSERT INTO test1 VALUES(NULL,0)"
          169  +do_test expr-7.1 {
          170  +  execsql {SELECT * FROM test1 ORDER BY a}
          171  +} {{} 0 1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 9 512 10 1024 11 2048 12 4096 13 8192 14 16384 15 32768 16 65536 17 131072 18 262144 19 524288 20 1048576}
          172  +
          173  +proc test_expr2 {name expr result} {
          174  +  do_test $name [format {
          175  +    execsql {SELECT a FROM test1 WHERE %s ORDER BY a}
          176  +  } $expr] $result
          177  +}
          178  +
          179  +test_expr2 expr-7.2  {a<10 AND a>8}                  {9}
          180  +test_expr2 expr-7.3  {a<=10 AND a>=8}                {8 9 10}
          181  +test_expr2 expr-7.4  {a>=8 AND a<=10}                {8 9 10}
          182  +test_expr2 expr-7.5  {a>=20 OR a<=1}                 {{} 1 20}
          183  +test_expr2 expr-7.6  {b!=4 AND a<=3}                 {{} 1 3}
          184  +test_expr2 expr-7.7  {b==8 OR b==16 OR b==32}        {3 4 5}
          185  +test_expr2 expr-7.8  {NOT b<>8 OR b==1024}           {3 10}
          186  +test_expr2 expr-7.9  {b LIKE '10%'}                  {10 20}
          187  +test_expr2 expr-7.10 {b LIKE '_4'}                   {6}
          188  +test_expr2 expr-7.11 {a GLOB '1?'}            {10 11 12 13 14 15 16 17 18 19}
          189  +test_expr2 expr-7.12 {b GLOB '1*4'}                  {10 14}
          190  +test_expr2 expr-7.13 {b GLOB '*1[456]'}              {4}
          191  +test_expr2 expr-7.14 {a ISNULL}                      {{}}
          192  +test_expr2 expr-7.15 {a NOTNULL AND a<3}             {1 2}
          193  +test_expr2 expr-7.16 {a AND a<3}                     {1 2}
          194  +test_expr2 expr-7.17 {NOT a}                         {{}}
          195  +test_expr2 expr-7.18 {a==11 OR (b>1000 AND b<2000)}  {10 11}
          196  +test_expr2 expr-7.19 {a<=1 OR a>=20}                 {{} 1 20}
          197  +test_expr2 expr-7.20 {a<1 OR a>20}                   {{}}
          198  +test_expr2 expr-7.21 {a>19 OR a<1}                   {{} 20}
          199  +test_expr2 expr-7.22 {a!=1 OR a=100} \
          200  +                         {{} 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}
          201  +test_expr2 expr-7.23 {(a notnull AND a<4) OR a==8}   {1 2 3 8}
          202  +test_expr2 expr-7.24 {a LIKE '2_' OR a==8}           {8 20}
          203  +test_expr2 expr-7.25 {a GLOB '2?' OR a==8}           {8 20}
          204  +test_expr2 expr-7.26 {a isnull OR a=8}               {{} 8}
          205  +test_expr2 expr-7.27 {a notnull OR a=8} \
          206  +                          {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}
          207  +
   132    208   finish_test