SQLite

Check-in [f43ff8f82d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Modifications to ensure the nExtraDelete-related assert() statement does not fail.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | fordelete-assert
Files: files | file ages | folders
SHA1: f43ff8f82d6c1239e6f9a32e7716421c1180ac74
User & Date: dan 2016-01-28 17:06:17.501
Context
2016-01-29
18:04
Prepend "rc!=SQLITE_OK || " to the nExtraDelete assert() condition. (check-in: 2a055ed0af user: dan tags: fordelete-assert)
2016-01-28
17:06
Modifications to ensure the nExtraDelete-related assert() statement does not fail. (check-in: f43ff8f82d user: dan tags: fordelete-assert)
2016-01-27
16:26
Change the name of the BTREE_IDXDELETE flag to BTREE_AUXDELETE, to better reflect its purpose. (check-in: 1d3bf6bebd user: drh tags: fordelete-assert)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/vdbe.c.
4401
4402
4403
4404
4405
4406
4407

4408
4409
4410
4411
4412
4413
4414
4415

4416
4417
4418
4419
4420
4421
4422

  /* Only flags that can be set are SAVEPOISTION and AUXDELETE */ 
  assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_AUXDELETE))==0 );
  assert( OPFLAG_SAVEPOSITION==BTREE_SAVEPOSITION );
  assert( OPFLAG_AUXDELETE==BTREE_AUXDELETE );

#ifdef SQLITE_DEBUG

  if( pC->isEphemeral==0
   && (pOp->p5 & OPFLAG_AUXDELETE)==0
   && (pC->wrFlag & OPFLAG_FORDELETE)==0
  ){
    nExtraDelete++;
  }
  if( pOp->p2 & OPFLAG_NCHANGE ){
    nExtraDelete--;

  }
#endif

  rc = sqlite3BtreeDelete(pC->uc.pCursor, pOp->p5);
  pC->cacheStatus = CACHE_STALE;

  /* Invoke the update-hook if required. */







>
|
|
|
|
|
|
|
|
>







4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424

  /* Only flags that can be set are SAVEPOISTION and AUXDELETE */ 
  assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_AUXDELETE))==0 );
  assert( OPFLAG_SAVEPOSITION==BTREE_SAVEPOSITION );
  assert( OPFLAG_AUXDELETE==BTREE_AUXDELETE );

#ifdef SQLITE_DEBUG
  if( p->pFrame==0 ){
    if( pC->isEphemeral==0
        && (pOp->p5 & OPFLAG_AUXDELETE)==0
        && (pC->wrFlag & OPFLAG_FORDELETE)==0
      ){
      nExtraDelete++;
    }
    if( pOp->p2 & OPFLAG_NCHANGE ){
      nExtraDelete--;
    }
  }
#endif

  rc = sqlite3BtreeDelete(pC->uc.pCursor, pOp->p5);
  pC->cacheStatus = CACHE_STALE;

  /* Invoke the update-hook if required. */
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
  pCrsr = pC->uc.pCursor;
  assert( pCrsr!=0 );
  assert( pOp->p5==0 );
  r.pKeyInfo = pC->pKeyInfo;
  r.nField = (u16)pOp->p3;
  r.default_rc = 0;
  r.aMem = &aMem[pOp->p2];
#ifdef SQLITE_DEBUG
  {
    int i;
    for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) );
    if( pC->isEphemeral==0
     && (pOp->p5 & OPFLAG_AUXDELETE)==0
     && (pC->wrFlag & OPFLAG_FORDELETE)==0
    ){
      nExtraDelete++;
    }
  }
#endif
  rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
  if( rc==SQLITE_OK && res==0 ){
    rc = sqlite3BtreeDelete(pCrsr, 0);
  }
  assert( pC->deferredMoveto==0 );
  pC->cacheStatus = CACHE_STALE;
  break;
}

/* Opcode: IdxRowid P1 P2 * * *







<
<
<
<
<
<
<
<
<
<
<
<


|







4958
4959
4960
4961
4962
4963
4964












4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
  pCrsr = pC->uc.pCursor;
  assert( pCrsr!=0 );
  assert( pOp->p5==0 );
  r.pKeyInfo = pC->pKeyInfo;
  r.nField = (u16)pOp->p3;
  r.default_rc = 0;
  r.aMem = &aMem[pOp->p2];












  rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
  if( rc==SQLITE_OK && res==0 ){
    rc = sqlite3BtreeDelete(pCrsr, BTREE_AUXDELETE);
  }
  assert( pC->deferredMoveto==0 );
  pC->cacheStatus = CACHE_STALE;
  break;
}

/* Opcode: IdxRowid P1 P2 * * *
Changes to test/fordelete.test.
153
154
155
156
157
158
159
















































160
161
162
  btree_close_cursor $csr
  db eval { COMMIT }

  db eval {
    SELECT * FROM x2;
  }
} {6 {} {} {}}

















































finish_test








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
  btree_close_cursor $csr
  db eval { COMMIT }

  db eval {
    SELECT * FROM x2;
  }
} {6 {} {} {}}


#-------------------------------------------------------------------------
#
reset_db 
do_execsql_test 4.0 {
  CREATE TABLE log(x);
  CREATE TABLE p1(one PRIMARY KEY, two);

  CREATE TRIGGER tr_bd BEFORE DELETE ON p1 BEGIN
    INSERT INTO log VALUES('delete');
  END;
  INSERT INTO p1 VALUES('a', 'A'), ('b', 'B'), ('c', 'C');
  DELETE FROM p1 WHERE one = 'a';
}

reset_db
do_execsql_test 4.1 {
  BEGIN TRANSACTION;
  CREATE TABLE tbl(a PRIMARY KEY, b, c);
  CREATE TABLE log(a, b, c);
  INSERT INTO "tbl" VALUES(1,2,3);
  CREATE TRIGGER the_trigger BEFORE DELETE ON tbl BEGIN 
    INSERT INTO log VALUES(1, 2,3);
  END;
  COMMIT;
  DELETE FROM tbl WHERE a=1;
}

reset_db
do_execsql_test 5.1 {
  PRAGMA foreign_keys = 1;
  CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
  CREATE TABLE t2(
      c INTEGER PRIMARY KEY,
      d INTEGER DEFAULT 1 REFERENCES t1 ON DELETE SET DEFAULT
  );
} {}
do_execsql_test 5.2 {
  INSERT INTO t1 VALUES(1, 'one');
  INSERT INTO t1 VALUES(2, 'two');
  INSERT INTO t2 VALUES(1, 2);
  SELECT * FROM t2;
} {1 2}
do_execsql_test 5.3 {
  DELETE FROM t1 WHERE a = 2;
} {}


finish_test