Code simplifications. New test cases.

FossilOrigin-Name: 57508518ef9d003d259ba98dcc32e5104aca26731a7161808741fe10bc0830d0
This commit is contained in:
drh 2018-02-26 21:26:27 +00:00
parent 171d16bb21
commit 43c4ac8bfe
8 changed files with 84 additions and 44 deletions

View File

@ -1,5 +1,5 @@
C Get\sthe\s"DEFAULT\strue"\sand\s"DEFAULT\sfalse"\sphrases\sworking\scorrectly\sin\nCREATE\sTABLE.
D 2018-02-26T20:15:54.167
C Code\ssimplifications.\s\sNew\stest\scases.
D 2018-02-26T21:26:27.326
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in a2d2fb8d17c39ab5ec52beb27850b903949080848236923f436156b72a958737
@ -441,7 +441,7 @@ F src/date.c ebe1dc7c8a347117bb02570f1a931c62dd78f4a2b1b516f4837d45b7d6426957
F src/dbpage.c 8db4c97f630e7d83f884ea75caf1ffd0988c160e9d530194d93721c80821e0f6
F src/dbstat.c 7a4ba8518b6369ef3600c49cf9c918ad979acba610b2aebef1b656d649b96720
F src/delete.c 20c8788451dc737a967c87ea53ad43544d617f5b57d32ccce8bd52a0daf9e89b
F src/expr.c 2662b7cb76943b5865fe5e62f21615e7f86928b98f0b908b339f84a91ace8f8e
F src/expr.c ee29e9c2af181dd8fe4476f7e983aa13aa1634d00dd955a90ffbeb4732d7bc39
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
F src/fkey.c d617daf66b5515e2b42c1405b2b4984c30ca50fb705ab164271a9bf66c69e331
F src/func.c 94f42cba2cc1c34aeaa441022ba0170ec3fec4bba54db4e0ded085c6dc0fdc51
@ -477,7 +477,7 @@ F src/os_win.c eb03c6d52f893bcd7fdd4c6006674c13c1b5e49543fec98d605201af2997171c
F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
F src/pager.c 0b6bd5442733b2e08d0673de6cdafe3e7ab0b5715e4844ac836ab346b1d9ed89
F src/pager.h 581698f2177e8bd4008fe4760898ce20b6133d1df22139b9101b5155f900df7a
F src/parse.y 6319911fb7ab37907fb1ea14ddfea429b2c42707276eaa388b6c402891dfc091
F src/parse.y b875c74b72497f3cf23d9c6227ec0c859824ac9a5b23380cc1ed8adcff4857a0
F src/pcache.c 7ae91a4557a43d77d449accbfdc68846e6516f8e2eda46e8bbe4536fb669b201
F src/pcache.h 072f94d29281cffd99e46c1539849f248c4b56ae7684c1f36626797fee375170
F src/pcache1.c 716975564c15eb6679e97f734cec1bfd6c16ac3d4010f05f1f8e509fc7d19880
@ -486,14 +486,14 @@ F src/pragma.h bb83728944b42f6d409c77f5838a8edbdb0fe83046c5496ffc9602b40340a324
F src/prepare.c 259f4e7960c47082c9653f3d5f0c294abd68bb9c3aab86de7630700cba1c20fb
F src/printf.c d3b7844ddeb11fbbdd38dd84d09c9c1ac171d21fb038473c3aa97981201cc660
F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
F src/resolve.c 6f8a45063c693019734887b5f95e860137960fae324ef8b6db36f06e8c53240e
F src/resolve.c 66c73fcb7719b8ff0e841b58338f13604ff3e2b50a723f9b8f383595735262f6
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
F src/select.c f02352ac5cbb6fad3804add825743b924cfb6c742ba2e8666d726828a9985d73
F src/shell.c.in c1b14bc0bc1fe73a97dfaad55ca09f5d6e44f6019977d94e7e3d1861616035e1
F src/sqlite.h.in 235e942dd8c01b414c2996828b4d0d2500faf8850f8b24ae17d31c172f519e69
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d
F src/sqliteInt.h a6856d3d1aefd594b2c8c6245c6fbcba3d691e38555e22910ee6e7a839bc3897
F src/sqliteInt.h ce6d2c08df3216a69d3f7fb740e8ddb7ef94169277776778e7cfce05ab245d10
F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
F src/status.c 9737ed017279a9e0c5da748701c3c7bf1e8ae0dae459aad20dd64fcff97a7e35
F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
@ -551,7 +551,7 @@ F src/test_windirent.h 90dfbe95442c9762357fe128dc7ae3dc199d006de93eb33ba3972e0a9
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c
F src/tokenize.c 5b0c661a85f783d35b9883830736eeb63be4aefc4f6b7d9cd081d48782c041e2
F src/treeview.c bdc8ca85b6f9b56b10381801b656f0ec0f4a86a3f5006cd3f9faa24fc15ea443
F src/treeview.c b2470f160658181f5d1d7672144d5e7a2635a398a2f062842b7b4e0c766c4158
F src/trigger.c a34539c69433276d37b0da9a89c117726ff2d292c0902895af1f393a983cd3a1
F src/update.c a90a32ffc0100265b0693dbbdbe490756447af181f5ea2c138cce515b08c8795
F src/utf.c 810fbfebe12359f10bc2a011520a6e10879ab2a163bcb26c74768eab82ea62a5
@ -1001,7 +1001,7 @@ F test/ioerr3.test d3cec5e1a11ad6d27527d0d38573fbff14c71bdd
F test/ioerr4.test f130fe9e71008577b342b8874d52984bd04ede2c
F test/ioerr5.test 2edfa4fb0f896f733071303b42224df8bedd9da4
F test/ioerr6.test a395a6ab144b26a9e3e21059a1ab6a7149cca65b
F test/istrue.test c15523b11ea315e7c2855e12f39ddd9df8852d23b8caafceb53a5f5dca907c91
F test/istrue.test 2d89873d72248b7a0ef7b5457120100cce75a19181bcf4b30e90a3f96a5c5558
F test/join.test 442c462eea85cf065d70a663c626b780a95af6e11585d909bb63b87598afe678
F test/join2.test f1b5ba94ba70a791df2d99e61adcebf62edacad1eca57881c97eb3e2ca718595
F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
@ -1708,7 +1708,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 7e38305e6f71c3353df3d11d099e255eefbacceafd7ed2ccaba257fe2e7b8c38
R 8bbc8431995f4fe7e9fb21f05431fedd
P 8002f87d96b3f885cd208e7d204907a33ba60c4057ce2338b71e2de41215b0e5
R 5cfd707edda06e1acf2e2d72bf60da27
U drh
Z 0df480b7d34c4b4166a378f5cc8b7dd8
Z d672c3ecc0520c79d23db3920b6bc66e

View File

@ -1 +1 @@
8002f87d96b3f885cd208e7d204907a33ba60c4057ce2338b71e2de41215b0e5
57508518ef9d003d259ba98dcc32e5104aca26731a7161808741fe10bc0830d0

View File

@ -1123,7 +1123,7 @@ static int dupedExprStructSize(Expr *p, int flags){
assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
assert( EXPR_FULLSIZE<=0xfff );
assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
if( 0==flags || p->op==TK_SELECT_COLUMN || p->op==TK_TRUEFALSE ){
if( 0==flags || p->op==TK_SELECT_COLUMN ){
nSize = EXPR_FULLSIZE;
}else{
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
@ -1743,14 +1743,22 @@ int sqlite3ExprIdToTrueFalse(Expr *pExpr){
|| sqlite3StrICmp(pExpr->u.zToken, "false")==0
){
pExpr->op = TK_TRUEFALSE;
pExpr->iTable = pExpr->u.zToken[4]==0;
pExpr->pTab = 0;
ExprSetProperty(pExpr, EP_NoReduce);
return 1;
}
return 0;
}
/*
** The argument is one of a TK_TRUEFALSE term. Return 1 if it is TRUE
** and 0 if it is FALSE.
*/
int sqlite3ExprTruthOperand(const Expr *pExpr){
assert( pExpr->op==TK_TRUEFALSE );
assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0
|| sqlite3StrICmp(pExpr->u.zToken,"false")==0 );
return pExpr->u.zToken[4]==0;
}
/*
** These routines are Walker callbacks used to check expressions to
@ -3570,7 +3578,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
return target;
}
case TK_TRUEFALSE: {
sqlite3VdbeAddOp2(v, OP_Integer, pExpr->iTable, target);
sqlite3VdbeAddOp2(v, OP_Integer, sqlite3ExprTruthOperand(pExpr), target);
return target;
}
#ifndef SQLITE_OMIT_FLOATING_POINT
@ -3729,13 +3737,12 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
break;
}
case TK_TRUTH: {
assert( pExpr->pRight->op==TK_TRUEFALSE );
assert( pExpr->pRight->iTable==0 || pExpr->pRight->iTable==1 );
assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT );
int isTrue;
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
testcase( regFree1==0 );
sqlite3VdbeAddOp4Int(v, OP_IsTrue, r1, inReg, !pExpr->pRight->iTable,
pExpr->pRight->iTable ^ (pExpr->op2==TK_IS));
isTrue = sqlite3ExprTruthOperand(pExpr->pRight);
sqlite3VdbeAddOp4Int(v, OP_IsTrue, r1, inReg, !isTrue,
isTrue ^ (pExpr->op2==TK_IS));
break;
}
case TK_ISNULL:
@ -4515,13 +4522,13 @@ void sqlite3ExprIfTrue(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
}
case TK_TRUTH: {
int isNot;
int isTrue;
testcase( jumpIfNull==0 );
assert( pExpr->pRight->op==TK_TRUEFALSE );
assert( pExpr->pRight->iTable==0 || pExpr->pRight->iTable==1 );
testcase( pExpr->pRight->iTable==0 );
assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT );
isNot = pExpr->op2==TK_ISNOT;
if( pExpr->pRight->iTable ^ isNot ){
isTrue = sqlite3ExprTruthOperand(pExpr->pRight);
testcase( isTrue && isNot );
testcase( isTrue && !isNot );
if( isTrue ^ isNot ){
sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest,
isNot ? SQLITE_JUMPIFNULL : 0);
}else{
@ -4685,15 +4692,15 @@ void sqlite3ExprIfFalse(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
break;
}
case TK_TRUTH: {
testcase( jumpIfNull==0 );
int isNot;
int isTrue;
testcase( jumpIfNull==0 );
assert( pExpr->pRight->op==TK_TRUEFALSE );
assert( pExpr->pRight->iTable==0 || pExpr->pRight->iTable==1 );
testcase( pExpr->pRight->iTable==0 );
assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT );
isNot = pExpr->op2==TK_ISNOT;
if( pExpr->pRight->iTable ^ isNot ){
isTrue = sqlite3ExprTruthOperand(pExpr->pRight);
testcase( isTrue && isNot );
testcase( isTrue && !isNot );
if( isTrue ^ isNot ){
/* IS TRUE and IS NOT FALSE */
sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest,
isNot ? 0 : SQLITE_JUMPIFNULL);

View File

@ -314,7 +314,7 @@ ccons ::= DEFAULT MINUS(A) term(X) scanpt(Z). {
ccons ::= DEFAULT scanpt id(X). {
Expr *p = tokenExpr(pParse, TK_STRING, X);
sqlite3ExprIdToTrueFalse(p);
testcase( p->op==TK_TRUEFALSE && p->iTable==0 );
testcase( p->op==TK_TRUEFALSE && sqlite3ExprTruthOperand(p) );
sqlite3AddDefaultValue(pParse,p,X.z,X.z+X.n);
}

View File

@ -799,7 +799,6 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
int rc = resolveExprStep(pWalker, pRight);
if( rc==WRC_Abort ) return WRC_Abort;
if( pRight->op==TK_TRUEFALSE ){
assert( pRight->iTable==0 || pRight->iTable==1 );
pExpr->op2 = pExpr->op;
pExpr->op = TK_TRUTH;
return WRC_Continue;

View File

@ -2387,8 +2387,7 @@ struct Expr {
** TK_REGISTER: register number
** TK_TRIGGER: 1 -> new, 0 -> old
** EP_Unlikely: 134217728 times likelihood
** TK_SELECT: 1st register of result vector
** TK_TRUEFALSE: 1 for true, 0 for false */
** TK_SELECT: 1st register of result vector */
ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
** TK_VARIABLE: variable number (always >= 1).
** TK_SELECT_COLUMN: column of the result vector */
@ -3841,6 +3840,7 @@ void sqlite3Savepoint(Parse*, int, Token*);
void sqlite3CloseSavepoints(sqlite3 *);
void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
int sqlite3ExprIdToTrueFalse(Expr*);
int sqlite3ExprTruthOperand(const Expr*);
int sqlite3ExprIsConstant(Expr*);
int sqlite3ExprIsConstantNotJoin(Expr*);
int sqlite3ExprIsConstantOrFunction(Expr*, u8);

View File

@ -293,7 +293,8 @@ void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
break;
}
case TK_TRUEFALSE: {
sqlite3TreeViewLine(pView, pExpr->iTable ? "TRUE":"FALSE");
sqlite3TreeViewLine(pView,
sqlite3ExprTruthOperand(pExpr) ? "TRUE" : "FALSE");
break;
}
#ifndef SQLITE_OMIT_BLOB_LITERAL
@ -353,16 +354,15 @@ void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
case TK_NOTNULL: zUniOp = "NOTNULL"; break;
case TK_TRUTH: {
int x;
const char *azOp[] = {
"IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE"
};
assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT );
assert( pExpr->pRight );
assert( pExpr->pRight->op==TK_TRUEFALSE );
assert( pExpr->pRight->iTable==0 || pExpr->pRight->iTable==1 );
switch( (pExpr->op2==TK_ISNOT)*2 + pExpr->pRight->iTable ){
case 0: zUniOp = "IS-FALSE"; break;
case 1: zUniOp = "IS-TRUE"; break;
case 2: zUniOp = "IS-NOT-FALSE"; break;
case 3: zUniOp = "IS-NOT-TRUE"; break;
}
x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthOperand(pExpr->pRight);
zUniOp = azOp[x];
break;
}

View File

@ -88,5 +88,39 @@ do_execsql_test istrue-500 {
INSERT INTO t2 DEFAULT VALUES;
SELECT * FROM t2;
} {1 1 1 0 0}
do_execsql_test istrue-510 {
DROP TABLE t2;
CREATE TABLE t2(
a INTEGER PRIMARY KEY,
b BOOLEAN DEFAULT(not true),
c BOOLEAN DEFAULT(not false)
);
INSERT INTO t2(a) VALUES(99);
SELECT * FROM t2;
} {99 0 1}
do_execsql_test istrue-520 {
DROP TABLE t2;
CREATE TABLE t2(
a INTEGER PRIMARY KEY,
b BOOLEAN CHECK(b IS TRUE),
c BOOLEAN CHECK(c IS FALSE),
d BOOLEAN CHECK(d IS NOT TRUE),
e BOOLEAN CHECK(e IS NOT FALSE)
);
INSERT INTO t2 VALUES(1,true,false,null,null);
SELECT * FROM t2;
} {1 1 0 {} {}}
do_catchsql_test istrue-521 {
INSERT INTO t2 VALUES(2,false,false,null,null);
} {1 {CHECK constraint failed: t2}}
do_catchsql_test istrue-522 {
INSERT INTO t2 VALUES(2,true,true,null,null);
} {1 {CHECK constraint failed: t2}}
do_catchsql_test istrue-523 {
INSERT INTO t2 VALUES(2,true,false,true,null);
} {1 {CHECK constraint failed: t2}}
do_catchsql_test istrue-524 {
INSERT INTO t2 VALUES(2,true,false,null,false);
} {1 {CHECK constraint failed: t2}}
finish_test