1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-16 23:02:26 +03:00

Fix issues in the new ADD COLUMN constraint checking. Add preliminary

test cases.

FossilOrigin-Name: 48434ad3fa9504c063d812d119bc8f622548fd02b3d478ff247b11474c4ce5db
This commit is contained in:
drh
2021-07-20 08:23:54 +00:00
parent b4d9b2b537
commit 0f91a5352b
6 changed files with 62 additions and 22 deletions

View File

@@ -446,16 +446,16 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
renameReloadSchema(pParse, iDb, INITFLAG_AlterRename);
/* Verify that constraints are still satisfied */
if( pParse->bDiscardCheck
if( pNew->pCheck!=0
|| (pCol->notNull && (pCol->colFlags & COLFLAG_GENERATED)!=0)
){
sqlite3NestedParse(pParse,
"SELECT CASE WHEN quick_check GLOB 'CHECK*'"
" THEN raise(ABORT,'CHECK constraint failed')"
" WHEN quick_check GLOB 'NULL*'"
" THEN raise(ABORT,'NOT NULL constraint failed')"
" ELSE raise(ABORT,'NOT NULL constraint failed')"
" END"
" FROM pragma_quick_check(\"%w\",\"%w\")",
" FROM pragma_quick_check(\"%w\",\"%w\")"
" WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*'",
zTab, zDb
);
}

View File

@@ -1769,7 +1769,6 @@ void sqlite3AddCheckConstraint(
}else
#endif
{
pParse->bDiscardCheck = 1;
sqlite3ExprDelete(pParse->db, pCheckExpr);
}
}

View File

@@ -3437,8 +3437,7 @@ struct Parse {
Vdbe *pVdbe; /* An engine for executing database bytecode */
int rc; /* Return code from execution */
u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
u8 checkSchema : 1; /* Causes schema cookie check after an error */
u8 bDiscardCheck :1; /* A CHECK constraint was discarded by the parser */
u8 checkSchema; /* Causes schema cookie check after an error */
u8 nested; /* Number of nested calls to the parser/code generator */
u8 nTempReg; /* Number of temporary registers in aTempReg[] */
u8 isMultiWrite; /* True if statement may modify/insert multiple rows */