000001  # 2009 April 30
000002  #
000003  # The author disclaims copyright to this source code.  In place of
000004  # a legal notice, here is a blessing:
000005  #
000006  #    May you do good and not evil.
000007  #    May you find forgiveness for yourself and forgive others.
000008  #    May you share freely, never taking more than you give.
000009  #
000010  #***********************************************************************
000011  #
000012  # Make sure that attaching the same database multiple times in
000013  # shared cache mode fails.
000014  #
000015  # $Id: shared7.test,v 1.1 2009/04/30 13:30:33 drh Exp $
000016  
000017  set testdir [file dirname $argv0]
000018  source $testdir/tester.tcl
000019  ifcapable !shared_cache { finish_test ; return }
000020  
000021  do_test shared7-1.1 {
000022    set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
000023    sqlite3_enable_shared_cache
000024  } {1}
000025  
000026  # EVIDENCE-OF: R-05098-06501 In shared cache mode, attempting to attach
000027  # the same database file more than once results in an error.
000028  #
000029  do_test shared7-1.2 {
000030    db close
000031    sqlite3 db test.db
000032    db eval {
000033      CREATE TABLE t1(x);
000034    }
000035    catchsql {
000036      ATTACH 'test.db' AS err1;
000037    }
000038  } {1 {database is already attached}}
000039  
000040  do_test shared7-1.3 {
000041    forcedelete test2.db test2.db-journal
000042    db eval {
000043      ATTACH 'test2.db' AS test2;
000044      CREATE TABLE test2.t2(y);
000045    }
000046    catchsql {
000047      ATTACH 'test2.db' AS err2;
000048    }
000049  } {1 {database is already attached}}
000050  do_test shared7-1.4 {
000051    catchsql {
000052      ATTACH 'test.db' AS err1;
000053    }
000054  } {1 {database is already attached}}
000055  
000056  
000057  sqlite3_enable_shared_cache $::enable_shared_cache
000058  finish_test