# 2001 October 7 # # 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. # # This file implements tests for temporary tables and indices. # # $Id: temptable.test,v 1.1 2001/10/08 13:22:33 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create an alternative connection to the database # do_test temptable-1.0 { sqlite db2 ./test.db } {} # Create a permanent table. # do_test temptable-1.1 { execsql {CREATE TABLE t1(a,b,c);} execsql {INSERT INTO t1 VALUES(1,2,3);} execsql {SELECT * FROM t1} } {1 2 3} do_test temptable-1.2 { catch {db2 eval {SELECT * FROM sqlite_master}} db2 eval {SELECT * FROM t1} } {1 2 3} do_test testtable-1.3 { execsql {SELECT name FROM sqlite_master} } {t1} do_test testtable-1.4 { db2 eval {SELECT name FROM sqlite_master} } {t1} # Create a temporary table. Verify that only one of the two # processes can see it. # do_test testtable-1.5 { db2 eval { CREATE TEMP TABLE t2(x,y,z); INSERT INTO t2 VALUES(4,5,6); } db2 eval {SELECT * FROM t2} } {4 5 6} do_test testtable-1.6 { catch {execsql {SELECT * FROM sqlite_master}} catchsql {SELECT * FROM t2} } {1 {no such table: t2}} do_test testtable-1.7 { catchsql {INSERT INTO t2 VALUES(8,9,0);} } {1 {no such table: t2}} do_test testtable-1.8 { db2 eval {INSERT INTO t2 VALUES(8,9,0);} db2 eval {SELECT * FROM t2 ORDER BY x} } {4 5 6 8 9 0} do_test testtable-1.9 { db2 eval {DELETE FROM t2 WHERE x==8} db2 eval {SELECT * FROM t2 ORDER BY x} } {4 5 6} do_test testtable-1.10 { db2 eval {DELETE FROM t2} db2 eval {SELECT * FROM t2} } {} do_test testtable-1.11 { db2 eval { INSERT INTO t2 VALUES(7,6,5); INSERT INTO t2 VALUES(4,3,2); SELECT * FROM t2 ORDER BY x; } } {4 3 2 7 6 5} do_test testtable-1.12 { db2 eval {DROP TABLE t2;} set r [catch {db2 eval {SELECT * FROM t2}} msg] lappend r $msg } {1 {no such table: t2}} # Make sure temporary tables work with transactions # do_test testtable-2.1 { execsql { BEGIN TRANSACTION; CREATE TEMPORARY TABLE t2(x,y); INSERT INTO t2 VALUES(1,2); SELECT * FROM t2; } } {1 2} do_test testtable-2.2 { execsql {ROLLBACK} catchsql {SELECT * FROM t2} } {1 {no such table: t2}} do_test testtable-2.3 { execsql { BEGIN TRANSACTION; CREATE TEMPORARY TABLE t2(x,y); INSERT INTO t2 VALUES(1,2); SELECT * FROM t2; } } {1 2} do_test testtable-2.4 { execsql {COMMIT} catchsql {SELECT * FROM t2} } {0 {1 2}} do_test testtable-2.5 { set r [catch {db2 eval {SELECT * FROM t2}} msg] lappend r $msg } {1 {no such table: t2}} # Check for correct name collision processing. A name collision can # occur when process A creates a temporary table T then process B # creates a permanent table also named T. The temp table in process A # hides the existance of the permanent table. # finish_test