Overview
| SHA1 Hash: | 5461104668a49529577f21df97f6a0e7d8f0c679 |
|---|---|
| Date: | 2013-02-09 13:58:25 |
| User: | drh |
| Comment: | Add extended error codes for constraint errors. |
Tags And Properties
- branch=constraint-error-codes propagates to descendants
- sym-constraint-error-codes propagates to descendants
- sym-trunk cancelled
Changes
Changes to src/build.c
2443 sqlite3VdbeJumpHere(v, addr1); 2443 sqlite3VdbeJumpHere(v, addr1); 2444 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); 2444 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); 2445 if( pIndex->onError!=OE_None ){ 2445 if( pIndex->onError!=OE_None ){ 2446 int j2 = sqlite3VdbeCurrentAddr(v) + 3; 2446 int j2 = sqlite3VdbeCurrentAddr(v) + 3; 2447 sqlite3VdbeAddOp2(v, OP_Goto, 0, j2); 2447 sqlite3VdbeAddOp2(v, OP_Goto, 0, j2); 2448 addr2 = sqlite3VdbeCurrentAddr(v); 2448 addr2 = sqlite3VdbeCurrentAddr(v); 2449 sqlite3VdbeAddOp3(v, OP_SorterCompare, iSorter, j2, regRecord); 2449 sqlite3VdbeAddOp3(v, OP_SorterCompare, iSorter, j2, regRecord); 2450 sqlite3HaltConstraint( | 2450 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_UNIQUE, 2451 pParse, OE_Abort, "indexed columns are not unique", P4_STATIC | 2451 OE_Abort, "indexed columns are not unique", P4_STATIC 2452 ); 2452 ); 2453 }else{ 2453 }else{ 2454 addr2 = sqlite3VdbeCurrentAddr(v); 2454 addr2 = sqlite3VdbeCurrentAddr(v); 2455 } 2455 } 2456 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord); 2456 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord); 2457 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1); 2457 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1); 2458 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); 2458 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); ................................................................................................................................................................................ 2470 ** (made available to the compiler for reuse) using 2470 ** (made available to the compiler for reuse) using 2471 ** sqlite3ReleaseTempRange(). So in some ways having the OP_IsUnique 2471 ** sqlite3ReleaseTempRange(). So in some ways having the OP_IsUnique 2472 ** opcode use the values stored within seems dangerous. However, since 2472 ** opcode use the values stored within seems dangerous. However, since 2473 ** we can be sure that no other temp registers have been allocated 2473 ** we can be sure that no other temp registers have been allocated 2474 ** since sqlite3ReleaseTempRange() was called, it is safe to do so. 2474 ** since sqlite3ReleaseTempRange() was called, it is safe to do so. 2475 */ 2475 */ 2476 sqlite3VdbeAddOp4(v, OP_IsUnique, iIdx, j2, regRowid, pRegKey, P4_INT32); 2476 sqlite3VdbeAddOp4(v, OP_IsUnique, iIdx, j2, regRowid, pRegKey, P4_INT32); 2477 sqlite3HaltConstraint( | 2477 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_UNIQUE, 2478 pParse, OE_Abort, "indexed columns are not unique", P4_STATIC); | 2478 "indexed columns are not unique", P4_STATIC); 2479 } 2479 } 2480 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0); 2480 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0); 2481 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); 2481 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); 2482 #endif 2482 #endif 2483 sqlite3ReleaseTempReg(pParse, regRecord); 2483 sqlite3ReleaseTempReg(pParse, regRecord); 2484 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); 2484 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); 2485 sqlite3VdbeJumpHere(v, addr1); 2485 sqlite3VdbeJumpHere(v, addr1); ................................................................................................................................................................................ 3688 } 3688 } 3689 3689 3690 /* 3690 /* 3691 ** Code an OP_Halt that causes the vdbe to return an SQLITE_CONSTRAINT 3691 ** Code an OP_Halt that causes the vdbe to return an SQLITE_CONSTRAINT 3692 ** error. The onError parameter determines which (if any) of the statement 3692 ** error. The onError parameter determines which (if any) of the statement 3693 ** and/or current transaction is rolled back. 3693 ** and/or current transaction is rolled back. 3694 */ 3694 */ 3695 void sqlite3HaltConstraint(Parse *pParse, int onError, char *p4, int p4type){ | 3695 void sqlite3HaltConstraint( > 3696 Parse *pParse, /* Parsing context */ > 3697 int errCode, /* extended error code */ > 3698 int onError, /* Constraint type */ > 3699 char *p4, /* Error message */ > 3700 int p4type /* P4_STATIC or P4_TRANSIENT */ > 3701 ){ 3696 Vdbe *v = sqlite3GetVdbe(pParse); 3702 Vdbe *v = sqlite3GetVdbe(pParse); > 3703 assert( (errCode&0xff)==SQLITE_CONSTRAINT ); 3697 if( onError==OE_Abort ){ 3704 if( onError==OE_Abort ){ 3698 sqlite3MayAbort(pParse); 3705 sqlite3MayAbort(pParse); 3699 } 3706 } 3700 sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CONSTRAINT, onError, 0, p4, p4type); | 3707 sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type); 3701 } 3708 } 3702 3709 3703 /* 3710 /* 3704 ** Check to see if pIndex uses the collating sequence pColl. Return 3711 ** Check to see if pIndex uses the collating sequence pColl. Return 3705 ** true if it does and false if it does not. 3712 ** true if it does and false if it does not. 3706 */ 3713 */ 3707 #ifndef SQLITE_OMIT_REINDEX 3714 #ifndef SQLITE_OMIT_REINDEX
Changes to src/expr.c
2931 sqlite3MayAbort(pParse); 2931 sqlite3MayAbort(pParse); 2932 } 2932 } 2933 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 2933 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 2934 if( pExpr->affinity==OE_Ignore ){ 2934 if( pExpr->affinity==OE_Ignore ){ 2935 sqlite3VdbeAddOp4( 2935 sqlite3VdbeAddOp4( 2936 v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0); 2936 v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0); 2937 }else{ 2937 }else{ > 2938 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_RAISE, 2938 sqlite3HaltConstraint(pParse, pExpr->affinity, pExpr->u.zToken, 0); | 2939 pExpr->affinity, pExpr->u.zToken, 0); 2939 } 2940 } 2940 2941 2941 break; 2942 break; 2942 } 2943 } 2943 #endif 2944 #endif 2944 } 2945 } 2945 sqlite3ReleaseTempReg(pParse, regFree1); 2946 sqlite3ReleaseTempReg(pParse, regFree1);
Changes to src/fkey.c
17 #ifndef SQLITE_OMIT_TRIGGER 17 #ifndef SQLITE_OMIT_TRIGGER 18 18 19 /* 19 /* 20 ** Deferred and Immediate FKs 20 ** Deferred and Immediate FKs 21 ** -------------------------- 21 ** -------------------------- 22 ** 22 ** 23 ** Foreign keys in SQLite come in two flavours: deferred and immediate. 23 ** Foreign keys in SQLite come in two flavours: deferred and immediate. 24 ** If an immediate foreign key constraint is violated, SQLITE_CONSTRAINT | 24 ** If an immediate foreign key constraint is violated, > 25 ** SQLITE_CONSTRAINT_FOREIGNKEY is returned and the current 25 ** is returned and the current statement transaction rolled back. If a | 26 ** statement transaction rolled back. If a 26 ** deferred foreign key constraint is violated, no action is taken 27 ** deferred foreign key constraint is violated, no action is taken 27 ** immediately. However if the application attempts to commit the 28 ** immediately. However if the application attempts to commit the 28 ** transaction before fixing the constraint violation, the attempt fails. 29 ** transaction before fixing the constraint violation, the attempt fails. 29 ** 30 ** 30 ** Deferred constraints are implemented using a simple counter associated 31 ** Deferred constraints are implemented using a simple counter associated 31 ** with the database handle. The counter is set to zero each time a 32 ** with the database handle. The counter is set to zero each time a 32 ** database transaction is opened. Each time a statement is executed 33 ** database transaction is opened. Each time a statement is executed ................................................................................................................................................................................ 82 ** If a delete caused by OR REPLACE violates an FK constraint, an exception 83 ** If a delete caused by OR REPLACE violates an FK constraint, an exception 83 ** is thrown, even if the FK constraint would be satisfied after the new 84 ** is thrown, even if the FK constraint would be satisfied after the new 84 ** row is inserted. 85 ** row is inserted. 85 ** 86 ** 86 ** Immediate constraints are usually handled similarly. The only difference 87 ** Immediate constraints are usually handled similarly. The only difference 87 ** is that the counter used is stored as part of each individual statement 88 ** is that the counter used is stored as part of each individual statement 88 ** object (struct Vdbe). If, after the statement has run, its immediate 89 ** object (struct Vdbe). If, after the statement has run, its immediate 89 ** constraint counter is greater than zero, it returns SQLITE_CONSTRAINT | 90 ** constraint counter is greater than zero, > 91 ** it returns SQLITE_CONSTRAINT_FOREIGNKEY 90 ** and the statement transaction is rolled back. An exception is an INSERT 92 ** and the statement transaction is rolled back. An exception is an INSERT 91 ** statement that inserts a single row only (no triggers). In this case, 93 ** statement that inserts a single row only (no triggers). In this case, 92 ** instead of using a counter, an exception is thrown immediately if the 94 ** instead of using a counter, an exception is thrown immediately if the 93 ** INSERT violates a foreign key constraint. This is necessary as such 95 ** INSERT violates a foreign key constraint. This is necessary as such 94 ** an INSERT does not open a statement transaction. 96 ** an INSERT does not open a statement transaction. 95 ** 97 ** 96 ** TODO: How should dropping a table be handled? How should renaming a 98 ** TODO: How should dropping a table be handled? How should renaming a ................................................................................................................................................................................ 422 424 423 if( !pFKey->isDeferred && !pParse->pToplevel && !pParse->isMultiWrite ){ 425 if( !pFKey->isDeferred && !pParse->pToplevel && !pParse->isMultiWrite ){ 424 /* Special case: If this is an INSERT statement that will insert exactly 426 /* Special case: If this is an INSERT statement that will insert exactly 425 ** one row into the table, raise a constraint immediately instead of 427 ** one row into the table, raise a constraint immediately instead of 426 ** incrementing a counter. This is necessary as the VM code is being 428 ** incrementing a counter. This is necessary as the VM code is being 427 ** generated for will not open a statement transaction. */ 429 ** generated for will not open a statement transaction. */ 428 assert( nIncr==1 ); 430 assert( nIncr==1 ); 429 sqlite3HaltConstraint( | 431 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY, 430 pParse, OE_Abort, "foreign key constraint failed", P4_STATIC | 432 OE_Abort, "foreign key constraint failed", P4_STATIC 431 ); 433 ); 432 }else{ 434 }else{ 433 if( nIncr>0 && pFKey->isDeferred==0 ){ 435 if( nIncr>0 && pFKey->isDeferred==0 ){ 434 sqlite3ParseToplevel(pParse)->mayAbort = 1; 436 sqlite3ParseToplevel(pParse)->mayAbort = 1; 435 } 437 } 436 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr); 438 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr); 437 } 439 } ................................................................................................................................................................................ 663 pParse->disableTriggers = 0; 665 pParse->disableTriggers = 0; 664 666 665 /* If the DELETE has generated immediate foreign key constraint 667 /* If the DELETE has generated immediate foreign key constraint 666 ** violations, halt the VDBE and return an error at this point, before 668 ** violations, halt the VDBE and return an error at this point, before 667 ** any modifications to the schema are made. This is because statement 669 ** any modifications to the schema are made. This is because statement 668 ** transactions are not able to rollback schema changes. */ 670 ** transactions are not able to rollback schema changes. */ 669 sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2); 671 sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2); 670 sqlite3HaltConstraint( | 672 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY, 671 pParse, OE_Abort, "foreign key constraint failed", P4_STATIC | 673 OE_Abort, "foreign key constraint failed", P4_STATIC 672 ); 674 ); 673 675 674 if( iSkip ){ 676 if( iSkip ){ 675 sqlite3VdbeResolveLabel(v, iSkip); 677 sqlite3VdbeResolveLabel(v, iSkip); 676 } 678 } 677 } 679 } 678 } 680 }
Changes to src/insert.c
1241 switch( onError ){ 1241 switch( onError ){ 1242 case OE_Abort: 1242 case OE_Abort: 1243 sqlite3MayAbort(pParse); 1243 sqlite3MayAbort(pParse); 1244 case OE_Rollback: 1244 case OE_Rollback: 1245 case OE_Fail: { 1245 case OE_Fail: { 1246 char *zMsg; 1246 char *zMsg; 1247 sqlite3VdbeAddOp3(v, OP_HaltIfNull, 1247 sqlite3VdbeAddOp3(v, OP_HaltIfNull, 1248 SQLITE_CONSTRAINT, onError, regData+i); | 1248 SQLITE_CONSTRAINT_NOTNULL, onError, regData+i); 1249 zMsg = sqlite3MPrintf(db, "%s.%s may not be NULL", 1249 zMsg = sqlite3MPrintf(db, "%s.%s may not be NULL", 1250 pTab->zName, pTab->aCol[i].zName); 1250 pTab->zName, pTab->aCol[i].zName); 1251 sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC); 1251 sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC); 1252 break; 1252 break; 1253 } 1253 } 1254 case OE_Ignore: { 1254 case OE_Ignore: { 1255 sqlite3VdbeAddOp2(v, OP_IsNull, regData+i, ignoreDest); 1255 sqlite3VdbeAddOp2(v, OP_IsNull, regData+i, ignoreDest); ................................................................................................................................................................................ 1281 char *zConsName = pCheck->a[i].zName; 1281 char *zConsName = pCheck->a[i].zName; 1282 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ 1282 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ 1283 if( zConsName ){ 1283 if( zConsName ){ 1284 zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName); 1284 zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName); 1285 }else{ 1285 }else{ 1286 zConsName = 0; 1286 zConsName = 0; 1287 } 1287 } > 1288 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK, 1288 sqlite3HaltConstraint(pParse, onError, zConsName, P4_DYNAMIC); | 1289 onError, zConsName, P4_DYNAMIC); 1289 } 1290 } 1290 sqlite3VdbeResolveLabel(v, allOk); 1291 sqlite3VdbeResolveLabel(v, allOk); 1291 } 1292 } 1292 } 1293 } 1293 #endif /* !defined(SQLITE_OMIT_CHECK) */ 1294 #endif /* !defined(SQLITE_OMIT_CHECK) */ 1294 1295 1295 /* If we have an INTEGER PRIMARY KEY, make sure the primary key 1296 /* If we have an INTEGER PRIMARY KEY, make sure the primary key ................................................................................................................................................................................ 1312 default: { 1313 default: { 1313 onError = OE_Abort; 1314 onError = OE_Abort; 1314 /* Fall thru into the next case */ 1315 /* Fall thru into the next case */ 1315 } 1316 } 1316 case OE_Rollback: 1317 case OE_Rollback: 1317 case OE_Abort: 1318 case OE_Abort: 1318 case OE_Fail: { 1319 case OE_Fail: { 1319 sqlite3HaltConstraint( | 1320 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_PRIMARYKEY, 1320 pParse, onError, "PRIMARY KEY must be unique", P4_STATIC); | 1321 onError, "PRIMARY KEY must be unique", P4_STATIC); 1321 break; 1322 break; 1322 } 1323 } 1323 case OE_Replace: { 1324 case OE_Replace: { 1324 /* If there are DELETE triggers on this table and the 1325 /* If there are DELETE triggers on this table and the 1325 ** recursive-triggers flag is set, call GenerateRowDelete() to 1326 ** recursive-triggers flag is set, call GenerateRowDelete() to 1326 ** remove the conflicting row from the table. This will fire 1327 ** remove the conflicting row from the table. This will fire 1327 ** the triggers and remove both the table and index b-tree entries. 1328 ** the triggers and remove both the table and index b-tree entries. ................................................................................................................................................................................ 1440 sqlite3StrAccumAppend(&errMsg, zSep, -1); 1441 sqlite3StrAccumAppend(&errMsg, zSep, -1); 1441 zSep = ", "; 1442 zSep = ", "; 1442 sqlite3StrAccumAppend(&errMsg, zCol, -1); 1443 sqlite3StrAccumAppend(&errMsg, zCol, -1); 1443 } 1444 } 1444 sqlite3StrAccumAppend(&errMsg, 1445 sqlite3StrAccumAppend(&errMsg, 1445 pIdx->nColumn>1 ? " are not unique" : " is not unique", -1); 1446 pIdx->nColumn>1 ? " are not unique" : " is not unique", -1); 1446 zErr = sqlite3StrAccumFinish(&errMsg); 1447 zErr = sqlite3StrAccumFinish(&errMsg); 1447 sqlite3HaltConstraint(pParse, onError, zErr, 0); | 1448 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_UNIQUE, > 1449 onError, zErr, 0); 1448 sqlite3DbFree(errMsg.db, zErr); 1450 sqlite3DbFree(errMsg.db, zErr); 1449 break; 1451 break; 1450 } 1452 } 1451 case OE_Ignore: { 1453 case OE_Ignore: { 1452 assert( seenReplace==0 ); 1454 assert( seenReplace==0 ); 1453 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); 1455 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); 1454 break; 1456 break; ................................................................................................................................................................................ 1848 sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead); 1850 sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead); 1849 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); 1851 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); 1850 regData = sqlite3GetTempReg(pParse); 1852 regData = sqlite3GetTempReg(pParse); 1851 regRowid = sqlite3GetTempReg(pParse); 1853 regRowid = sqlite3GetTempReg(pParse); 1852 if( pDest->iPKey>=0 ){ 1854 if( pDest->iPKey>=0 ){ 1853 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); 1855 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); 1854 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid); 1856 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid); 1855 sqlite3HaltConstraint( | 1857 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_PRIMARYKEY, 1856 pParse, onError, "PRIMARY KEY must be unique", P4_STATIC); | 1858 onError, "PRIMARY KEY must be unique", P4_STATIC); 1857 sqlite3VdbeJumpHere(v, addr2); 1859 sqlite3VdbeJumpHere(v, addr2); 1858 autoIncStep(pParse, regAutoinc, regRowid); 1860 autoIncStep(pParse, regAutoinc, regRowid); 1859 }else if( pDest->pIndex==0 ){ 1861 }else if( pDest->pIndex==0 ){ 1860 addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid); 1862 addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid); 1861 }else{ 1863 }else{ 1862 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); 1864 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); 1863 assert( (pDest->tabFlags & TF_Autoincrement)==0 ); 1865 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
Changes to src/sqlite.h.in
475 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) 475 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) 476 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) 476 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) 477 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) 477 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) 478 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) 478 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) 479 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) 479 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) 480 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) 480 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) 481 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) 481 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) > 482 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (1<<8)) > 483 #define SQLITE_CONSTRAINT_RAISE (SQLITE_CONSTRAINT | (2<<8)) > 484 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) > 485 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (4<<8)) > 486 #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (5<<8)) > 487 #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (6<<8)) > 488 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (7<<8)) > 489 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (8<<8)) > 490 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (9<<8)) 482 491 483 /* 492 /* 484 ** CAPI3REF: Flags For File Open Operations 493 ** CAPI3REF: Flags For File Open Operations 485 ** 494 ** 486 ** These bit values are intended for use in the 495 ** These bit values are intended for use in the 487 ** 3rd parameter to the [sqlite3_open_v2()] interface and 496 ** 3rd parameter to the [sqlite3_open_v2()] interface and 488 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method. 497 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
Changes to src/sqliteInt.h
2900 void sqlite3GenerateConstraintChecks(Parse*,Table*,int,int, 2900 void sqlite3GenerateConstraintChecks(Parse*,Table*,int,int, 2901 int*,int,int,int,int,int*); 2901 int*,int,int,int,int,int*); 2902 void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*, int, int, int); 2902 void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*, int, int, int); 2903 int sqlite3OpenTableAndIndices(Parse*, Table*, int, int); 2903 int sqlite3OpenTableAndIndices(Parse*, Table*, int, int); 2904 void sqlite3BeginWriteOperation(Parse*, int, int); 2904 void sqlite3BeginWriteOperation(Parse*, int, int); 2905 void sqlite3MultiWrite(Parse*); 2905 void sqlite3MultiWrite(Parse*); 2906 void sqlite3MayAbort(Parse*); 2906 void sqlite3MayAbort(Parse*); 2907 void sqlite3HaltConstraint(Parse*, int, char*, int); | 2907 void sqlite3HaltConstraint(Parse*, int, int, char*, int); 2908 Expr *sqlite3ExprDup(sqlite3*,Expr*,int); 2908 Expr *sqlite3ExprDup(sqlite3*,Expr*,int); 2909 ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int); 2909 ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int); 2910 SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int); 2910 SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int); 2911 IdList *sqlite3IdListDup(sqlite3*,IdList*); 2911 IdList *sqlite3IdListDup(sqlite3*,IdList*); 2912 Select *sqlite3SelectDup(sqlite3*,Select*,int); 2912 Select *sqlite3SelectDup(sqlite3*,Select*,int); 2913 void sqlite3FuncDefInsert(FuncDefHash*, FuncDef*); 2913 void sqlite3FuncDefInsert(FuncDefHash*, FuncDef*); 2914 FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,u8); 2914 FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,u8);
Changes to src/test1.c
134 case SQLITE_FULL: zName = "SQLITE_FULL"; break; 134 case SQLITE_FULL: zName = "SQLITE_FULL"; break; 135 case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break; 135 case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break; 136 case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break; 136 case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break; 137 case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break; 137 case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break; 138 case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break; 138 case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break; 139 case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break; 139 case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break; 140 case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break; 140 case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break; > 141 case SQLITE_CONSTRAINT_UNIQUE: zName = "SQLITE_CONSTRAINT_UNIQUE"; break; > 142 case SQLITE_CONSTRAINT_RAISE: zName = "SQLITE_CONSTRAINT_RAISE"; break; > 143 case SQLITE_CONSTRAINT_FOREIGNKEY: > 144 zName = "SQLITE_CONSTRAINT_FOREIGNKEY"; break; > 145 case SQLITE_CONSTRAINT_CHECK: zName = "SQLITE_CONSTRAINT_CHECK"; break; > 146 case SQLITE_CONSTRAINT_PRIMARYKEY: > 147 zName = "SQLITE_CONSTRAINT_PRIMARYKEY"; break; > 148 case SQLITE_CONSTRAINT_NOTNULL: zName = "SQLITE_CONSTRAINT_NOTNULL";break; > 149 case SQLITE_CONSTRAINT_COMMITHOOK: > 150 zName = "SQLITE_CONSTRAINT_COMMITHOOK"; break; > 151 case SQLITE_CONSTRAINT_VTAB: zName = "SQLITE_CONSTRAINT_VTAB"; break; > 152 case SQLITE_CONSTRAINT_FUNCTION: zName = "SQLITE_CONSTRAINT_FUNCTION";break; 141 case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break; 153 case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break; 142 case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break; 154 case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break; 143 case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break; 155 case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break; 144 case SQLITE_AUTH: zName = "SQLITE_AUTH"; break; 156 case SQLITE_AUTH: zName = "SQLITE_AUTH"; break; 145 case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break; 157 case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break; 146 case SQLITE_RANGE: zName = "SQLITE_RANGE"; break; 158 case SQLITE_RANGE: zName = "SQLITE_RANGE"; break; 147 case SQLITE_NOTADB: zName = "SQLITE_NOTADB"; break; 159 case SQLITE_NOTADB: zName = "SQLITE_NOTADB"; break;
Changes to src/test_spellfix.c
2669 ** cause zWord to be NULL, so we look at the "command" column to see 2669 ** cause zWord to be NULL, so we look at the "command" column to see 2670 ** what special actions to take */ 2670 ** what special actions to take */ 2671 const char *zCmd = 2671 const char *zCmd = 2672 (const char*)sqlite3_value_text(argv[SPELLFIX_COL_COMMAND+2]); 2672 (const char*)sqlite3_value_text(argv[SPELLFIX_COL_COMMAND+2]); 2673 if( zCmd==0 ){ 2673 if( zCmd==0 ){ 2674 pVTab->zErrMsg = sqlite3_mprintf("%s.word may not be NULL", 2674 pVTab->zErrMsg = sqlite3_mprintf("%s.word may not be NULL", 2675 p->zTableName); 2675 p->zTableName); 2676 return SQLITE_CONSTRAINT; | 2676 return SQLITE_CONSTRAINT_NOTNULL; 2677 } 2677 } 2678 if( strcmp(zCmd,"reset")==0 ){ 2678 if( strcmp(zCmd,"reset")==0 ){ 2679 /* Reset the edit cost table (if there is one). */ 2679 /* Reset the edit cost table (if there is one). */ 2680 editDist3ConfigDelete(p->pConfig3); 2680 editDist3ConfigDelete(p->pConfig3); 2681 p->pConfig3 = 0; 2681 p->pConfig3 = 0; 2682 return SQLITE_OK; 2682 return SQLITE_OK; 2683 } 2683 }
Changes to src/vdbe.c
865 sqlite3_log(pOp->p1, "constraint failed at %d in [%s]", pc, p->zSql); 865 sqlite3_log(pOp->p1, "constraint failed at %d in [%s]", pc, p->zSql); 866 } 866 } 867 rc = sqlite3VdbeHalt(p); 867 rc = sqlite3VdbeHalt(p); 868 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); 868 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); 869 if( rc==SQLITE_BUSY ){ 869 if( rc==SQLITE_BUSY ){ 870 p->rc = rc = SQLITE_BUSY; 870 p->rc = rc = SQLITE_BUSY; 871 }else{ 871 }else{ 872 assert( rc==SQLITE_OK || p->rc==SQLITE_CONSTRAINT ); | 872 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ); 873 assert( rc==SQLITE_OK || db->nDeferredCons>0 ); 873 assert( rc==SQLITE_OK || db->nDeferredCons>0 ); 874 rc = p->rc ? SQLITE_ERROR : SQLITE_DONE; 874 rc = p->rc ? SQLITE_ERROR : SQLITE_DONE; 875 } 875 } 876 goto vdbe_return; 876 goto vdbe_return; 877 } 877 } 878 878 879 /* Opcode: Integer P1 P2 * * * 879 /* Opcode: Integer P1 P2 * * * ................................................................................................................................................................................ 6059 rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid); 6059 rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid); 6060 db->vtabOnConflict = vtabOnConflict; 6060 db->vtabOnConflict = vtabOnConflict; 6061 importVtabErrMsg(p, pVtab); 6061 importVtabErrMsg(p, pVtab); 6062 if( rc==SQLITE_OK && pOp->p1 ){ 6062 if( rc==SQLITE_OK && pOp->p1 ){ 6063 assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) ); 6063 assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) ); 6064 db->lastRowid = lastRowid = rowid; 6064 db->lastRowid = lastRowid = rowid; 6065 } 6065 } 6066 if( rc==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){ | 6066 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){ 6067 if( pOp->p5==OE_Ignore ){ 6067 if( pOp->p5==OE_Ignore ){ 6068 rc = SQLITE_OK; 6068 rc = SQLITE_OK; 6069 }else{ 6069 }else{ 6070 p->errorAction = ((pOp->p5==OE_Replace) ? OE_Abort : pOp->p5); 6070 p->errorAction = ((pOp->p5==OE_Replace) ? OE_Abort : pOp->p5); 6071 } 6071 } 6072 }else{ 6072 }else{ 6073 p->nChange++; 6073 p->nChange++;
Changes to src/vdbeaux.c
363 while( (pOp = opIterNext(&sIter))!=0 ){ 363 while( (pOp = opIterNext(&sIter))!=0 ){ 364 int opcode = pOp->opcode; 364 int opcode = pOp->opcode; 365 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename 365 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename 366 #ifndef SQLITE_OMIT_FOREIGN_KEY 366 #ifndef SQLITE_OMIT_FOREIGN_KEY 367 || (opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1) 367 || (opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1) 368 #endif 368 #endif 369 || ((opcode==OP_Halt || opcode==OP_HaltIfNull) 369 || ((opcode==OP_Halt || opcode==OP_HaltIfNull) 370 && (pOp->p1==SQLITE_CONSTRAINT && pOp->p2==OE_Abort)) | 370 && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort)) 371 ){ 371 ){ 372 hasAbort = 1; 372 hasAbort = 1; 373 break; 373 break; 374 } 374 } 375 } 375 } 376 sqlite3DbFree(v->db, sIter.apSub); 376 sqlite3DbFree(v->db, sIter.apSub); 377 377 ................................................................................................................................................................................ 1766 return rc; 1766 return rc; 1767 } 1767 } 1768 1768 1769 /* If there are any write-transactions at all, invoke the commit hook */ 1769 /* If there are any write-transactions at all, invoke the commit hook */ 1770 if( needXcommit && db->xCommitCallback ){ 1770 if( needXcommit && db->xCommitCallback ){ 1771 rc = db->xCommitCallback(db->pCommitArg); 1771 rc = db->xCommitCallback(db->pCommitArg); 1772 if( rc ){ 1772 if( rc ){ 1773 return SQLITE_CONSTRAINT; | 1773 return SQLITE_CONSTRAINT_COMMITHOOK; 1774 } 1774 } 1775 } 1775 } 1776 1776 1777 /* The simple case - no more than one database file (not counting the 1777 /* The simple case - no more than one database file (not counting the 1778 ** TEMP database) has a transaction active. There is no need for the 1778 ** TEMP database) has a transaction active. There is no need for the 1779 ** master-journal. 1779 ** master-journal. 1780 ** 1780 ** ................................................................................................................................................................................ 2058 /* 2058 /* 2059 ** This function is called when a transaction opened by the database 2059 ** This function is called when a transaction opened by the database 2060 ** handle associated with the VM passed as an argument is about to be 2060 ** handle associated with the VM passed as an argument is about to be 2061 ** committed. If there are outstanding deferred foreign key constraint 2061 ** committed. If there are outstanding deferred foreign key constraint 2062 ** violations, return SQLITE_ERROR. Otherwise, SQLITE_OK. 2062 ** violations, return SQLITE_ERROR. Otherwise, SQLITE_OK. 2063 ** 2063 ** 2064 ** If there are outstanding FK violations and this function returns 2064 ** If there are outstanding FK violations and this function returns 2065 ** SQLITE_ERROR, set the result of the VM to SQLITE_CONSTRAINT and write | 2065 ** SQLITE_ERROR, set the result of the VM to SQLITE_CONSTRAINT_FOREIGNKEY 2066 ** an error message to it. Then return SQLITE_ERROR. | 2066 ** and write an error message to it. Then return SQLITE_ERROR. 2067 */ 2067 */ 2068 #ifndef SQLITE_OMIT_FOREIGN_KEY 2068 #ifndef SQLITE_OMIT_FOREIGN_KEY 2069 int sqlite3VdbeCheckFk(Vdbe *p, int deferred){ 2069 int sqlite3VdbeCheckFk(Vdbe *p, int deferred){ 2070 sqlite3 *db = p->db; 2070 sqlite3 *db = p->db; 2071 if( (deferred && db->nDeferredCons>0) || (!deferred && p->nFkConstraint>0) ){ 2071 if( (deferred && db->nDeferredCons>0) || (!deferred && p->nFkConstraint>0) ){ 2072 p->rc = SQLITE_CONSTRAINT; | 2072 p->rc = SQLITE_CONSTRAINT_FOREIGNKEY; 2073 p->errorAction = OE_Abort; 2073 p->errorAction = OE_Abort; 2074 sqlite3SetString(&p->zErrMsg, db, "foreign key constraint failed"); 2074 sqlite3SetString(&p->zErrMsg, db, "foreign key constraint failed"); 2075 return SQLITE_ERROR; 2075 return SQLITE_ERROR; 2076 } 2076 } 2077 return SQLITE_OK; 2077 return SQLITE_OK; 2078 } 2078 } 2079 #endif 2079 #endif ................................................................................................................................................................................ 2180 if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){ 2180 if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){ 2181 rc = sqlite3VdbeCheckFk(p, 1); 2181 rc = sqlite3VdbeCheckFk(p, 1); 2182 if( rc!=SQLITE_OK ){ 2182 if( rc!=SQLITE_OK ){ 2183 if( NEVER(p->readOnly) ){ 2183 if( NEVER(p->readOnly) ){ 2184 sqlite3VdbeLeave(p); 2184 sqlite3VdbeLeave(p); 2185 return SQLITE_ERROR; 2185 return SQLITE_ERROR; 2186 } 2186 } 2187 rc = SQLITE_CONSTRAINT; | 2187 rc = SQLITE_CONSTRAINT_FOREIGNKEY; 2188 }else{ 2188 }else{ 2189 /* The auto-commit flag is true, the vdbe program was successful 2189 /* The auto-commit flag is true, the vdbe program was successful 2190 ** or hit an 'OR FAIL' constraint and there are no deferred foreign 2190 ** or hit an 'OR FAIL' constraint and there are no deferred foreign 2191 ** key constraints to hold up the transaction. This means a commit 2191 ** key constraints to hold up the transaction. This means a commit 2192 ** is required. */ 2192 ** is required. */ 2193 rc = vdbeCommit(db, p); 2193 rc = vdbeCommit(db, p); 2194 } 2194 } ................................................................................................................................................................................ 2223 ** do so. If this operation returns an error, and the current statement 2223 ** do so. If this operation returns an error, and the current statement 2224 ** error code is SQLITE_OK or SQLITE_CONSTRAINT, then promote the 2224 ** error code is SQLITE_OK or SQLITE_CONSTRAINT, then promote the 2225 ** current statement error code. 2225 ** current statement error code. 2226 */ 2226 */ 2227 if( eStatementOp ){ 2227 if( eStatementOp ){ 2228 rc = sqlite3VdbeCloseStatement(p, eStatementOp); 2228 rc = sqlite3VdbeCloseStatement(p, eStatementOp); 2229 if( rc ){ 2229 if( rc ){ 2230 if( p->rc==SQLITE_OK || p->rc==SQLITE_CONSTRAINT ){ | 2230 if( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ){ 2231 p->rc = rc; 2231 p->rc = rc; 2232 sqlite3DbFree(db, p->zErrMsg); 2232 sqlite3DbFree(db, p->zErrMsg); 2233 p->zErrMsg = 0; 2233 p->zErrMsg = 0; 2234 } 2234 } 2235 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); 2235 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); 2236 sqlite3CloseSavepoints(db); 2236 sqlite3CloseSavepoints(db); 2237 db->autoCommit = 1; 2237 db->autoCommit = 1;