mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Fix some errors to do with attached databases and text encodings in shared-cache mode. (CVS 2895)
FossilOrigin-Name: 3e75d3d5efebc0dfff1adfc13d85e85ec39db3eb
This commit is contained in:
@ -8,10 +8,8 @@
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the SELECT statement.
|
||||
#
|
||||
# $Id: shared.test,v 1.7 2006/01/09 06:29:49 danielk1977 Exp $
|
||||
# $Id: shared.test,v 1.8 2006/01/09 16:12:05 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -35,7 +33,7 @@ set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
|
||||
# shared-5.*: Test that creating/dropping schema items works when databases
|
||||
# are attached in different orders to different handles.
|
||||
# shared-6.*: Locking, UNION ALL queries and sub-queries.
|
||||
# shared-6.*: Autovacuum and shared-cache.
|
||||
# shared-7.*: Autovacuum and shared-cache.
|
||||
#
|
||||
|
||||
do_test shared-1.1 {
|
||||
@ -475,6 +473,10 @@ foreach f [list test.db test2.db] {
|
||||
# COMMIT.
|
||||
#
|
||||
do_test shared-7.1 {
|
||||
# This test case sets up a test database in auto-vacuum mode consisting
|
||||
# of two tables, t1 and t2. Both have a single index. Table t1 is
|
||||
# populated first (so consists of pages toward the start of the db file),
|
||||
# t2 second (pages toward the end of the file).
|
||||
sqlite3 db test.db
|
||||
sqlite3 db2 test.db
|
||||
execsql {
|
||||
@ -500,6 +502,13 @@ do_test shared-7.1 {
|
||||
}
|
||||
} {1}
|
||||
do_test shared-7.2 {
|
||||
# This test case deletes the contents of table t1 (the one at the start of
|
||||
# the file) while many cursors are open on table t2 and it's index. All of
|
||||
# the non-root pages will be moved from the end to the start of the file
|
||||
# when the DELETE is committed - this test verifies that moving the pages
|
||||
# does not disturb the open cursors.
|
||||
#
|
||||
|
||||
proc lockrow {db tbl oids body} {
|
||||
set ret [list]
|
||||
db eval "SELECT oid AS i, a, b FROM $tbl ORDER BY a" {
|
||||
@ -526,6 +535,8 @@ do_test shared-7.2 {
|
||||
} db2
|
||||
}]
|
||||
set error 0
|
||||
|
||||
# Test that each SELECT query returned the expected contents of t2.
|
||||
foreach s $scans {
|
||||
if {[lsort -integer -index 0 $s]!=$::contents} {
|
||||
set error 1
|
||||
@ -537,6 +548,63 @@ do_test shared-7.2 {
|
||||
catch {db close}
|
||||
catch {db2 close}
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# The following tests try to trick the shared-cache code into assuming
|
||||
# the wrong encoding for a database.
|
||||
#
|
||||
file delete -force test.db test.db-journal
|
||||
do_test shared-8.1.1 {
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
PRAGMA encoding = 'UTF-16';
|
||||
SELECT * FROM sqlite_master;
|
||||
}
|
||||
} {}
|
||||
do_test shared-8.1.2 {
|
||||
string range [execsql {PRAGMA encoding;}] 0 end-2
|
||||
} {UTF-16}
|
||||
do_test shared-8.1.3 {
|
||||
sqlite3 db2 test.db
|
||||
execsql {
|
||||
PRAGMA encoding = 'UTF-8';
|
||||
CREATE TABLE abc(a, b, c);
|
||||
} db2
|
||||
} {}
|
||||
do_test shared-8.1.4 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_master;
|
||||
}
|
||||
} "table abc abc [expr $AUTOVACUUM?3:2] {CREATE TABLE abc(a, b, c)}"
|
||||
do_test shared-8.1.5 {
|
||||
db2 close
|
||||
execsql {
|
||||
PRAGMA encoding;
|
||||
}
|
||||
} {UTF-8}
|
||||
file delete -force test2.db test2.db-journal
|
||||
do_test shared-8.2.1 {
|
||||
execsql {
|
||||
ATTACH 'test2.db' AS aux;
|
||||
SELECT * FROM aux.sqlite_master;
|
||||
}
|
||||
} {}
|
||||
do_test shared-8.2.2 {
|
||||
sqlite3 db2 test2.db
|
||||
execsql {
|
||||
PRAGMA encoding = 'UTF-16';
|
||||
CREATE TABLE def(d, e, f);
|
||||
} db2
|
||||
string range [execsql {PRAGMA encoding;} db2] 0 end-2
|
||||
} {UTF-16}
|
||||
do_test shared-8.2.3 {
|
||||
catchsql {
|
||||
SELECT * FROM aux.sqlite_master;
|
||||
}
|
||||
} {1 {attached databases must use the same text encoding as main database}}
|
||||
|
||||
catch {db close}
|
||||
catch {db2 close}
|
||||
|
||||
finish_test
|
||||
sqlite3_enable_shared_cache $::enable_shared_cache
|
||||
|
||||
|
Reference in New Issue
Block a user