Skip to content

Commit d82218b

Browse files
committed
Fix a problem with using ALTER TABLE commands on database schemas that contain expressions of the form "<expr> NOT NULL" or "<expr> IS NULL" that can be evaluated at prepare time.
1 parent 9555b0b commit d82218b

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/resolve.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
807807
anRef[i] = p->nRef;
808808
}
809809
sqlite3WalkExpr(pWalker, pExpr->pLeft);
810-
if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) ){
810+
if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
811811
if( pExpr->op==TK_NOTNULL ){
812812
pExpr->u.zToken = "true";
813813
ExprSetProperty(pExpr, EP_IsTrue);

test/altercol.test

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
# file format change that may be used in the future to implement
1414
# "ALTER TABLE ... RENAME COLUMN ... TO".
1515
#
16-
# $Id: alter4.test,v 1.1 2009/02/02 18:03:22 drh Exp $
17-
#
1816

1917
set testdir [file dirname $argv0]
2018
source $testdir/tester.tcl
@@ -804,6 +802,25 @@ do_execsql_test 20.110 {
804802
SELECT sql FROM sqlite_master WHERE name='t1';
805803
} {{CREATE TABLE t1(xx UNIQUE,yy UNIQUE,zz UNIQUE,UNIQUE(xx),PRIMARY KEY(yy),UNIQUE(zz))}}
806804

805+
#-------------------------------------------------------------------------
806+
reset_db
807+
do_execsql_test 21.0 {
808+
CREATE TABLE t1(a, b, c NOT NULL);
809+
CREATE TRIGGER tr1 AFTER INSERT ON t1 WHEN new.c IS NOT NULL BEGIN
810+
SELECT c NOT NULL FROM t1;
811+
END;
812+
}
813+
814+
do_execsql_test 21.1 {
815+
ALTER TABLE t1 RENAME c TO d;
816+
}
817+
818+
do_execsql_test 21.2 {
819+
SELECT sql FROM sqlite_schema WHERE name IS 'tr1'
820+
} {{CREATE TRIGGER tr1 AFTER INSERT ON t1 WHEN new.d IS NOT NULL BEGIN
821+
SELECT d NOT NULL FROM t1;
822+
END}
823+
}
807824

808825

809826
finish_test

0 commit comments

Comments
 (0)