diff options
author | drh <drh@noemail.net> | 2005-11-03 02:03:13 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2005-11-03 02:03:13 +0000 |
commit | 06f6541e2f53f07827dd68f688500e2ccdb45add (patch) | |
tree | 4d015e0c2234eaace11f10f2ca3ca9b9b835a1a7 /src | |
parent | 6275b88b9ef82432c725c8c6a8d65ba416cb46c5 (diff) | |
download | sqlite-06f6541e2f53f07827dd68f688500e2ccdb45add.tar.gz sqlite-06f6541e2f53f07827dd68f688500e2ccdb45add.zip |
Disallow subqueries in CHECK constraints. (CVS 2756)
FossilOrigin-Name: db27afc4cdc5b51c1fa0e83dbd6d4a4a69c5b642
Diffstat (limited to 'src')
-rw-r--r-- | src/build.c | 3 | ||||
-rw-r--r-- | src/expr.c | 7 | ||||
-rw-r--r-- | src/parse.y | 6 | ||||
-rw-r--r-- | src/sqliteInt.h | 3 |
4 files changed, 13 insertions, 6 deletions
diff --git a/src/build.c b/src/build.c index 11b7a039c..b6ecf0f65 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.353 2005/11/03 00:41:17 drh Exp $ +** $Id: build.c,v 1.354 2005/11/03 02:03:13 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -1307,6 +1307,7 @@ void sqlite3EndTable( sSrc.a[0].iCursor = -1; sNC.pParse = pParse; sNC.pSrcList = &sSrc; + sNC.isCheck = 1; if( sqlite3ExprResolveNames(&sNC, p->pCheck) ){ return; } diff --git a/src/expr.c b/src/expr.c index 88c48cfba..7ac839349 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.233 2005/11/03 00:41:17 drh Exp $ +** $Id: expr.c,v 1.234 2005/11/03 02:03:13 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -1188,6 +1188,11 @@ static int nameResolverStep(void *pArg, Expr *pExpr){ #endif case TK_IN: { if( pExpr->pSelect ){ +#ifndef SQLITE_OMIT_CHECK + if( pNC->isCheck ){ + sqlite3ErrorMsg(pParse,"subqueries prohibited in CHECK constraints"); + } +#endif int nRef = pNC->nRef; sqlite3SelectResolve(pParse, pExpr->pSelect, pNC); assert( pNC->nRef>=nRef ); diff --git a/src/parse.y b/src/parse.y index 490ceb2e2..b7a7e4518 100644 --- a/src/parse.y +++ b/src/parse.y @@ -14,7 +14,7 @@ ** the parser. Lemon will also generate a header file containing ** numeric codes for all of the tokens. ** -** @(#) $Id: parse.y,v 1.181 2005/11/03 00:41:17 drh Exp $ +** @(#) $Id: parse.y,v 1.182 2005/11/03 02:03:13 drh Exp $ */ // All token codes are small integers with #defines that begin with "TK_" @@ -268,7 +268,7 @@ ccons ::= NOT NULL onconf(R). {sqlite3AddNotNull(pParse, R);} ccons ::= PRIMARY KEY sortorder onconf(R) autoinc(I). {sqlite3AddPrimaryKey(pParse,0,R,I);} ccons ::= UNIQUE onconf(R). {sqlite3CreateIndex(pParse,0,0,0,0,R,0,0);} -ccons ::= CHECK LP expr(X) RP. {sqlite3AddCheckConstraint(pParse, X);} +ccons ::= CHECK LP expr(X) RP. {sqlite3AddCheckConstraint(pParse,X);} ccons ::= REFERENCES nm(T) idxlist_opt(TA) refargs(R). {sqlite3CreateForeignKey(pParse,0,&T,TA,R);} ccons ::= defer_subclause(D). {sqlite3DeferForeignKey(pParse,D);} @@ -318,7 +318,7 @@ tcons ::= PRIMARY KEY LP idxlist(X) autoinc(I) RP onconf(R). {sqlite3AddPrimaryKey(pParse,X,R,I);} tcons ::= UNIQUE LP idxlist(X) RP onconf(R). {sqlite3CreateIndex(pParse,0,0,0,X,R,0,0);} -tcons ::= CHECK expr onconf. +tcons ::= CHECK LP expr(E) RP onconf. {sqlite3AddCheckConstraint(pParse,E);} tcons ::= FOREIGN KEY LP idxlist(FA) RP REFERENCES nm(T) idxlist_opt(TA) refargs(R) defer_subclause_opt(D). { sqlite3CreateForeignKey(pParse, FA, &T, TA, R); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 048d07074..3cb1aef99 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.425 2005/11/03 00:41:17 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.426 2005/11/03 02:03:13 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -1088,6 +1088,7 @@ struct NameContext { int nErr; /* Number of errors encountered while resolving names */ u8 allowAgg; /* Aggregate functions allowed here */ u8 hasAgg; /* True if aggregates are seen */ + u8 isCheck; /* True if resolving names in a CHECK constraint */ int nDepth; /* Depth of subquery recursion. 1 for no recursion */ AggInfo *pAggInfo; /* Information about aggregates at this level */ NameContext *pNext; /* Next outer name context. NULL for outermost */ |