1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Check the value of the schema cookie before reading the sqlite_master table. (CVS 1585)

FossilOrigin-Name: 80c299f8839d920c61854f575498340b28db98d7
This commit is contained in:
danielk1977
2004-06-14 08:26:35 +00:00
parent 19bea40160
commit f9d19a6b3f
7 changed files with 103 additions and 33 deletions

View File

@ -13,11 +13,23 @@
# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and
# UTF-16be).
#
# $Id: enc2.test,v 1.9 2004/06/13 23:07:04 drh Exp $
# $Id: enc2.test,v 1.10 2004/06/14 08:26:37 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# The rough organisation of tests in this file is:
#
# enc2.1.*: Simple tests with a UTF-8 db.
# enc2.2.*: Simple tests with a UTF-16LE db.
# enc2.3.*: Simple tests with a UTF-16BE db.
# enc2.4.*: Test that attached databases must have the same text encoding
# as the main database.
# enc2.5.*: Test the behaviour of the library when a collation sequence is
# not available for the most desirable text encoding.
# enc2.6.*: Test that the VerifyCookie opcode protects against assuming the
# wrong text encoding for the database.
db close
# Return the UTF-8 representation of the supplied UTF-16 string $str.
@ -252,4 +264,55 @@ do_test enc2-5.11 {
lappend res $::test_collate_enc
} {one two three four five UTF-8}
db close
file delete -force test.db
# The following tests - enc2-6.* - function as follows:
#
# 1: Open an empty database file assuming UTF-16 encoding.
# 2: Open the same database with a different handle assuming UTF-8. Create
# a table using this handle.
# 3: Read the sqlite_master table from the first handle.
# 4: Ensure the first handle recognises the database encoding is UTF-8.
#
do_test enc2-6.1 {
sqlite db test.db
execsql {
PRAGMA encoding = 'UTF-16';
SELECT * FROM sqlite_master;
}
} {}
do_test enc2-6.2 {
set enc [execsql {
PRAGMA encoding;
}]
string range $enc 0 end-2 ;# Chop off the "le" or "be"
} {UTF-16}
do_test enc2-6.3 {
sqlite db2 test.db
execsql {
PRAGMA encoding = 'UTF-8';
CREATE TABLE abc(a, b, c);
} db2
} {}
do_test enc2-6.4 {
execsql {
SELECT * FROM sqlite_master;
}
} {table abc abc 2 {CREATE TABLE abc(a, b, c)}}
do_test enc2-6.5 {
execsql {
PRAGMA encoding;
}
} {UTF-8}
db close
db2 close
finish_test

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script is database locks.
#
# $Id: lock.test,v 1.24 2004/06/12 01:43:27 danielk1977 Exp $
# $Id: lock.test,v 1.25 2004/06/14 08:26:37 danielk1977 Exp $
set testdir [file dirname $argv0]
@ -43,9 +43,10 @@ do_test lock-1.6 {
execsql {INSERT INTO t1 VALUES(1,2)}
execsql {SELECT * FROM t1}
} {1 2}
do_test lock-1.7.1 {
catchsql {SELECT * FROM t1} db2
} {1 {no such table: t1}}
# Update: The schema is now brought up to date by test lock-1.5.
# do_test lock-1.7.1 {
# catchsql {SELECT * FROM t1} db2
# } {1 {no such table: t1}}
do_test lock-1.7.2 {
catchsql {SELECT * FROM t1} db2
} {0 {1 2}}

View File

@ -12,7 +12,7 @@
#
# This file implements tests for temporary tables and indices.
#
# $Id: temptable.test,v 1.12 2004/06/10 10:51:53 danielk1977 Exp $
# $Id: temptable.test,v 1.13 2004/06/14 08:26:37 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -237,11 +237,13 @@ do_test temptable-4.10.1 {
SELECT * FROM t2;
} db2
} {0 {1 2}}
do_test temptable-4.10.2 {
catchsql {
SELECT name FROM sqlite_master WHERE type='table'
} db2
} {1 {database schema has changed}}
# Update: The schema is reloaded in test temptable-4.10.1. And tclsqlite.c
# handles it and retries the query anyway.
# do_test temptable-4.10.2 {
# catchsql {
# SELECT name FROM sqlite_master WHERE type='table'
# } db2
# } {1 {database schema has changed}}
do_test temptable-4.10.3 {
catchsql {
SELECT name FROM sqlite_master WHERE type='table'

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script is multithreading behavior
#
# $Id: thread1.test,v 1.5 2004/06/10 05:59:25 danielk1977 Exp $
# $Id: thread1.test,v 1.6 2004/06/14 08:26:37 danielk1977 Exp $
set testdir [file dirname $argv0]
@ -96,14 +96,20 @@ do_test thread1-1.12 {
} {t1 t2}
# Under this scenario:
#
# read-lock A
# read-lock B
# unlock A
# write-lock C
# The following tests - thread1-2.* - test the following scenario:
#
# Make sure the write-lock fails with SQLITE_BUSY
# 1: Read-lock thread A
# 2: Read-lock thread B
# 3: Attempt to write in thread C -> SQLITE_BUSY
# 4: Check db write failed from main thread.
# 5: Unlock from thread A.
# 6: Attempt to write in thread C -> SQLITE_BUSY
# 7: Check db write failed from main thread.
# 8: Unlock from thread B.
# 9: Attempt to write in thread C -> SQLITE_DONE
# 10: Finalize the write from thread C
# 11: Check db write succeeded from main thread.
#
do_test thread1-2.1 {
thread_halt *