]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the ignore_check_constraints pragma. VACUUM works even on a database
authordrh <drh@noemail.net>
Thu, 3 Nov 2005 02:15:02 +0000 (02:15 +0000)
committerdrh <drh@noemail.net>
Thu, 3 Nov 2005 02:15:02 +0000 (02:15 +0000)
that contains table entries that violate check constraints. (CVS 2757)

FossilOrigin-Name: be83bfee0211396a0038ffb125897199bea9a73f

manifest
manifest.uuid
src/insert.c
src/pragma.c
src/sqliteInt.h
src/vacuum.c
test/check.test

index 00591efc330630099ae036b1312133627541d541..d639c0a58d3625f1e5bd17d0a66fecce16165db3 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Disallow\ssubqueries\sin\sCHECK\sconstraints.\s(CVS\s2756)
-D 2005-11-03T02:03:13
+C Add\sthe\signore_check_constraints\spragma.\s\sVACUUM\sworks\seven\son\sa\sdatabase\nthat\scontains\stable\sentries\sthat\sviolate\scheck\sconstraints.\s(CVS\s2757)
+D 2005-11-03T02:15:03
 F Makefile.in 12784cdce5ffc8dfb707300c34e4f1eb3b8a14f1
 F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -45,7 +45,7 @@ F src/expr.c 14466b227096263213d7748174c2bd8cb722cc3c
 F src/func.c 7d81dccd9c440c6c4e761056333e629192814af0
 F src/hash.c 8747cf51d12de46512880dfcf1b68b4e24072863
 F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
-F src/insert.c c8f12b468f311f55ecfadda2fe08799bf2633a18
+F src/insert.c e04b27e076ed093606db82400a3769a3a3b00a61
 F src/legacy.c d58ea507bce885298a2c8c3cbb0f4bff5d47830b
 F src/main.c 97bb830cdbd378d1f87469618471f52d9d263d09
 F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070
@@ -60,14 +60,14 @@ F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
 F src/pager.c adbb27f13ac75cd5bc29a3d84803e0cab1edfa88
 F src/pager.h e7b41ce8e7b5f629d456708b7ad9a8c8ede37140
 F src/parse.y 1d5afb972ed5ef3ec8712a2b5953b48f086091da
-F src/pragma.c 9ec219dc4ee2d4e78f4ec5c9d1422089758af13f
+F src/pragma.c b40189967155a522433b8470f363192a927ba22c
 F src/prepare.c fc098db25d2a121affb08686cf04833fd50452d4
 F src/printf.c 3ea3a17d25d7ac498efc18007c70371a42c968f8
 F src/random.c 90adff4e73a3b249eb4f1fc2a6ff9cf78c7233a4
 F src/select.c be02f123e8651bee22beb07d89dcfa75bcc2e291
 F src/shell.c 3596c1e559b82663057940d19ba533ad421c7dd3
 F src/sqlite.h.in 8e648e1f386e4509f2f96c09ded7c07b0df0c9a2
-F src/sqliteInt.h c6685ddb841f9b5585758642b6ae32a7428c7936
+F src/sqliteInt.h e546554bdd4e3c903dd033bb1e2476193c2d4f37
 F src/table.c e03b60eaabaeb54a00d7e931566d77302dfc19b0
 F src/tclsqlite.c 4f274fae3d4a1863451a553dd8e5015747a5d91d
 F src/test1.c 77506b6b88125c26f00a11bf3ff5c8dc824e837e
@@ -80,7 +80,7 @@ F src/trigger.c f51dec15921629591cb98bf2e350018e268b109a
 F src/update.c ac506fb7400158f826ec6c3a0dbe65e7ed3928d5
 F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c
 F src/util.c 48fecbbef4391d102a23096d32f0d74173428406
-F src/vacuum.c 829d9e1a6d7c094b80e0899686670932eafd768c
+F src/vacuum.c 2ed18a4e9c894de7239bc1c68fe455fcb39571c6
 F src/vdbe.c e83de8a017fe5c495fcef3093dbdca30fa6b1ea4
 F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13
 F src/vdbeInt.h 6eba0b967dc4fc4d5dea6e3bcc66e70a44981cc9
@@ -124,7 +124,7 @@ F test/capi2.test f897209386fb21cfdc9267595e0c667ebaca9164
 F test/capi3.test fc8e573467049add3bfaf81f53827e8ff153cf8f
 F test/capi3b.test 5b6a66f9f295f79f443b5d3f33187fa5ef6cf336
 F test/cast.test 2543165ced4249c89ce5f0352222df503a98b9e5
-F test/check.test c591a20fcb082ae7362299c00b4fb85536f62f1b
+F test/check.test 6d9891a9c23664187cec285b2766bc545d9cc712
 F test/collate1.test add9454cef160677bb8b34148b8f277ce7f9f1c4
 F test/collate2.test 224a632ba04907c049804b08162efd234aa7871f
 F test/collate3.test 947a77f5b8227e037a7094d0e338a5504f155cc4
@@ -316,7 +316,7 @@ F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 55b314a22c69fbe129b024e953f3230b67eaaa87
-R 8803f664e97429fe76d644ff77ce2e9b
+P db27afc4cdc5b51c1fa0e83dbd6d4a4a69c5b642
+R 845f2cc4e249401789db166e879f4183
 U drh
-Z a81fd0388a861af771476f6fd322db14
+Z bd889ec2abfde5bf334bd2278ed2468d
index c816a932dec9204f80dc0c37de052b576a696058..611be2177ce1d0c3274877b8777f991190f6a17a 100644 (file)
@@ -1 +1 @@
-db27afc4cdc5b51c1fa0e83dbd6d4a4a69c5b642
\ No newline at end of file
+be83bfee0211396a0038ffb125897199bea9a73f
\ No newline at end of file
index 33090b18e3053655a2672f5469b0311c5f47250c..ce1dc511a38ded6b82fc653e085145c7c856210e 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle INSERT statements in SQLite.
 **
-** $Id: insert.c,v 1.146 2005/11/03 01:22:31 drh Exp $
+** $Id: insert.c,v 1.147 2005/11/03 02:15:03 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -869,7 +869,7 @@ void sqlite3GenerateConstraintChecks(
   /* Test all CHECK constraints
   */
 #ifndef SQLITE_OMIT_CHECK
-  if( pTab->pCheck ){
+  if( pTab->pCheck && (pParse->db->flags & SQLITE_IgnoreChecks)==0 ){
     int allOk = sqlite3VdbeMakeLabel(v);
     assert( pParse->ckOffset==0 );
     pParse->ckOffset = nCol;
index 87d87fab188fd64ea3b7cfce2a56db39d94243e5..93707f53014ed227f97a3a59bc427ccc3e81391f 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains code used to implement the PRAGMA command.
 **
-** $Id: pragma.c,v 1.102 2005/10/06 13:59:27 drh Exp $
+** $Id: pragma.c,v 1.103 2005/11/03 02:15:03 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -151,6 +151,9 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
     { "short_column_names",       SQLITE_ShortColNames },
     { "count_changes",            SQLITE_CountRows     },
     { "empty_result_callbacks",   SQLITE_NullCallback  },
+#ifndef SQLITE_OMIT_CHECK
+    { "ignore_check_constraints", SQLITE_IgnoreChecks  },
+#endif
     /* The following is VERY experimental */
     { "writable_schema",          SQLITE_WriteSchema   },
     { "omit_readlock",            SQLITE_NoReadlock    },
index 3cb1aef99b2e02fa2ce43f40fcffd4319ccaf68a..84ae5735c04a56a5307082cb05134d4e0bcd7845 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.426 2005/11/03 02:03:13 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.427 2005/11/03 02:15:03 drh Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -489,6 +489,7 @@ struct sqlite3 {
 #define SQLITE_WriteSchema    0x00000800  /* OK to update SQLITE_MASTER */
 #define SQLITE_NoReadlock     0x00001000  /* Readlocks are omitted when 
                                           ** accessing read-only databases */
+#define SQLITE_IgnoreChecks   0x00002000  /* Do not enforce check constraints */
 
 /*
 ** Possible values for the sqlite.magic field.
index eb45fb99e55d47da4c13d979f67c69c31380d2b4..28d45d5d7c9ac20c7bc8424e1dfa36ee1444bcbb 100644 (file)
@@ -14,7 +14,7 @@
 ** Most of the code in this file may be omitted by defining the
 ** SQLITE_OMIT_VACUUM macro.
 **
-** $Id: vacuum.c,v 1.45 2005/06/07 09:21:07 danielk1977 Exp $
+** $Id: vacuum.c,v 1.46 2005/11/03 02:15:04 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -100,11 +100,11 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
   Btree *pMain;           /* The database being vacuumed */
   Btree *pTemp;
   char *zSql = 0;
-  int writeschema_flag;   /* Saved value of the write-schema flag */
+  int saved_flags;       /* Saved value of the db->flags */
 
   /* Save the current value of the write-schema flag before setting it. */
-  writeschema_flag = db->flags&SQLITE_WriteSchema;
-  db->flags |= SQLITE_WriteSchema;
+  saved_flags = db->flags;
+  db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks;
 
   if( !db->autoCommit ){
     sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction", 
@@ -281,9 +281,8 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
   }
 
 end_of_vacuum:
-  /* Restore the original value of the write-schema flag. */
-  db->flags &= ~SQLITE_WriteSchema;
-  db->flags |= writeschema_flag;
+  /* Restore the original value of db->flags */
+  db->flags = saved_flags;
 
   /* Currently there is an SQL level transaction open on the vacuum
   ** database. No locks are held on any other files (since the main file
index 4c992edff9e7ffa88b17c42bf3f855faf3ff2599..109d18387b103e5e1d7ad2f6df20f9077b872694 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing CHECK constraints
 #
-# $Id: check.test,v 1.3 2005/11/03 02:03:13 drh Exp $
+# $Id: check.test,v 1.4 2005/11/03 02:15:04 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -256,5 +256,25 @@ do_test check-4.6 {
     SELECT * FROM t4;
   }
 } {12 -22}
+do_test check-4.7 {
+  execsql {
+    PRAGMA ignore_check_constraints=ON;
+    UPDATE t4 SET x=0, y=1;
+    SELECT * FROM t4;
+  }
+} {0 1}
+do_test check-4.8 {
+  catchsql {
+    PRAGMA ignore_check_constraints=OFF;
+    UPDATE t4 SET x=0, y=2;
+  }
+} {1 {constraint failed}}
+do_test check_4.9 {
+  catchsql {
+    VACUUM
+  }
+} {0 {}}
+
+
 
 finish_test