aboutsummaryrefslogtreecommitdiff
path: root/src/expr.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2014-09-24 13:20:22 +0000
committerdrh <drh@noemail.net>2014-09-24 13:20:22 +0000
commitfeada2df39af475b18055c117d4f3c75212dbbe5 (patch)
treebc4c682e39e718a24ea389ad16286d1412230bec /src/expr.c
parent9bfdc250622df58dd87e34566ccb23d5910b40a6 (diff)
downloadsqlite-feada2df39af475b18055c117d4f3c75212dbbe5.tar.gz
sqlite-feada2df39af475b18055c117d4f3c75212dbbe5.zip
Do not allow parameters in a DEFAULT clause of a CREATE TABLE statement.
Ticket [78c0c8c3c9f7c1]. FossilOrigin-Name: 1ad2bc1ed4c4ac81ac67a9660761f0eeb47c7fef
Diffstat (limited to 'src/expr.c')
-rw-r--r--src/expr.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/src/expr.c b/src/expr.c
index c8e8e7826..57e462ea6 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -1212,32 +1212,40 @@ void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
/*
** These routines are Walker callbacks. Walker.u.pi is a pointer
** to an integer. These routines are checking an expression to see
-** if it is a constant. Set *Walker.u.pi to 0 if the expression is
+** if it is a constant. Set *Walker.u.i to 0 if the expression is
** not constant.
**
** These callback routines are used to implement the following:
**
-** sqlite3ExprIsConstant()
-** sqlite3ExprIsConstantNotJoin()
-** sqlite3ExprIsConstantOrFunction()
+** sqlite3ExprIsConstant() pWalker->u.i==1
+** sqlite3ExprIsConstantNotJoin() pWalker->u.i==2
+** sqlite3ExprIsConstantOrFunction() pWalker->u.i==3 or 4
**
+** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions
+** in a CREATE TABLE statement. The Walker.u.i value is 4 when parsing
+** an existing schema and 3 when processing a new statement. A bound
+** parameter raises an error for new statements, but is silently converted
+** to NULL for existing schemas. This allows sqlite_master tables that
+** contain a bound parameter because they were generated by older versions
+** of SQLite to be parsed by newer versions of SQLite without raising a
+** malformed schema error.
*/
static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
- /* If pWalker->u.i is 3 then any term of the expression that comes from
+ /* If pWalker->u.i is 2 then any term of the expression that comes from
** the ON or USING clauses of a join disqualifies the expression
** from being considered constant. */
- if( pWalker->u.i==3 && ExprHasProperty(pExpr, EP_FromJoin) ){
+ if( pWalker->u.i==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
pWalker->u.i = 0;
return WRC_Abort;
}
switch( pExpr->op ){
/* Consider functions to be constant if all their arguments are constant
- ** and either pWalker->u.i==2 or the function as the SQLITE_FUNC_CONST
+ ** and either pWalker->u.i==3 or 4 or the function as the SQLITE_FUNC_CONST
** flag. */
case TK_FUNCTION:
- if( pWalker->u.i==2 || ExprHasProperty(pExpr,EP_Constant) ){
+ if( pWalker->u.i>=3 || ExprHasProperty(pExpr,EP_Constant) ){
return WRC_Continue;
}
/* Fall through */
@@ -1251,6 +1259,19 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
testcase( pExpr->op==TK_AGG_COLUMN );
pWalker->u.i = 0;
return WRC_Abort;
+ case TK_VARIABLE:
+ if( pWalker->u.i==4 ){
+ /* Silently convert bound parameters that appear inside of CREATE
+ ** statements into a NULL when parsing the CREATE statement text out
+ ** of the sqlite_master table */
+ pExpr->op = TK_NULL;
+ }else if( pWalker->u.i==3 ){
+ /* A bound parameter in a CREATE statement that originates from
+ ** sqlite3_prepare() causes an error */
+ pWalker->u.i = 0;
+ return WRC_Abort;
+ }
+ /* Fall through */
default:
testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */
testcase( pExpr->op==TK_EXISTS ); /* selectNodeIsConstant will disallow */
@@ -1291,7 +1312,7 @@ int sqlite3ExprIsConstant(Expr *p){
** an ON or USING clause.
*/
int sqlite3ExprIsConstantNotJoin(Expr *p){
- return exprIsConst(p, 3);
+ return exprIsConst(p, 2);
}
/*
@@ -1303,8 +1324,9 @@ int sqlite3ExprIsConstantNotJoin(Expr *p){
** is considered a variable but a single-quoted string (ex: 'abc') is
** a constant.
*/
-int sqlite3ExprIsConstantOrFunction(Expr *p){
- return exprIsConst(p, 2);
+int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){
+ assert( isInit==0 || isInit==1 );
+ return exprIsConst(p, 3+isInit);
}
/*