os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/shared3.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/shared3.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,107 @@
     1.4 +# 2005 January 19
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +#
    1.15 +# $Id: shared3.test,v 1.4 2008/08/20 14:49:25 danielk1977 Exp $
    1.16 +
    1.17 +set testdir [file dirname $argv0]
    1.18 +source $testdir/tester.tcl
    1.19 +db close
    1.20 +
    1.21 +ifcapable !shared_cache {
    1.22 +  finish_test
    1.23 +  return
    1.24 +}
    1.25 +set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
    1.26 +
    1.27 +# Ticket #1824
    1.28 +#
    1.29 +do_test shared3-1.1 {
    1.30 +  file delete -force test.db test.db-journal
    1.31 +  sqlite3 db1 test.db
    1.32 +  db1 eval {
    1.33 +    PRAGMA encoding=UTF16;
    1.34 +    CREATE TABLE t1(x,y);
    1.35 +    INSERT INTO t1 VALUES('abc','This is a test string');
    1.36 +  }
    1.37 +  db1 close
    1.38 +  sqlite3 db1 test.db
    1.39 +  db1 eval {SELECT * FROM t1}
    1.40 +} {abc {This is a test string}}
    1.41 +do_test shared3-1.2 {
    1.42 +  sqlite3 db2 test.db
    1.43 +  db2 eval {SELECT y FROM t1 WHERE x='abc'}
    1.44 +} {{This is a test string}}
    1.45 +
    1.46 +db1 close
    1.47 +db2 close
    1.48 +
    1.49 +do_test shared3-2.1 {
    1.50 +  sqlite3 db1 test.db
    1.51 +  execsql {
    1.52 +    PRAGMA main.cache_size = 10;
    1.53 +  } db1
    1.54 +} {}
    1.55 +do_test shared3-2.2 {
    1.56 +  execsql { PRAGMA main.cache_size } db1
    1.57 +} {10}
    1.58 +do_test shared3-2.3 {
    1.59 +  sqlite3 db2 test.db
    1.60 +  execsql { PRAGMA main.cache_size } db1
    1.61 +} {10}
    1.62 +do_test shared3-2.4 {
    1.63 +  execsql { PRAGMA main.cache_size } db2
    1.64 +} {10}
    1.65 +do_test shared3-2.5 {
    1.66 +  execsql { PRAGMA main.cache_size } db1
    1.67 +} {10}
    1.68 +
    1.69 +# The cache-size should now be 10 pages. However at one point there was
    1.70 +# a bug that caused the cache size to return to the default value when
    1.71 +# a second connection was opened on the shared-cache (as happened in
    1.72 +# test case shared3-2.3 above). The goal of the following tests is to
    1.73 +# ensure that the cache-size really is 10 pages.
    1.74 +#
    1.75 +if {$::tcl_platform(platform)=="unix"} {
    1.76 +  set alternative_name ./test.db
    1.77 +} else {
    1.78 +  set alternative_name TEST.DB
    1.79 +}
    1.80 +do_test shared3-2.6 {
    1.81 +  sqlite3 db3 $alternative_name
    1.82 +  catchsql {select count(*) from sqlite_master} db3
    1.83 +} {0 1}
    1.84 +do_test shared3-2.7 {
    1.85 +  execsql {
    1.86 +    BEGIN;
    1.87 +    INSERT INTO t1 VALUES(10, randomblob(5000))
    1.88 +  } db1
    1.89 +  catchsql {select count(*) from sqlite_master} db3
    1.90 +} {0 1}
    1.91 +do_test shared3-2.8 {
    1.92 +  db3 close
    1.93 +  execsql {
    1.94 +    INSERT INTO t1 VALUES(10, randomblob(10000))
    1.95 +  } db1
    1.96 +  sqlite3 db3 $alternative_name
    1.97 +
    1.98 +  # If the pager-cache is really still limited to 10 pages, then the INSERT
    1.99 +  # statement above should have caused the pager to grab an exclusive lock
   1.100 +  # on the database file so that the cache could be spilled.
   1.101 +  #
   1.102 +  catchsql {select count(*) from sqlite_master} db3
   1.103 +} {1 {database is locked}}
   1.104 +
   1.105 +db1 close
   1.106 +db2 close
   1.107 +db3 close
   1.108 +
   1.109 +sqlite3_enable_shared_cache $::enable_shared_cache
   1.110 +finish_test