/ Check-in [c0689409]
Login

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

Overview
Comment:Minor cleanup changes on the OP_StackDepth opcode. Added the sidedelete test for additional testing of ticket #2832. (CVS 4619)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c0689409320de1532be0c0cae12b4b716f6bffb9
User & Date: drh 2007-12-12 22:24:13
Context
2007-12-13
02:45
Towards getting ORDER BY to match against the correctin columns. This version only looks at the left-most column in a compound SELECT. That is the correct thing to do, but not what SQLite has historically done. (CVS 4620) check-in: bbddf16a user: drh tags: trunk
2007-12-12
22:24
Minor cleanup changes on the OP_StackDepth opcode. Added the sidedelete test for additional testing of ticket #2832. (CVS 4619) check-in: c0689409 user: drh tags: trunk
18:05
Remove an (explain) accidentally left in tkt2832.test. (CVS 4618) check-in: 48947e2b user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Show Whitespace Changes Patch

Changes to src/vdbe.c.

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
697
698
699
700
701
702
703

704
705
706
707
708
709
710
711
712
713
**
** Various scripts scan this source file in order to generate HTML
** documentation, headers files, or other derived files.  The formatting
** of the code in this file is, therefore, important.  See other comments
** in this file for details.  If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.658 2007/12/12 12:25:22 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
#include "vdbeInt.h"

/*
** The following global variable is incremented every time a cursor
................................................................................
** If P1 is less than zero, then store the current stack depth
** in P1.  If P1 is zero or greater, verify that the current stack
** depth is equal to P1 and throw an exception if it is not.
**
** This opcode is used for internal consistency checking.
*/
case OP_StackDepth: {       /* no-push */

  if( pOp->p1<0 ){
    pOp->p1 = pTos - p->aStack + 1;
  }else if( pOp->p1!=pTos - p->aStack + 1 ){
    p->pTos = pTos;
    p->rc = rc = SQLITE_INTERNAL;
    p->pc = pc;
    p->errorAction = OE_Rollback;
    sqlite3SetString(&p->zErrMsg, "internal error: VDBE stack leak", (char*)0);
    goto vdbe_return;
  }







|







 







>

|
|







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
**
** Various scripts scan this source file in order to generate HTML
** documentation, headers files, or other derived files.  The formatting
** of the code in this file is, therefore, important.  See other comments
** in this file for details.  If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.659 2007/12/12 22:24:13 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
#include "vdbeInt.h"

/*
** The following global variable is incremented every time a cursor
................................................................................
** If P1 is less than zero, then store the current stack depth
** in P1.  If P1 is zero or greater, verify that the current stack
** depth is equal to P1 and throw an exception if it is not.
**
** This opcode is used for internal consistency checking.
*/
case OP_StackDepth: {       /* no-push */
  int n = pTos - p->aStack + 1;
  if( pOp->p1<0 ){
    pOp->p1 = n;
  }else if( pOp->p1!=n ){
    p->pTos = pTos;
    p->rc = rc = SQLITE_INTERNAL;
    p->pc = pc;
    p->errorAction = OE_Rollback;
    sqlite3SetString(&p->zErrMsg, "internal error: VDBE stack leak", (char*)0);
    goto vdbe_return;
  }

Added test/sidedelete.test.























































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 2007 Dec 12
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file contains test cases for stressing database
# changes that involve side effects that delete rows from
# the table being changed.  Ticket #2832 shows that in
# older versions of SQLite that behavior was implemented
# incorrectly and resulted in corrupt database files.
#
# $Id: sidedelete.test,v 1.1 2007/12/12 22:24:13 drh Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# The sequence table is created to store a sequence of integers
# starting with 1.  This is used to reinitialize other tables
# as part of other tests.
#
do_test sidedelete-1.1 {
  execsql {
    CREATE TABLE sequence(a INTEGER PRIMARY KEY);
    INSERT INTO sequence VALUES(1);
    INSERT INTO sequence VALUES(2);
  }
  for {set i 0} {$i<8} {incr i} {
    execsql {
      INSERT INTO sequence SELECT a+(SELECT max(a) FROM sequence) FROM sequence;
    }
  }
  execsql {SELECT count(*) FROM sequence}
} {512}

# Make a series of changes using an UPDATE OR REPLACE and a
# correlated subquery.  This would cause database corruption
# prior to the fix for ticket #2832.
#
do_test sidedelete-2.0 {
  execsql {
    CREATE TABLE t1(a PRIMARY KEY, b);
    CREATE TABLE chng(a PRIMARY KEY, b);
    SELECT count(*) FROM t1 UNION ALL SELECT count(*) FROM chng;
  }
} {0 0}
for {set i 2} {$i<=100} {incr i} {
  set n [expr {($i+2)/2}]
  do_test sidedelete-2.$i.1 {
    execsql {
      DELETE FROM t1;
      INSERT INTO t1 SELECT a, a FROM sequence WHERE a<=$i;
      DELETE FROM chng;
      INSERT INTO chng SELECT a*2, a*2+1 FROM sequence WHERE a<=$i/2;
      UPDATE OR REPLACE t1 SET a=(SELECT b FROM chng WHERE a=t1.a);
      SELECT count(*), sum(a) FROM t1;
    }
  } [list $n [expr {$n*$n-1}]]
  integrity_check sidedelete-2.$i.2
}

# This will cause stacks leaks but not database corruption prior
# to the #2832 fix.
#
do_test sidedelete-3.0 {
  execsql {
     DROP TABLE t1;
     CREATE TABLE t1(a PRIMARY KEY);
     SELECT * FROM t1;
  }
} {}
for {set i 1} {$i<=100} {incr i} {
  set n [expr {($i+1)/2}]
  do_test sidedelete-3.$i.1 {
    execsql {
      DELETE FROM t1;
      INSERT INTO t1 SELECT a FROM sequence WHERE a<=$i;
      UPDATE OR REPLACE t1 SET a=a+1;
      SELECT count(*), sum(a) FROM t1;
    }
  } [list $n [expr {$n*($n+1)}]]
  integrity_check sidedelete-3.$i.2
}

finish_test