SQLite

Check-in [1bca0a7e19]
Login

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

Overview
Comment:When a stale schema-cookie is seen, expire only the one statement that encountered the bad cookie, not every statement on the database connection. Ticket [b72787b1a7cea1f]
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1bca0a7e198391202fd2bc1650c0a62028a9aaa5
User & Date: drh 2011-02-22 03:34:56.684
Context
2011-02-23
13:33
Retry selected system calls on unix when they fail with EINTR. (check-in: b9d29ea385 user: drh tags: trunk)
2011-02-22
03:34
When a stale schema-cookie is seen, expire only the one statement that encountered the bad cookie, not every statement on the database connection. Ticket [b72787b1a7cea1f] (check-in: 1bca0a7e19 user: drh tags: trunk)
2011-02-21
17:49
Fix a problem with "EXPLAIN QUERY PLAN SELECT count(*) FROM tbl". (check-in: 9f9f328825 user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
install-sh became executable.
Changes to src/vdbe.c.
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
    ** to be invalidated whenever sqlite3_step() is called from within 
    ** a v-table method.
    */
    if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
      sqlite3ResetInternalSchema(db, pOp->p1);
    }

    sqlite3ExpirePreparedStatements(db);
    rc = SQLITE_SCHEMA;
  }
  break;
}

/* Opcode: OpenRead P1 P2 P3 P4 P5
**







|







2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
    ** to be invalidated whenever sqlite3_step() is called from within 
    ** a v-table method.
    */
    if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
      sqlite3ResetInternalSchema(db, pOp->p1);
    }

    p->expired = 1;
    rc = SQLITE_SCHEMA;
  }
  break;
}

/* Opcode: OpenRead P1 P2 P3 P4 P5
**
test/progress.test became a regular file.
Added test/tkt-b72787b1.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
# 2011 February 21
#
# 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 implements regression tests for SQLite library.
#
# This file implements tests to verify that ticket [b72787b1a7] has been
# fixed.  From the ticket:
#
#     The sqlite3ExpirePreparedStatements routine marks all statements
#     as expired. This includes statements that are not expired.
#
#     Steps to reproduce:
#
#        * Prepare a statement (A)
#        * Alter the schema to invalidate cookie in A
#        * Prepare a statement (B)
#        * Run B and have A run as part of B
#        * A will find a bad cookie and cause *all* statements
#          to be expired including the currently running B by calling
#          sqlite3ExpirePreparedStatements
#        * When control returns to B it will then abort 
#
#     The bug is that sqlite3ExpirePreparedStatements expires all statements.
#     Note that B was prepared after the schema change and hence is perfectly
#     valid and then is marked as expired while running.
#

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

unset -nocomplain ::STMT
proc runsql {} {
  db eval {CREATE TABLE IF NOT EXISTS t4(q)}
  sqlite3_step $::STMT
  set rc [sqlite3_column_int $::STMT 0]
  sqlite3_reset $::STMT
  return $rc
}

do_test tkt-b72787b1.1 {
  db eval {
    CREATE TABLE t1(x);
    INSERT INTO t1 VALUES(1);
    INSERT INTO t1 VALUES(2);
    CREATE TABLE t2(y);
    INSERT INTO t2 SELECT x+2 FROM t1;
    INSERT INTO t2 SELECT x+4 FROM t1;
  }
  db func runsql ::runsql
  set DB [sqlite3_connection_pointer db]
  set sql {SELECT max(x) FROM t1}
  set ::STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL]

  # The runsql() call on the second row of the first query will
  # cause all $::STMT to hit an expired cookie.  Prior to the fix
  # for [b72787b1a7, the bad cookie would expire all statements, including
  # the following compound SELECT, which would cause a fault when the
  # second SELECT was reached.  After the fix, the current statement
  # continues to completion.
  db eval {
    SELECT CASE WHEN y=3 THEN y+100 WHEN y==4 THEN runsql()+200
                ELSE 300+y END FROM t2
    UNION ALL
    SELECT * FROM t1;
  }
} {103 202 305 306 1 2}

sqlite3_finalize $::STMT

finish_test
tool/mkopts.tcl became a regular file.