1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Refinements in expression handling logic that have resulted from recent

structural testing. (CVS 6690)

FossilOrigin-Name: bd89f2c29b00e6b473f30c2e929d2f626721ad92
This commit is contained in:
drh
2009-05-29 14:39:07 +00:00
parent 9fe769f129
commit fd773cf970
5 changed files with 51 additions and 39 deletions

View File

@ -1,5 +1,5 @@
C Still\smore\srefinements\sto\sthe\shasHotJournal()\sfix\sof\sticket\s#3883.\s(CVS\s6689) C Refinements\sin\sexpression\shandling\slogic\sthat\shave\sresulted\sfrom\srecent\nstructural\stesting.\s(CVS\s6690)
D 2009-05-29T11:57:38 D 2009-05-29T14:39:08
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -114,7 +114,7 @@ F src/callback.c 57359fa93de47c341b6b8ee504a88ff276397686
F src/complete.c 5ad5c6cd4548211867c204c41a126d73a9fbcea0 F src/complete.c 5ad5c6cd4548211867c204c41a126d73a9fbcea0
F src/date.c ab5f7137656652a48434d64f96bdcdc823bb23b3 F src/date.c ab5f7137656652a48434d64f96bdcdc823bb23b3
F src/delete.c cb791855c7948cecc96def9d97989879ca26f257 F src/delete.c cb791855c7948cecc96def9d97989879ca26f257
F src/expr.c 9d25d7229719334dc87909f8094b10d033b994f1 F src/expr.c ba5ba6a6332ec07d81cda97585dabf6c88bffbab
F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff
F src/func.c 9d7b47729c337c5e4b78d795922ed34eec4aef67 F src/func.c 9d7b47729c337c5e4b78d795922ed34eec4aef67
F src/global.c 448419c44ce0701104c2121b0e06919b44514c0c F src/global.c 448419c44ce0701104c2121b0e06919b44514c0c
@ -156,7 +156,7 @@ F src/pragma.c d4a6fd74fd1dba0f22c8930791f7fbbe80d2ef26
F src/prepare.c f46d1a029760edee5447e27164fb3ae10e2a6839 F src/prepare.c f46d1a029760edee5447e27164fb3ae10e2a6839
F src/printf.c 3f4dca207a88258d37af5a7a03e800a825fe6456 F src/printf.c 3f4dca207a88258d37af5a7a03e800a825fe6456
F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628 F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628
F src/resolve.c fc6fdd01305518fd1462e1621213e63bd011a115 F src/resolve.c 42065c05d4dd56894d1ae232974668674435e468
F src/rowset.c c64dafba1f9fd876836c8db8682966b9d197eb1f F src/rowset.c c64dafba1f9fd876836c8db8682966b9d197eb1f
F src/select.c fd1737a667bab296f50049a841b3aba5ec89418e F src/select.c fd1737a667bab296f50049a841b3aba5ec89418e
F src/shell.c 7eacd0bdaa887931f5ff205c9defc3e8df95a2dd F src/shell.c 7eacd0bdaa887931f5ff205c9defc3e8df95a2dd
@ -226,7 +226,7 @@ F test/async.test c042ff6d2a29f65e05d498a52448229d25bb5d9d
F test/async2.test bf5e2ca2c96763b4cba3d016249ad7259a5603b6 F test/async2.test bf5e2ca2c96763b4cba3d016249ad7259a5603b6
F test/async3.test 93edaa9122f498e56ea98c36c72abc407f4fb11e F test/async3.test 93edaa9122f498e56ea98c36c72abc407f4fb11e
F test/async4.test bdb997924394a2034ff3df1d839ff95b2e602ed4 F test/async4.test bdb997924394a2034ff3df1d839ff95b2e602ed4
F test/attach.test e710d543769305942e9354cee5aba8cfcbe89577 F test/attach.test 1d1be27b9e4c654f9bb14d011a4a87753c0b197a
F test/attach2.test a295d2d7061adcee5884ef4a93c7c96a82765437 F test/attach2.test a295d2d7061adcee5884ef4a93c7c96a82765437
F test/attach3.test 7b92dc8e40c1ebca9732ca6f2d3fefbd46f196df F test/attach3.test 7b92dc8e40c1ebca9732ca6f2d3fefbd46f196df
F test/attachmalloc.test cf8cf17d183de357b1147a9baacbdfc85b940b61 F test/attachmalloc.test cf8cf17d183de357b1147a9baacbdfc85b940b61
@ -731,7 +731,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P a2ba61d927a06c390a9a818a013328092b802222 P 726b425e43e5d864e7e83853bdf134debc1ffb59
R df5faf03661654bce8e5953dac271838 R 7782c740d0e684d85e0d73fa4ed3175a
U drh U drh
Z c67a8bef852bbf3b9d8397d68afe4414 Z 3b276276ba95400e6569bffb7e01828d

View File

@ -1 +1 @@
726b425e43e5d864e7e83853bdf134debc1ffb59 bd89f2c29b00e6b473f30c2e929d2f626721ad92

View File

@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and ** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite. ** for generating VDBE code that evaluates expressions in SQLite.
** **
** $Id: expr.c,v 1.439 2009/05/28 21:04:38 drh Exp $ ** $Id: expr.c,v 1.440 2009/05/29 14:39:08 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@ -1378,7 +1378,7 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){
** ephemeral table. ** ephemeral table.
*/ */
p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0); p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
if( pParse->nErr==0 && isCandidateForInOpt(p) ){ if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
sqlite3 *db = pParse->db; /* Database connection */ sqlite3 *db = pParse->db; /* Database connection */
Expr *pExpr = p->pEList->a[0].pExpr; /* Expression <column> */ Expr *pExpr = p->pEList->a[0].pExpr; /* Expression <column> */
int iCol = pExpr->iColumn; /* Index of column <column> */ int iCol = pExpr->iColumn; /* Index of column <column> */
@ -1489,17 +1489,29 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){
** to some integer key column of a table B-Tree. In this case, use an ** to some integer key column of a table B-Tree. In this case, use an
** intkey B-Tree to store the set of IN(...) values instead of the usual ** intkey B-Tree to store the set of IN(...) values instead of the usual
** (slower) variable length keys B-Tree. ** (slower) variable length keys B-Tree.
**
** If rMayHaveNull is non-zero, that means that the operation is an IN
** (not a SELECT or EXISTS) and that the RHS might contains NULLs.
** Furthermore, the IN is in a WHERE clause and that we really want
** to iterate over the RHS of the IN operator in order to quickly locate
** all corresponding LHS elements. All this routine does is initialize
** the register given by rMayHaveNull to NULL. Calling routines will take
** care of changing this register value to non-NULL if the RHS is NULL-free.
**
** If rMayHaveNull is zero, that means that the subquery is being used
** for membership testing only. There is no need to initialize any
** registers to indicate the presense or absence of NULLs on the RHS.
*/ */
#ifndef SQLITE_OMIT_SUBQUERY #ifndef SQLITE_OMIT_SUBQUERY
void sqlite3CodeSubselect( void sqlite3CodeSubselect(
Parse *pParse, Parse *pParse, /* Parsing context */
Expr *pExpr, Expr *pExpr, /* The IN, SELECT, or EXISTS operator */
int rMayHaveNull, int rMayHaveNull, /* Register that records whether NULLs exist in RHS */
int isRowid int isRowid /* If true, LHS of IN operator is a rowid */
){ ){
int testAddr = 0; /* One-time test address */ int testAddr = 0; /* One-time test address */
Vdbe *v = sqlite3GetVdbe(pParse); Vdbe *v = sqlite3GetVdbe(pParse);
if( v==0 ) return; if( NEVER(v==0) ) return;
sqlite3ExprCachePush(pParse); sqlite3ExprCachePush(pParse);
/* This code must be run in its entirety every time it is encountered /* This code must be run in its entirety every time it is encountered
@ -1567,11 +1579,11 @@ void sqlite3CodeSubselect(
return; return;
} }
pEList = pExpr->x.pSelect->pEList; pEList = pExpr->x.pSelect->pEList;
if( pEList && pEList->nExpr>0 ){ if( ALWAYS(pEList!=0 && pEList->nExpr>0) ){
keyInfo.aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft, keyInfo.aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
pEList->a[0].pExpr); pEList->a[0].pExpr);
} }
}else if( pExpr->x.pList ){ }else if( pExpr->x.pList!=0 ){
/* Case 2: expr IN (exprlist) /* Case 2: expr IN (exprlist)
** **
** For each expression, build an index key from the evaluation and ** For each expression, build an index key from the evaluation and
@ -1627,14 +1639,20 @@ void sqlite3CodeSubselect(
} }
case TK_EXISTS: case TK_EXISTS:
case TK_SELECT: { case TK_SELECT:
/* This has to be a scalar SELECT. Generate code to put the default: {
testcase( pExpr->op==TK_EXISTS );
testcase( pExpr->op==TK_SELECT );
assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
/* If this has to be a scalar SELECT. Generate code to put the
** value of this select in a memory cell and record the number ** value of this select in a memory cell and record the number
** of the memory cell in iColumn. ** of the memory cell in iColumn. If this is an EXISTS, write
** an integer 0 (not exists) or 1 (exists) into a memory cell
** and record that memory cell in iColumn.
*/ */
static const Token one = { "1", 1 }; static const Token one = { "1", 1 }; /* Token for literal value 1 */
Select *pSel; Select *pSel; /* SELECT statement to encode */
SelectDest dest; SelectDest dest; /* How to deal with SELECt result */
assert( ExprHasProperty(pExpr, EP_xIsSelect) ); assert( ExprHasProperty(pExpr, EP_xIsSelect) );
pSel = pExpr->x.pSelect; pSel = pExpr->x.pSelect;
@ -1688,8 +1706,7 @@ static char *dup8bytes(Vdbe *v, const char *in){
** like the continuation of the number. ** like the continuation of the number.
*/ */
static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){ static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){
assert( z || v==0 || sqlite3VdbeDb(v)->mallocFailed ); if( ALWAYS(z!=0) ){
if( z ){
double value; double value;
char *zV; char *zV;
sqlite3AtoF(z, &value); sqlite3AtoF(z, &value);
@ -1713,19 +1730,14 @@ static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){
** like the continuation of the number. ** like the continuation of the number.
*/ */
static void codeInteger(Vdbe *v, Expr *pExpr, int negFlag, int iMem){ static void codeInteger(Vdbe *v, Expr *pExpr, int negFlag, int iMem){
const char *z;
if( pExpr->flags & EP_IntValue ){ if( pExpr->flags & EP_IntValue ){
int i = pExpr->u.iValue; int i = pExpr->u.iValue;
if( negFlag ) i = -i; if( negFlag ) i = -i;
sqlite3VdbeAddOp2(v, OP_Integer, i, iMem); sqlite3VdbeAddOp2(v, OP_Integer, i, iMem);
}else if( (z = pExpr->u.zToken)!=0 ){ }else{
int i; const char *z = pExpr->u.zToken;
int n = sqlite3Strlen30(pExpr->u.zToken); assert( z!=0 );
assert( !sqlite3Isdigit(z[n]) ); if( sqlite3FitsIn64Bits(z, negFlag) ){
if( sqlite3GetInt32(z, &i) ){
if( negFlag ) i = -i;
sqlite3VdbeAddOp2(v, OP_Integer, i, iMem);
}else if( sqlite3FitsIn64Bits(z, negFlag) ){
i64 value; i64 value;
char *zV; char *zV;
sqlite3Atoi64(z, &value); sqlite3Atoi64(z, &value);

View File

@ -14,7 +14,7 @@
** resolve all identifiers by associating them with a particular ** resolve all identifiers by associating them with a particular
** table and column. ** table and column.
** **
** $Id: resolve.c,v 1.26 2009/05/28 14:34:50 drh Exp $ ** $Id: resolve.c,v 1.27 2009/05/29 14:39:08 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <stdlib.h> #include <stdlib.h>
@ -1127,7 +1127,7 @@ int sqlite3ResolveExprNames(
#if SQLITE_MAX_EXPR_DEPTH>0 #if SQLITE_MAX_EXPR_DEPTH>0
pNC->pParse->nHeight -= pExpr->nHeight; pNC->pParse->nHeight -= pExpr->nHeight;
#endif #endif
if( pNC->nErr>0 ){ if( pNC->nErr>0 || w.pParse->nErr>0 ){
ExprSetProperty(pExpr, EP_Error); ExprSetProperty(pExpr, EP_Error);
} }
if( pNC->hasAgg ){ if( pNC->hasAgg ){

View File

@ -12,7 +12,7 @@
# focus of this script is testing the ATTACH and DETACH commands # focus of this script is testing the ATTACH and DETACH commands
# and related functionality. # and related functionality.
# #
# $Id: attach.test,v 1.51 2009/05/28 01:00:56 drh Exp $ # $Id: attach.test,v 1.52 2009/05/29 14:39:08 drh Exp $
# #
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
@ -756,7 +756,7 @@ ifcapable subquery {
DETACH RAISE ( IGNORE ) IN ( SELECT "AAAAAA" . * ORDER BY DETACH RAISE ( IGNORE ) IN ( SELECT "AAAAAA" . * ORDER BY
REGISTER LIMIT "AAAAAA" . "AAAAAA" OFFSET RAISE ( IGNORE ) NOT NULL ) REGISTER LIMIT "AAAAAA" . "AAAAAA" OFFSET RAISE ( IGNORE ) NOT NULL )
} }
} {1 {invalid name: ""}} } {1 {no such table: AAAAAA}}
} }
# Create a malformed file (a file that is not a valid database) # Create a malformed file (a file that is not a valid database)