sqlite/test/trans.test
drh c73d1f5a55 Enchanced transaction tests (CVS 253)
FossilOrigin-Name: b30f2b5e150a219c374f88d13386dbda190ad9ed
2001-09-17 20:48:30 +00:00

277 lines
6.3 KiB
Plaintext

# 2001 September 15
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is database locks.
#
# $Id: trans.test,v 1.5 2001/09/17 20:48:30 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Create several tables to work with.
#
do_test trans-1.0 {
execsql {
CREATE TABLE one(a int PRIMARY KEY, b text);
INSERT INTO one VALUES(1,'one');
INSERT INTO one VALUES(2,'two');
INSERT INTO one VALUES(3,'three');
SELECT b FROM one ORDER BY a;
}
} {one two three}
do_test trans-1.1 {
execsql {
CREATE TABLE two(a int PRIMARY KEY, b text);
INSERT INTO two VALUES(1,'I');
INSERT INTO two VALUES(5,'V');
INSERT INTO two VALUES(10,'X');
SELECT b FROM two ORDER BY a;
}
} {I V X}
do_test trans-1.9 {
sqlite altdb test.db
execsql {SELECT b FROM one ORDER BY a} altdb
} {one two three}
do_test trans-1.10 {
execsql {SELECT b FROM two ORDER BY a} altdb
} {I V X}
# Basic transactions
#
do_test trans-2.1 {
set v [catch {execsql {BEGIN}} msg]
lappend v $msg
} {0 {}}
do_test trans-2.2 {
set v [catch {execsql {END}} msg]
lappend v $msg
} {0 {}}
do_test trans-2.3 {
set v [catch {execsql {BEGIN TRANSACTION}} msg]
lappend v $msg
} {0 {}}
do_test trans-2.4 {
set v [catch {execsql {COMMIT TRANSACTION}} msg]
lappend v $msg
} {0 {}}
do_test trans-2.5 {
set v [catch {execsql {BEGIN TRANSACTION 'foo'}} msg]
lappend v $msg
} {0 {}}
do_test trans-2.6 {
set v [catch {execsql {ROLLBACK TRANSACTION 'foo'}} msg]
lappend v $msg
} {0 {}}
do_test trans-2.10 {
execsql {
BEGIN;
SELECT a FROM one ORDER BY a;
SELECT a FROM two ORDER BY a;
END;
}
} {1 2 3 1 5 10}
# Check the locking behavior
#
do_test trans-3.1 {
execsql {
BEGIN;
SELECT a FROM one ORDER BY a;
}
} {1 2 3}
do_test trans-3.2 {
set v [catch {execsql {
SELECT a FROM two ORDER BY a;
} altdb} msg]
lappend v $msg
} {1 {database in use by another process}}
do_test trans-3.3 {
set v [catch {execsql {
SELECT a FROM one ORDER BY a;
} altdb} msg]
lappend v $msg
} {1 {database in use by another process}}
do_test trans-3.4 {
set v [catch {execsql {
INSERT INTO one VALUES(4,'four');
}} msg]
lappend v $msg
} {0 {}}
do_test trans-3.5 {
set v [catch {execsql {
SELECT a FROM two ORDER BY a;
} altdb} msg]
lappend v $msg
} {1 {database in use by another process}}
do_test trans-3.6 {
set v [catch {execsql {
SELECT a FROM one ORDER BY a;
} altdb} msg]
lappend v $msg
} {1 {database in use by another process}}
do_test trans-3.7 {
set v [catch {execsql {
INSERT INTO two VALUES(4,'IV');
}} msg]
lappend v $msg
} {0 {}}
do_test trans-3.8 {
set v [catch {execsql {
SELECT a FROM two ORDER BY a;
} altdb} msg]
lappend v $msg
} {1 {database in use by another process}}
do_test trans-3.9 {
set v [catch {execsql {
SELECT a FROM one ORDER BY a;
} altdb} msg]
lappend v $msg
} {1 {database in use by another process}}
do_test trans-3.10 {
execsql {END TRANSACTION}
} {}
do_test trans-3.11 {
set v [catch {execsql {
SELECT a FROM two ORDER BY a;
} altdb} msg]
lappend v $msg
} {0 {1 4 5 10}}
do_test trans-3.12 {
set v [catch {execsql {
SELECT a FROM one ORDER BY a;
} altdb} msg]
lappend v $msg
} {0 {1 2 3 4}}
do_test trans-3.13 {
set v [catch {execsql {
SELECT a FROM two ORDER BY a;
} db} msg]
lappend v $msg
} {0 {1 4 5 10}}
do_test trans-3.14 {
set v [catch {execsql {
SELECT a FROM one ORDER BY a;
} db} msg]
lappend v $msg
} {0 {1 2 3 4}}
do_test trans-4.1 {
set v [catch {execsql {
COMMIT;
} db} msg]
lappend v $msg
} {0 {}}
do_test trans-4.2 {
set v [catch {execsql {
ROLLBACK;
} db} msg]
lappend v $msg
} {0 {}}
do_test trans-4.3 {
set v [catch {execsql {
BEGIN TRANSACTION;
SELECT a FROM two ORDER BY a;
} db} msg]
lappend v $msg
} {0 {1 4 5 10}}
do_test trans-4.4 {
set v [catch {execsql {
SELECT a FROM two ORDER BY a;
} altdb} msg]
lappend v $msg
} {1 {database in use by another process}}
do_test trans-4.5 {
set v [catch {execsql {
SELECT a FROM one ORDER BY a;
} altdb} msg]
lappend v $msg
} {1 {database in use by another process}}
do_test trans-4.6 {
set v [catch {execsql {
BEGIN TRANSACTION;
SELECT a FROM one ORDER BY a;
} db} msg]
lappend v $msg
} {0 {1 2 3 4}}
do_test trans-4.7 {
set v [catch {execsql {
SELECT a FROM two ORDER BY a;
} altdb} msg]
lappend v $msg
} {1 {database in use by another process}}
do_test trans-4.8 {
set v [catch {execsql {
SELECT a FROM one ORDER BY a;
} altdb} msg]
lappend v $msg
} {1 {database in use by another process}}
do_test trans-4.9 {
set v [catch {execsql {
END TRANSACTION;
SELECT a FROM two ORDER BY a;
} db} msg]
lappend v $msg
} {0 {1 4 5 10}}
do_test trans-4.10 {
set v [catch {execsql {
SELECT a FROM two ORDER BY a;
} altdb} msg]
lappend v $msg
} {0 {1 4 5 10}}
do_test trans-4.11 {
set v [catch {execsql {
SELECT a FROM one ORDER BY a;
} altdb} msg]
lappend v $msg
} {0 {1 2 3 4}}
do_test trans-4.99 {
altdb close
execsql {
DROP TABLE one;
DROP TABLE two;
}
} {}
# Check out the commit/rollback behavior of the database
#
do_test trans-5.1 {
execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name}
} {}
do_test trans-5.2 {
execsql {BEGIN TRANSACTION}
execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name}
} {}
do_test trans-5.3 {
execsql {CREATE TABLE one(a text, b int)}
execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name}
} {one}
do_test trans-5.4 {
execsql {SELECT a,b FROM one ORDER BY b}
} {}
do_test trans-5.5 {
execsql {INSERT INTO one(a,b) VALUES('hello', 1)}
execsql {SELECT a,b FROM one ORDER BY b}
} {hello 1}
do_test trans-5.6 {
execsql {ROLLBACK}
execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name}
} {}
do_test trans-5.7 {
set v [catch {
execsql {SELECT a,b FROM one ORDER BY b}
} msg]
lappend v $msg
} {1 {no such table: one}}
finish_test