File: tkt-b72787b1.test

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (82 lines) | stat: -rw-r--r-- 2,582 bytes parent folder | download | duplicates (19)
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
# 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

ifcapable !compound {
  finish_test
  return
}

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