drh | f012ea3 | 2006-05-24 12:43:26 +0000 | [diff] [blame] | 1 | # 2005 January 19 |
| 2 | # |
| 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
| 5 | # |
| 6 | # May you do good and not evil. |
| 7 | # May you find forgiveness for yourself and forgive others. |
| 8 | # May you share freely, never taking more than you give. |
| 9 | # |
| 10 | #*********************************************************************** |
| 11 | # |
danielk1977 | 8c0a791 | 2008-08-20 14:49:23 +0000 | [diff] [blame] | 12 | # $Id: shared3.test,v 1.4 2008/08/20 14:49:25 danielk1977 Exp $ |
drh | f012ea3 | 2006-05-24 12:43:26 +0000 | [diff] [blame] | 13 | |
| 14 | set testdir [file dirname $argv0] |
| 15 | source $testdir/tester.tcl |
| 16 | db close |
| 17 | |
| 18 | ifcapable !shared_cache { |
| 19 | finish_test |
| 20 | return |
| 21 | } |
| 22 | set ::enable_shared_cache [sqlite3_enable_shared_cache 1] |
| 23 | |
| 24 | # Ticket #1824 |
| 25 | # |
| 26 | do_test shared3-1.1 { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 27 | forcedelete test.db test.db-journal |
drh | f012ea3 | 2006-05-24 12:43:26 +0000 | [diff] [blame] | 28 | sqlite3 db1 test.db |
| 29 | db1 eval { |
| 30 | PRAGMA encoding=UTF16; |
| 31 | CREATE TABLE t1(x,y); |
| 32 | INSERT INTO t1 VALUES('abc','This is a test string'); |
| 33 | } |
| 34 | db1 close |
| 35 | sqlite3 db1 test.db |
| 36 | db1 eval {SELECT * FROM t1} |
| 37 | } {abc {This is a test string}} |
| 38 | do_test shared3-1.2 { |
| 39 | sqlite3 db2 test.db |
| 40 | db2 eval {SELECT y FROM t1 WHERE x='abc'} |
| 41 | } {{This is a test string}} |
| 42 | |
| 43 | db1 close |
| 44 | db2 close |
| 45 | |
danielk1977 | 9324c8f | 2008-06-20 17:51:16 +0000 | [diff] [blame] | 46 | do_test shared3-2.1 { |
| 47 | sqlite3 db1 test.db |
| 48 | execsql { |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 49 | PRAGMA main.cache_size = 10; |
danielk1977 | 9324c8f | 2008-06-20 17:51:16 +0000 | [diff] [blame] | 50 | } db1 |
| 51 | } {} |
| 52 | do_test shared3-2.2 { |
| 53 | execsql { PRAGMA main.cache_size } db1 |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 54 | } {10} |
danielk1977 | 9324c8f | 2008-06-20 17:51:16 +0000 | [diff] [blame] | 55 | do_test shared3-2.3 { |
| 56 | sqlite3 db2 test.db |
| 57 | execsql { PRAGMA main.cache_size } db1 |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 58 | } {10} |
danielk1977 | 9324c8f | 2008-06-20 17:51:16 +0000 | [diff] [blame] | 59 | do_test shared3-2.4 { |
| 60 | execsql { PRAGMA main.cache_size } db2 |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 61 | } {10} |
danielk1977 | 9324c8f | 2008-06-20 17:51:16 +0000 | [diff] [blame] | 62 | do_test shared3-2.5 { |
| 63 | execsql { PRAGMA main.cache_size } db1 |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 64 | } {10} |
| 65 | |
| 66 | # The cache-size should now be 10 pages. However at one point there was |
| 67 | # a bug that caused the cache size to return to the default value when |
| 68 | # a second connection was opened on the shared-cache (as happened in |
| 69 | # test case shared3-2.3 above). The goal of the following tests is to |
| 70 | # ensure that the cache-size really is 10 pages. |
| 71 | # |
| 72 | if {$::tcl_platform(platform)=="unix"} { |
| 73 | set alternative_name ./test.db |
| 74 | } else { |
| 75 | set alternative_name TEST.DB |
| 76 | } |
| 77 | do_test shared3-2.6 { |
| 78 | sqlite3 db3 $alternative_name |
| 79 | catchsql {select count(*) from sqlite_master} db3 |
| 80 | } {0 1} |
| 81 | do_test shared3-2.7 { |
| 82 | execsql { |
| 83 | BEGIN; |
| 84 | INSERT INTO t1 VALUES(10, randomblob(5000)) |
| 85 | } db1 |
| 86 | catchsql {select count(*) from sqlite_master} db3 |
| 87 | } {0 1} |
| 88 | do_test shared3-2.8 { |
danielk1977 | 8c0a791 | 2008-08-20 14:49:23 +0000 | [diff] [blame] | 89 | db3 close |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 90 | execsql { |
| 91 | INSERT INTO t1 VALUES(10, randomblob(10000)) |
| 92 | } db1 |
| 93 | |
| 94 | # If the pager-cache is really still limited to 10 pages, then the INSERT |
| 95 | # statement above should have caused the pager to grab an exclusive lock |
| 96 | # on the database file so that the cache could be spilled. |
| 97 | # |
dan | cb35460 | 2010-07-08 09:44:42 +0000 | [diff] [blame] | 98 | catch { sqlite3 db3 $alternative_name } |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 99 | catchsql {select count(*) from sqlite_master} db3 |
| 100 | } {1 {database is locked}} |
danielk1977 | 9324c8f | 2008-06-20 17:51:16 +0000 | [diff] [blame] | 101 | |
| 102 | db1 close |
| 103 | db2 close |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 104 | db3 close |
danielk1977 | 9324c8f | 2008-06-20 17:51:16 +0000 | [diff] [blame] | 105 | |
drh | f012ea3 | 2006-05-24 12:43:26 +0000 | [diff] [blame] | 106 | sqlite3_enable_shared_cache $::enable_shared_cache |
| 107 | finish_test |