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 |
dan | 56c517a | 2013-09-26 11:04:33 +0000 | [diff] [blame] | 16 | set testprefix shared3 |
drh | f012ea3 | 2006-05-24 12:43:26 +0000 | [diff] [blame] | 17 | db close |
| 18 | |
| 19 | ifcapable !shared_cache { |
| 20 | finish_test |
| 21 | return |
| 22 | } |
| 23 | set ::enable_shared_cache [sqlite3_enable_shared_cache 1] |
| 24 | |
| 25 | # Ticket #1824 |
| 26 | # |
| 27 | do_test shared3-1.1 { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 28 | forcedelete test.db test.db-journal |
drh | f012ea3 | 2006-05-24 12:43:26 +0000 | [diff] [blame] | 29 | sqlite3 db1 test.db |
| 30 | db1 eval { |
| 31 | PRAGMA encoding=UTF16; |
| 32 | CREATE TABLE t1(x,y); |
| 33 | INSERT INTO t1 VALUES('abc','This is a test string'); |
| 34 | } |
| 35 | db1 close |
| 36 | sqlite3 db1 test.db |
| 37 | db1 eval {SELECT * FROM t1} |
| 38 | } {abc {This is a test string}} |
| 39 | do_test shared3-1.2 { |
| 40 | sqlite3 db2 test.db |
| 41 | db2 eval {SELECT y FROM t1 WHERE x='abc'} |
| 42 | } {{This is a test string}} |
| 43 | |
| 44 | db1 close |
| 45 | db2 close |
| 46 | |
danielk1977 | 9324c8f | 2008-06-20 17:51:16 +0000 | [diff] [blame] | 47 | do_test shared3-2.1 { |
| 48 | sqlite3 db1 test.db |
| 49 | execsql { |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 50 | PRAGMA main.cache_size = 10; |
danielk1977 | 9324c8f | 2008-06-20 17:51:16 +0000 | [diff] [blame] | 51 | } db1 |
| 52 | } {} |
| 53 | do_test shared3-2.2 { |
| 54 | execsql { PRAGMA main.cache_size } db1 |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 55 | } {10} |
danielk1977 | 9324c8f | 2008-06-20 17:51:16 +0000 | [diff] [blame] | 56 | do_test shared3-2.3 { |
| 57 | sqlite3 db2 test.db |
| 58 | execsql { PRAGMA main.cache_size } db1 |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 59 | } {10} |
danielk1977 | 9324c8f | 2008-06-20 17:51:16 +0000 | [diff] [blame] | 60 | do_test shared3-2.4 { |
| 61 | execsql { PRAGMA main.cache_size } db2 |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 62 | } {10} |
danielk1977 | 9324c8f | 2008-06-20 17:51:16 +0000 | [diff] [blame] | 63 | do_test shared3-2.5 { |
| 64 | execsql { PRAGMA main.cache_size } db1 |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 65 | } {10} |
| 66 | |
| 67 | # The cache-size should now be 10 pages. However at one point there was |
| 68 | # a bug that caused the cache size to return to the default value when |
| 69 | # a second connection was opened on the shared-cache (as happened in |
| 70 | # test case shared3-2.3 above). The goal of the following tests is to |
| 71 | # ensure that the cache-size really is 10 pages. |
| 72 | # |
drh | e5dc4a2 | 2020-11-19 21:01:11 +0000 | [diff] [blame] | 73 | #if {$::tcl_platform(platform)=="unix"} { |
| 74 | # set alternative_name ./test.db |
| 75 | #} else { |
| 76 | # set alternative_name TEST.DB |
| 77 | #} |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 78 | do_test shared3-2.6 { |
drh | e5dc4a2 | 2020-11-19 21:01:11 +0000 | [diff] [blame] | 79 | #sqlite3 db3 $alternative_name |
| 80 | sqlite3 db3 "file:./test.db?cache=private" -uri 1 |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 81 | catchsql {select count(*) from sqlite_master} db3 |
| 82 | } {0 1} |
| 83 | do_test shared3-2.7 { |
| 84 | execsql { |
| 85 | BEGIN; |
| 86 | INSERT INTO t1 VALUES(10, randomblob(5000)) |
| 87 | } db1 |
| 88 | catchsql {select count(*) from sqlite_master} db3 |
| 89 | } {0 1} |
| 90 | do_test shared3-2.8 { |
danielk1977 | 8c0a791 | 2008-08-20 14:49:23 +0000 | [diff] [blame] | 91 | db3 close |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 92 | execsql { |
| 93 | INSERT INTO t1 VALUES(10, randomblob(10000)) |
| 94 | } db1 |
| 95 | |
| 96 | # If the pager-cache is really still limited to 10 pages, then the INSERT |
| 97 | # statement above should have caused the pager to grab an exclusive lock |
| 98 | # on the database file so that the cache could be spilled. |
| 99 | # |
drh | e5dc4a2 | 2020-11-19 21:01:11 +0000 | [diff] [blame] | 100 | catch { sqlite3 db3 "file:./test.db?cache=private" -uri 1 } |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 101 | catchsql {select count(*) from sqlite_master} db3 |
| 102 | } {1 {database is locked}} |
danielk1977 | 9324c8f | 2008-06-20 17:51:16 +0000 | [diff] [blame] | 103 | |
| 104 | db1 close |
| 105 | db2 close |
danielk1977 | 171bfed | 2008-06-23 09:50:50 +0000 | [diff] [blame] | 106 | db3 close |
danielk1977 | 9324c8f | 2008-06-20 17:51:16 +0000 | [diff] [blame] | 107 | |
dan | 56c517a | 2013-09-26 11:04:33 +0000 | [diff] [blame] | 108 | #------------------------------------------------------------------------- |
| 109 | # At one point this was causing a faulty assert to fail. |
| 110 | # |
| 111 | forcedelete test.db |
| 112 | sqlite3 db test.db |
| 113 | sqlite3 db2 test.db |
| 114 | do_execsql_test 3.1 { |
| 115 | PRAGMA auto_vacuum = 2; |
| 116 | CREATE TABLE t1(x, y); |
| 117 | INSERT INTO t1 VALUES(randomblob(500), randomblob(500)); |
| 118 | INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; |
| 119 | INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; |
| 120 | INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; |
| 121 | INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; |
| 122 | INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; |
| 123 | INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; |
| 124 | INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; |
| 125 | } |
| 126 | do_test 3.2 { |
| 127 | execsql { SELECT count(*) FROM sqlite_master } db2 |
| 128 | } {1} |
| 129 | do_execsql_test 3.3 { |
| 130 | BEGIN; |
| 131 | DELETE FROM t1 WHERE 1; |
| 132 | PRAGMA incremental_vacuum; |
| 133 | } {} |
| 134 | do_test 3.4 { |
| 135 | execsql { SELECT count(*) FROM sqlite_master } db2 |
| 136 | } {1} |
| 137 | do_test 3.5 { |
| 138 | execsql { COMMIT } |
| 139 | } {} |
| 140 | |
drh | f012ea3 | 2006-05-24 12:43:26 +0000 | [diff] [blame] | 141 | sqlite3_enable_shared_cache $::enable_shared_cache |
| 142 | finish_test |