Index: src/dbbe.c ================================================================== --- src/dbbe.c +++ src/dbbe.c @@ -28,11 +28,11 @@ ** ** This file uses GDBM as the database backend. It should be ** relatively simple to convert to a different database such ** as NDBM, SDBM, or BerkeleyDB. ** -** $Id: dbbe.c,v 1.12 2000/06/07 14:42:26 drh Exp $ +** $Id: dbbe.c,v 1.13 2000/06/08 15:10:47 drh Exp $ */ #include "sqliteInt.h" #include #include #include @@ -310,11 +310,15 @@ if( pFile==0 ){ sqliteFree(zFile); return SQLITE_NOMEM; } if( zFile ){ - pFile->dbf = gdbm_open(zFile, 0, rw_mask, mode, 0); + if( !writeable || pBe->write ){ + pFile->dbf = gdbm_open(zFile, 0, rw_mask, mode, 0); + }else{ + pFile->dbf = 0; + } }else{ int limit; struct rc4 *pRc4; char zRandom[50]; pRc4 = &pBe->rc4; @@ -337,11 +341,13 @@ } pFile->pNext = pBe->pOpen; pBe->pOpen = pFile; if( pFile->dbf==0 ){ if( !writeable && access(zFile,0) ){ - rc = SQLITE_OK; + /* Trying to read a non-existant file. This is OK. All the + ** reads will return empty, which is what we want. */ + rc = SQLITE_OK; }else if( access(zFile,W_OK|R_OK) ){ rc = SQLITE_PERM; }else{ rc = SQLITE_BUSY; } Index: src/expr.c ================================================================== --- src/expr.c +++ src/expr.c @@ -21,11 +21,11 @@ ** http://www.hwaci.com/drh/ ** ************************************************************************* ** This file contains C code routines used for processing expressions ** -** $Id: expr.c,v 1.13 2000/06/08 13:36:40 drh Exp $ +** $Id: expr.c,v 1.14 2000/06/08 15:10:47 drh Exp $ */ #include "sqliteInt.h" /* ** Walk an expression tree. Return 1 if the expression is constant @@ -398,11 +398,12 @@ nErr++; } if( is_agg ) pExpr->op = TK_AGG_FUNCTION; if( is_agg && pIsAgg ) *pIsAgg = 1; for(i=0; nErr==0 && ipList->a[i].pExpr, 0, 0); + nErr = sqliteExprCheck(pParse, pExpr->pList->a[i].pExpr, + allowAgg && !is_agg, pIsAgg); } } default: { if( pExpr->pLeft ){ nErr = sqliteExprCheck(pParse, pExpr->pLeft, allowAgg, pIsAgg); Index: src/parse.y ================================================================== --- src/parse.y +++ src/parse.y @@ -24,11 +24,11 @@ ** This file contains SQLite's grammar for SQL. Process this file ** using the lemon parser generator to generate C code that runs ** the parser. Lemon will also generate a header file containing ** numeric codes for all of the tokens. ** -** @(#) $Id: parse.y,v 1.17 2000/06/08 13:36:40 drh Exp $ +** @(#) $Id: parse.y,v 1.18 2000/06/08 15:10:47 drh Exp $ */ %token_prefix TK_ %token_type {Token} %extra_argument {Parse *pParse} %syntax_error { @@ -81,18 +81,18 @@ id(A) ::= ID(X). {A = X;} id(A) ::= STRING(X). {A = X;} type ::= typename. type ::= typename LP signed RP. type ::= typename LP signed COMMA signed RP. -typename ::= ID. -typename ::= typename ID. +typename ::= id. +typename ::= typename id. signed ::= INTEGER. signed ::= PLUS INTEGER. signed ::= MINUS INTEGER. carglist ::= carglist carg. carglist ::= . -carg ::= CONSTRAINT ID ccons. +carg ::= CONSTRAINT id ccons. carg ::= ccons. carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);} carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);} carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);} carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);} @@ -115,11 +115,11 @@ // conslist_opt ::= . conslist_opt ::= COMMA conslist. conslist ::= conslist COMMA tcons. conslist ::= tcons. -tcons ::= CONSTRAINT ID tcons2. +tcons ::= CONSTRAINT id tcons2. tcons ::= tcons2. tcons2 ::= PRIMARY KEY LP idxlist(X) RP. {sqliteCreateIndex(pParse,0,0,X,0,0);} tcons2 ::= UNIQUE LP idlist RP. tcons2 ::= CHECK expr. @@ -176,13 +176,11 @@ %destructor sclp {sqliteExprListDelete($$);} sclp(A) ::= selcollist(X) COMMA. {A = X;} sclp(A) ::= . {A = 0;} selcollist(A) ::= STAR. {A = 0;} selcollist(A) ::= sclp(P) expr(X). {A = sqliteExprListAppend(P,X,0);} -selcollist(A) ::= sclp(P) expr(X) as ID(Y). {A = sqliteExprListAppend(P,X,&Y);} -selcollist(A) ::= sclp(P) expr(X) as STRING(Y). - {A = sqliteExprListAppend(P,X,&Y);} +selcollist(A) ::= sclp(P) expr(X) as id(Y). {A = sqliteExprListAppend(P,X,&Y);} as ::= . as ::= AS. %type seltablist {IdList*} @@ -234,11 +232,11 @@ %destructor having_opt {sqliteExprDelete($$);} having_opt(A) ::= . {A = 0;} having_opt(A) ::= HAVING expr(X). {A = X;} -cmd ::= DELETE FROM ID(X) where_opt(Y). +cmd ::= DELETE FROM id(X) where_opt(Y). {sqliteDeleteFrom(pParse, &X, Y);} %type where_opt {Expr*} %destructor where_opt {sqliteExprDelete($$);} @@ -246,20 +244,20 @@ where_opt(A) ::= WHERE expr(X). {A = X;} %type setlist {ExprList*} %destructor setlist {sqliteExprListDelete($$);} -cmd ::= UPDATE ID(X) SET setlist(Y) where_opt(Z). +cmd ::= UPDATE id(X) SET setlist(Y) where_opt(Z). {sqliteUpdate(pParse,&X,Y,Z);} -setlist(A) ::= ID(X) EQ expr(Y) COMMA setlist(Z). +setlist(A) ::= id(X) EQ expr(Y) COMMA setlist(Z). {A = sqliteExprListAppend(Z,Y,&X);} -setlist(A) ::= ID(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);} +setlist(A) ::= id(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);} -cmd ::= INSERT INTO ID(X) fieldlist_opt(F) VALUES LP itemlist(Y) RP. +cmd ::= INSERT INTO id(X) fieldlist_opt(F) VALUES LP itemlist(Y) RP. {sqliteInsert(pParse, &X, Y, 0, F);} -cmd ::= INSERT INTO ID(X) fieldlist_opt(F) select(S). +cmd ::= INSERT INTO id(X) fieldlist_opt(F) select(S). {sqliteInsert(pParse, &X, 0, S, F);} %type itemlist {ExprList*} %destructor itemlist {sqliteExprListDelete($$);} @@ -288,12 +286,12 @@ %type fieldlist {IdList*} %destructor fieldlist {sqliteIdListDelete($$);} fieldlist_opt(A) ::= . {A = 0;} fieldlist_opt(A) ::= LP fieldlist(X) RP. {A = X;} -fieldlist(A) ::= fieldlist(X) COMMA ID(Y). {A = sqliteIdListAppend(X,&Y);} -fieldlist(A) ::= ID(Y). {A = sqliteIdListAppend(0,&Y);} +fieldlist(A) ::= fieldlist(X) COMMA id(Y). {A = sqliteIdListAppend(X,&Y);} +fieldlist(A) ::= id(Y). {A = sqliteIdListAppend(0,&Y);} %left OR. %left AND. %right NOT. %left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN. @@ -306,11 +304,11 @@ %destructor expr {sqliteExprDelete($$);} expr(A) ::= LP expr(X) RP. {A = X;} expr(A) ::= ID(X). {A = sqliteExpr(TK_ID, 0, 0, &X);} expr(A) ::= NULL. {A = sqliteExpr(TK_NULL, 0, 0, 0);} -expr(A) ::= ID(X) DOT ID(Y). {Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X); +expr(A) ::= id(X) DOT id(Y). {Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X); Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y); A = sqliteExpr(TK_DOT, temp1, temp2, 0);} expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);} expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);} expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);} @@ -391,11 +389,11 @@ exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);} expritem(A) ::= expr(X). {A = X;} expritem(A) ::= . {A = 0;} -cmd ::= CREATE(S) uniqueflag INDEX ID(X) ON ID(Y) LP idxlist(Z) RP(E). +cmd ::= CREATE(S) uniqueflag INDEX id(X) ON id(Y) LP idxlist(Z) RP(E). {sqliteCreateIndex(pParse, &X, &Y, Z, &S, &E);} uniqueflag ::= UNIQUE. uniqueflag ::= . %type idxlist {IdList*} @@ -404,11 +402,11 @@ idxlist(A) ::= idxlist(X) COMMA idxitem(Y). {A = sqliteIdListAppend(X,&Y);} idxlist(A) ::= idxitem(Y). {A = sqliteIdListAppend(0,&Y);} -idxitem(A) ::= ID(X). {A = X;} +idxitem(A) ::= id(X). {A = X;} cmd ::= DROP INDEX id(X). {sqliteDropIndex(pParse, &X);} cmd ::= COPY id(X) FROM id(Y) USING DELIMITERS STRING(Z). {sqliteCopy(pParse,&X,&Y,&Z);} Index: src/select.c ================================================================== --- src/select.c +++ src/select.c @@ -22,11 +22,11 @@ ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle SELECT statements. ** -** $Id: select.c,v 1.22 2000/06/08 13:36:40 drh Exp $ +** $Id: select.c,v 1.23 2000/06/08 15:10:48 drh Exp $ */ #include "sqliteInt.h" /* ** Allocate a new Select structure and return a pointer to that @@ -375,20 +375,20 @@ for(i=0; inExpr; i++){ Expr *pE = pOrderBy->a[i].pExpr; int match = 0; if( pOrderBy->a[i].done ) continue; for(j=0; jnExpr; j++){ - if( pEList->a[i].zName && (pE->op==TK_ID || pE->op==TK_STRING) ){ - char *zName = pEList->a[i].zName; + if( pEList->a[j].zName && (pE->op==TK_ID || pE->op==TK_STRING) ){ + char *zName = pEList->a[j].zName; char *zLabel = sqliteStrNDup(pE->token.z, pE->token.n); sqliteDequote(zLabel); if( sqliteStrICmp(zName, zLabel)==0 ){ match = 1; } sqliteFree(zLabel); } - if( match==0 && sqliteExprCompare(pE, pEList->a[i].pExpr) ){ + if( match==0 && sqliteExprCompare(pE, pEList->a[j].pExpr) ){ match = 1; } if( match ){ pE->op = TK_FIELD; pE->iField = j; Index: src/vdbe.c ================================================================== --- src/vdbe.c +++ src/vdbe.c @@ -39,11 +39,11 @@ ** Most of the code in this file is taken up by the sqliteVdbeExec() ** function which does the work of interpreting a VDBE program. ** But other routines are also provided to help in building up ** a program instruction by instruction. ** -** $Id: vdbe.c,v 1.28 2000/06/08 13:36:41 drh Exp $ +** $Id: vdbe.c,v 1.29 2000/06/08 15:10:48 drh Exp $ */ #include "sqliteInt.h" #include /* @@ -1709,11 +1709,11 @@ " permission denied for table ", pOp->p3, 0); break; } case SQLITE_READONLY: { sqliteSetString(pzErrMsg,"table ", pOp->p3, - " is already opened for reading", 0); + " is readonly", 0); break; } case SQLITE_NOMEM: { goto no_mem; } Index: test/dbbe.test ================================================================== --- test/dbbe.test +++ test/dbbe.test @@ -21,11 +21,11 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is exercising the code in dbbe.c. # -# $Id: dbbe.test,v 1.1 2000/06/07 14:42:27 drh Exp $ +# $Id: dbbe.test,v 1.2 2000/06/08 15:10:48 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Try to open a database that does not exist. @@ -116,7 +116,21 @@ set r [execsql {SELECT * FROM T1}] db close sqlite db testdb 0666 lappend r [execsql {SELECT * FROM t1}] } {1 1} + +# Try to change a table after opening the database readonly +# +do_test dbbe-3.1 { + catch {db close} + file delete -force testdb + sqlite db testdb 0666 + execsql {CREATE TABLE t1(x int)} + db close + sqlite db testdb 0444 + set v [catch {execsql {INSERT INTO t1 VALUES(1)}} msg] + lappend v $msg +} {1 {write permission denied for table t1}} + finish_test Index: test/delete.test ================================================================== --- test/delete.test +++ test/delete.test @@ -21,11 +21,11 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the DELETE FROM statement. # -# $Id: delete.test,v 1.4 2000/06/03 19:19:42 drh Exp $ +# $Id: delete.test,v 1.5 2000/06/08 15:10:48 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Try to delete from a non-existant table. @@ -56,11 +56,11 @@ execsql {DELETE FROM table1 WHERE f1=3} execsql {SELECT * FROM table1 ORDER BY f1} } {1 2 2 4 4 16} do_test delete-3.1c { execsql {CREATE INDEX index1 ON table1(f1)} - execsql {DELETE FROM table1 WHERE f1=3} + execsql {DELETE FROM 'table1' WHERE f1=3} execsql {SELECT * FROM table1 ORDER BY f1} } {1 2 2 4 4 16} do_test delete-3.1d { execsql {DELETE FROM table1 WHERE f1=2} execsql {SELECT * FROM table1 ORDER BY f1} Index: test/select3.test ================================================================== --- test/select3.test +++ test/select3.test @@ -22,11 +22,11 @@ #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing aggregate functions and the # GROUP BY and HAVING clauses of SELECT statements. # -# $Id: select3.test,v 1.1 2000/06/06 18:00:16 drh Exp $ +# $Id: select3.test,v 1.2 2000/06/08 15:10:48 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Build some test data @@ -109,6 +109,21 @@ HAVING count(*)>=4 ORDER BY max(n) } } {3 4 4 8 5 15} +do_test select3-5.1 { + execsql { + SELECT log, count(*), avg(n), max(n+log*2) FROM t1 + GROUP BY log + ORDER BY max(n+log*2), avg(n) + } +} {0 1 1 1 1 1 2 4 2 2 3.5 8 3 4 6.5 14 4 8 12.5 24 5 15 24 41} +do_test select3-5.2 { + execsql { + SELECT log, count(*), avg(n), max(n+log*2) FROM t1 + GROUP BY log + ORDER BY max(n+log*2), min(log,avg(n)) + } +} {0 1 1 1 1 1 2 4 2 2 3.5 8 3 4 6.5 14 4 8 12.5 24 5 15 24 41} + finish_test Index: test/select4.test ================================================================== --- test/select4.test +++ test/select4.test @@ -22,11 +22,11 @@ #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing UNION, INTERSECT and EXCEPT operators # in SELECT statements. # -# $Id: select4.test,v 1.2 2000/06/08 01:55:31 drh Exp $ +# $Id: select4.test,v 1.3 2000/06/08 15:10:48 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Build some test data @@ -242,6 +242,23 @@ ORDER BY log; }} msg] lappend v $msg } {0 {1 2 2 3}} +do_test select4-6.1 { + execsql { + SELECT log, count(*) as cnt FROM t1 GROUP BY log + UNION + SELECT log, n FROM t1 WHERE n=7 + ORDER BY cnt, log; + } +} {0 1 1 1 2 2 3 4 3 7 4 8 5 15} +do_test select4-6.2 { + execsql { + SELECT log, count(*) FROM t1 GROUP BY log + UNION + SELECT log, n FROM t1 WHERE n=7 + ORDER BY count(*), log; + } +} {0 1 1 1 2 2 3 4 3 7 4 8 5 15} + finish_test Index: test/table.test ================================================================== --- test/table.test +++ test/table.test @@ -21,11 +21,11 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the CREATE TABLE statement. # -# $Id: table.test,v 1.4 2000/05/30 16:27:05 drh Exp $ +# $Id: table.test,v 1.5 2000/06/08 15:10:48 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a basic table and verify it is added to sqlite_master @@ -111,11 +111,11 @@ # Verify that we cannot make two tables with the same name # do_test table-2.1 { - execsql {CREATE TABLE test2(one text)} + execsql {CREATE TABLE TEST2(one text)} set v [catch {execsql {CREATE TABLE test2(two text)}} msg] lappend v $msg } {1 {table test2 already exists}} do_test table-2.1b { set v [catch {execsql {CREATE TABLE sqlite_master(two text)}} msg] @@ -283,6 +283,14 @@ execsql {CREATE TABLE test1(f1 int)} execsql {EXPLAIN DROP TABLE test1} execsql {SELECT name FROM sqlite_master} } {test1} +# Create a table with a goofy name +# +do_test table-6.1 { + execsql {CREATE TABLE 'Spaces In This Name!'(x int)} + execsql {INSERT INTO 'spaces in this name!' VALUES(1)} + set list [glob -nocomplain testdb/spaces*.tbl] +} {testdb/spaces+in+this+name+.tbl} + finish_test