/ Check-in [82b6aa77]
Login

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

Overview
Comment:Add a test for the collation-sequence/CHECK constraint problem fixed by the previous commit.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | shared-cache-fix
Files: files | file ages | folders
SHA1: 82b6aa77c8d8de4c6fad1960f5958457a929a821
User & Date: dan 2012-10-05 17:18:16
Context
2012-10-05
17:44
Merge the shared-cache related fixes from the shared-cache-fix branch to the trunk. check-in: 698ec776 user: dan tags: trunk
17:18
Add a test for the collation-sequence/CHECK constraint problem fixed by the previous commit. Closed-Leaf check-in: 82b6aa77 user: dan tags: shared-cache-fix
16:30
Fix a problem with shared-cache mode and CHECK constraints causing one db handle to invoke a collation sequence function registered with another. check-in: c2c776ab user: dan tags: shared-cache-fix
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/shared9.test.

    13     13   # to the same shared cache using different database names, views and
    14     14   # virtual tables may still be accessed.
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   set testprefix shared9
           20  +
           21  +ifcapable !view||!trigger {
           22  +  finish_test
           23  +  return
           24  +}
           25  +
    20     26   db close
    21     27   set enable_shared_cache [sqlite3_enable_shared_cache 1]
    22     28   
    23         -# Test organization:
    24         -#   
    25         -#   1.* - Views.
    26         -#   2.* - Virtual tables.
    27         -#
    28         -
    29     29   sqlite3 db1 test.db
    30     30   sqlite3 db2 test.db
    31     31   forcedelete test.db2
    32     32   
    33     33   do_test 1.1 {
    34     34     db1 eval {
    35     35       ATTACH 'test.db2' AS 'fred';
................................................................................
    44     44       END;
    45     45       INSERT INTO t2 VALUES(1, 2);
    46     46       SELECT * FROM t3;
    47     47     }
    48     48   } {1 2}
    49     49   
    50     50   do_test 1.2 { db2 eval "ATTACH 'test.db2' AS 'jones'" } {}
    51         -do_test 1.2 { db2 eval "SELECT * FROM v1"             } {}
    52         -do_test 1.3 { db2 eval "INSERT INTO t2 VALUES(3, 4)"  } {}
           51  +do_test 1.3 { db2 eval "SELECT * FROM v1"             } {}
           52  +do_test 1.4 { db2 eval "INSERT INTO t2 VALUES(3, 4)"  } {}
    53     53   
    54         -do_test 2.1 {
    55         -  db1 eval {
    56         -    CREATE VIRTUAL TABLE fred.t4 USING fts4;
    57         -    INSERT INTO t4 VALUES('hello world');
    58         -  }
    59         -} {}
           54  +ifcapable fts3 {
           55  +  do_test 1.5 {
           56  +    db1 eval {
           57  +      CREATE VIRTUAL TABLE fred.t4 USING fts4;
           58  +      INSERT INTO t4 VALUES('hello world');
           59  +    }
           60  +  } {}
    60     61   
    61         -do_test 2.2 {
    62         -  db2 eval {
    63         -    INSERT INTO t4 VALUES('shared cache');
    64         -    SELECT * FROM t4 WHERE t4 MATCH 'hello';
    65         -  }
    66         -} {{hello world}}
           62  +  do_test 1.6 {
           63  +    db2 eval {
           64  +      INSERT INTO t4 VALUES('shared cache');
           65  +      SELECT * FROM t4 WHERE t4 MATCH 'hello';
           66  +    }
           67  +  } {{hello world}}
    67     68   
    68         -do_test 2.3 {
    69         -  db1 eval {
    70         -    SELECT * FROM t4 WHERE t4 MATCH 'c*';
    71         -  }
    72         -} {{shared cache}}
           69  +  do_test 1.7 {
           70  +    db1 eval {
           71  +      SELECT * FROM t4 WHERE t4 MATCH 'c*';
           72  +    }
           73  +  } {{shared cache}}
           74  +}
    73     75   
    74     76   db1 close
    75     77   db2 close
           78  +
           79  +#-------------------------------------------------------------------------
           80  +# The following tests attempt to find a similar problem with collation 
           81  +# sequence names - pointers to database handle specific allocations leaking 
           82  +# into schema objects and being used after the original handle has been
           83  +# closed.
           84  +#
           85  +forcedelete test.db test.db2
           86  +sqlite3 db1 test.db
           87  +sqlite3 db2 test.db
           88  +foreach x {collate1 collate2 collate3} {
           89  +  proc $x {a b} { string compare $a $b }
           90  +  db1 collate $x $x
           91  +  db2 collate $x $x
           92  +}
           93  +do_test 2.1 {
           94  +  db1 eval {
           95  +    CREATE TABLE t1(a, b, c COLLATE collate1);
           96  +    CREATE INDEX i1 ON t1(a COLLATE collate2, c, b);
           97  +  }
           98  +} {}
           99  +do_test 2.2 {
          100  +  db1 close
          101  +  db2 eval "INSERT INTO t1 VALUES('abc', 'def', 'ghi')"
          102  +} {}
          103  +db2 close
          104  +
          105  +#-------------------------------------------------------------------------
          106  +# At one point, the following would cause a collation sequence belonging
          107  +# to connection [db1] to be invoked by a call to [db2 eval]. Which is a
          108  +# problem if [db1] has already been closed.
          109  +#
          110  +forcedelete test.db test.db2
          111  +sqlite3 db1 test.db
          112  +sqlite3 db2 test.db
          113  +
          114  +proc mycollate_db1 {a b} {set ::invoked_mycollate_db1 1 ; string compare $a $b}
          115  +proc mycollate_db2 {a b} {string compare $a $b}
          116  +
          117  +db1 collate mycollate mycollate_db1
          118  +db2 collate mycollate mycollate_db2
          119  +
          120  +do_test 2.3 {
          121  +  set ::invoked_mycollate_db1 0
          122  +  db1 eval {
          123  +    CREATE TABLE t1(a COLLATE mycollate, CHECK (a IN ('one', 'two', 'three')));
          124  +    INSERT INTO t1 VALUES('one');
          125  +  }
          126  +  db1 close
          127  +  set ::invoked_mycollate_db1
          128  +} {1}
          129  +do_test 2.4 {
          130  +  set ::invoked_mycollate_db1 0
          131  +  db2 eval {
          132  +    INSERT INTO t1 VALUES('two');
          133  +  }
          134  +  db2 close
          135  +  set ::invoked_mycollate_db1
          136  +} {0}
          137  +
    76    138   sqlite3_enable_shared_cache $::enable_shared_cache
    77    139   finish_test
    78    140