attach2.test revision 2
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A# 2003 July 1
2N/A#
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
2N/A#
2N/A# May you do good and not evil.
2N/A# May you find forgiveness for yourself and forgive others.
2N/A# May you share freely, never taking more than you give.
2N/A#
2N/A#***********************************************************************
2N/A# This file implements regression tests for SQLite library. The
2N/A# focus of this script is testing the ATTACH and DETACH commands
2N/A# and related functionality.
2N/A#
2N/A# $Id: attach2.test,v 1.5 2004/02/12 15:31:22 drh Exp $
2N/A#
2N/A
2N/A
2N/Aset testdir [file dirname $argv0]
2N/Asource $testdir/tester.tcl
2N/A
2N/A# Ticket #354
2N/A#
2N/Ado_test attach2-1.1 {
2N/A db eval {
2N/A CREATE TABLE t1(a,b);
2N/A CREATE INDEX x1 ON t1(a);
2N/A }
2N/A file delete -force test2.db
2N/A file delete -force test2.db-journal
2N/A sqlite db2 test2.db
2N/A db2 eval {
2N/A CREATE TABLE t1(a,b);
2N/A CREATE INDEX x1 ON t1(a);
2N/A }
2N/A catchsql {
2N/A ATTACH 'test2.db' AS t2;
2N/A }
2N/A} {0 {}}
2N/A
2N/A# Ticket #514
2N/A#
2N/Aproc db_list {db} {
2N/A set list {}
2N/A foreach {idx name file} [execsql {PRAGMA database_list} $db] {
2N/A lappend list $idx $name
2N/A }
2N/A return $list
2N/A}
2N/Adb eval {DETACH t2}
2N/Ado_test attach2-2.1 {
2N/A # lock test2.db then try to attach it. Should get an error.
2N/A db2 eval {BEGIN}
2N/A catchsql {
2N/A ATTACH 'test2.db' AS t2;
2N/A }
2N/A} {1 {database is locked}}
2N/Ado_test attach2-2.2 {
2N/A # make sure test2.db did not get attached.
2N/A db_list db
2N/A} {0 main 1 temp}
2N/Ado_test attach2-2.3 {
2N/A # unlock test2.db and try to attach again. should work this time.
2N/A db2 eval {COMMIT}
2N/A catchsql {
2N/A ATTACH 'test2.db' AS t2;
2N/A }
2N/A} {0 {}}
2N/Ado_test attach2-2.4 {
2N/A db_list db
2N/A} {0 main 1 temp 2 t2}
2N/Ado_test attach2-2.5 {
2N/A catchsql {
2N/A SELECT name FROM t2.sqlite_master;
2N/A }
2N/A} {0 {t1 x1}}
2N/Ado_test attach2-2.6 {
2N/A # lock test2.db and try to read from it. should get an error.
2N/A db2 eval BEGIN
2N/A catchsql {
2N/A SELECT name FROM t2.sqlite_master;
2N/A }
2N/A} {1 {database is locked}}
2N/Ado_test attach2-2.7 {
2N/A # but we can still read from test1.db even though test2.db is locked.
2N/A catchsql {
2N/A SELECT name FROM main.sqlite_master;
2N/A }
2N/A} {0 {t1 x1}}
2N/Ado_test attach2-2.8 {
2N/A # start a transaction on test.db even though test2.db is locked.
2N/A catchsql {
2N/A BEGIN;
2N/A INSERT INTO t1 VALUES(8,9);
2N/A }
2N/A} {0 {}}
2N/Ado_test attach2-2.9 {
2N/A execsql {
2N/A SELECT * FROM t1
2N/A }
2N/A} {8 9}
2N/Ado_test attach2-2.10 {
2N/A # now try to write to test2.db. the write should fail
2N/A catchsql {
2N/A INSERT INTO t2.t1 VALUES(1,2);
2N/A }
2N/A} {1 {database is locked}}
2N/Ado_test attach2-2.11 {
2N/A # when the write failed in the previous test, the transaction should
2N/A # have rolled back.
2N/A db2 eval ROLLBACK
2N/A execsql {
2N/A SELECT * FROM t1
2N/A }
2N/A} {}
2N/Ado_test attach2-2.12 {
2N/A catchsql {
2N/A COMMIT
2N/A }
2N/A} {1 {cannot commit - no transaction is active}}
2N/A
2N/A# Ticket #574: Make sure it works usingi the non-callback API
2N/A#
2N/Ado_test attach2-3.1 {
2N/A db close
2N/A set DB [sqlite db test.db]
2N/A set rc [catch {sqlite_compile $DB "ATTACH 'test2.db' AS t2" TAIL} VM]
2N/A if {$rc} {lappend rc $VM}
2N/A sqlite_finalize $VM
2N/A set rc
2N/A} {0}
2N/Ado_test attach2-3.2 {
2N/A set rc [catch {sqlite_compile $DB "DETACH t2" TAIL} VM]
2N/A if {$rc} {lappend rc $VM}
2N/A sqlite_finalize $VM
2N/A set rc
2N/A} {0}
2N/A
2N/Adb close
2N/Afor {set i 2} {$i<=15} {incr i} {
2N/A catch {db$i close}
2N/A}
2N/Afile delete -force test2.db
2N/A
2N/A
2N/Afinish_test