Ensure tables cannot be created/dropped when btree cursors are open. (CVS 2085)

FossilOrigin-Name: 8e5c2e5df8b824f7efb27e776240f005c6f1f0ff
This commit is contained in:
danielk1977
2004-11-10 11:55:10 +00:00
parent 2a03c3a326
commit e6efa74b9f
9 changed files with 142 additions and 43 deletions
+74 -3
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the CREATE TABLE statement.
#
# $Id: table.test,v 1.32 2004/11/09 16:13:33 danielk1977 Exp $
# $Id: table.test,v 1.33 2004/11/10 11:55:15 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -524,6 +524,9 @@ do_test table-12.2 {
}
} {{CREATE TABLE t8(b number(5,10),h,i integer,j BLOB)}}
#--------------------------------------------------------------------
# Test cases table-13.*
#
# Test the ability to have default values of CURRENT_TIME, CURRENT_DATE
# and CURRENT_TIMESTAMP.
#
@@ -546,8 +549,8 @@ foreach {date time} {
2003-12-31 12:34:56
} {
incr i
# set sqlite_current_time [execsql "SELECT strftime('%s','$date $time')"]
set sqlite_current_time [clock scan "$date $time"]
set sqlite_current_time [clock scan "$date $time" -gmt 1]
# set sqlite_current_time [execsql "SELECT strftime('%s','$date $time')"]
do_test table-13.2.$i {
execsql "
INSERT INTO tablet8(a) VALUES($i);
@@ -557,4 +560,72 @@ foreach {date time} {
}
set sqlite_current_time 0
#--------------------------------------------------------------------
# Test cases table-14.*
#
# Test that a table cannot be created or dropped while other virtual
# machines are active. This is required because otherwise when in
# auto-vacuum mode the btree-layer may need to move the root-pages of
# a table for which there is an open cursor.
#
# Try to create a table from within a callback:
do_test table-14.1 {
set rc [
catch {
db eval {SELECT * FROM tablet8 LIMIT 1} {} {
db eval {CREATE TABLE t9(a, b, c)}
}
} msg
]
set result [list $rc $msg]
} {1 {database table is locked}}
do_test table-14.2 {
execsql {
CREATE TABLE t9(a, b, c)
}
} {}
# Try to drop a table from within a callback:
do_test table-14.3 {
set rc [
catch {
db eval {SELECT * FROM tablet8 LIMIT 1} {} {
db eval {DROP TABLE t9;}
}
} msg
]
set result [list $rc $msg]
} {1 {database table is locked}}
# Now attach a database and ensure that a table can be created in the
# attached database whilst in a callback from a query on the main database.
do_test table-14.4 {
file delete -force test2.db
file delete -force test2.db-journal
execsql {
attach 'test2.db' as aux;
}
db eval {SELECT * FROM tablet8 LIMIT 1} {} {
db eval {CREATE TABLE aux.t1(a, b, c)}
}
} {}
# On the other hand, it should be impossible to drop a table when any VMs
# are active. This is because VerifyCookie instructions may have already
# been executed, and btree root-pages may not move after this (which a
# delete table might do).
do_test table-14.4 {
set rc [
catch {
db eval {SELECT * FROM tablet8 LIMIT 1} {} {
db eval {DROP TABLE aux.t1;}
}
} msg
]
set result [list $rc $msg]
} {1 {database table is locked}}
finish_test