1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-10 01:02:56 +03:00

Always disallow the use of non-deterministic functions in CHECK constraints,

even date/time functions that use the 'now' or similar keywords.  Provide
improved error messages when this requirement is not met.
Ticket [830277d9db6c3ba1]

FossilOrigin-Name: 2978b65ebe25eeabe543b67cb266308cceb20082a4ae71565d6d083d7c08bc9f
This commit is contained in:
drh
2019-10-30 18:50:08 +00:00
parent 920cf596e6
commit 20cee7d0bb
10 changed files with 104 additions and 55 deletions

View File

@@ -815,15 +815,18 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){
/* For the purposes of the EP_ConstFunc flag, date and time
** functions and other functions that change slowly are considered
** constant because they are constant for the duration of one query */
** constant because they are constant for the duration of one query.
** This allows them to be factored out of inner loops. */
ExprSetProperty(pExpr,EP_ConstFunc);
}
if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
/* Date/time functions that use 'now', and other functions like
** sqlite_version() that might change over time cannot be used
** in an index. */
notValid(pParse, pNC, "non-deterministic functions",
NC_IdxExpr|NC_PartIdx|NC_GenCol);
notValid(pParse, pNC, "non-deterministic functions", NC_SelfRef);
}else{
assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
pExpr->op2 = pNC->ncFlags & NC_SelfRef;
}
if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
&& pParse->nested==0
@@ -1789,11 +1792,13 @@ void sqlite3ResolveSelectNames(
** Resolve names in expressions that can only reference a single table
** or which cannot reference any tables at all. Examples:
**
** (1) CHECK constraints
** (2) WHERE clauses on partial indices
** (3) Expressions in indexes on expressions
** (4) Expression arguments to VACUUM INTO.
** (5) GENERATED ALWAYS as expressions
** "type" flag
** ------------
** (1) CHECK constraints NC_IsCheck
** (2) WHERE clauses on partial indices NC_PartIdx
** (3) Expressions in indexes on expressions NC_IdxExpr
** (4) Expression arguments to VACUUM INTO. 0
** (5) GENERATED ALWAYS as expressions NC_GenCol
**
** In all cases except (4), the Expr.iTable value for Expr.op==TK_COLUMN
** nodes of the expression is set to -1 and the Expr.iColumn value is