1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Fix bugs associated with the codec. (CVS 1846)

FossilOrigin-Name: b0a3becd82b9a4203c23f35dc5a5fd725e046f21
This commit is contained in:
drh
2004-07-22 15:02:25 +00:00
parent 89aa31e509
commit 25d6543de5
13 changed files with 243 additions and 146 deletions

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script testing the callback-free C/C++ API.
#
# $Id: capi3.test,v 1.19 2004/06/30 06:30:26 danielk1977 Exp $
# $Id: capi3.test,v 1.20 2004/07/22 15:02:26 drh Exp $
#
set testdir [file dirname $argv0]
@ -443,6 +443,7 @@ db close
do_test capi3-6.0 {
set DB [sqlite3_open test.db]
sqlite3_key $DB xyzzy
set sql {SELECT a FROM t1 order by rowid}
set STMT [sqlite3_prepare $DB $sql -1 TAIL]
expr 0
@ -461,87 +462,93 @@ do_test capi3-6.4 {
sqlite3_close $DB
} {SQLITE_OK}
# Test what happens when the library encounters a newer file format.
# Do this by updating the file format via the btree layer.
do_test capi3-7.1 {
set ::bt [btree_open test.db 10 0]
btree_begin_transaction $::bt
set meta [btree_get_meta $::bt]
lset meta 2 2
eval [concat btree_update_meta $::bt [lrange $meta 0 end]]
btree_commit $::bt
btree_close $::bt
} {}
do_test capi3-7.2 {
sqlite3 db test.db
breakpoint
catchsql {
SELECT * FROM sqlite_master;
}
} {1 {unsupported file format}}
# Now test that the library correctly handles bogus entries in the
# sqlite_master table (schema corruption).
do_test capi3-8.1 {
if {![sqlite3 -has-codec]} {
# Test what happens when the library encounters a newer file format.
# Do this by updating the file format via the btree layer.
do_test capi3-7.1 {
set ::bt [btree_open test.db 10 0]
btree_begin_transaction $::bt
set meta [btree_get_meta $::bt]
lset meta 2 2
eval [concat btree_update_meta $::bt [lrange $meta 0 end]]
btree_commit $::bt
btree_close $::bt
} {}
do_test capi3-7.2 {
sqlite3 db test.db
catchsql {
SELECT * FROM sqlite_master;
}
} {1 {unsupported file format}}
db close
file delete -force test.db
sqlite3 db test.db
execsql {
CREATE TABLE t1(a);
}
}
if {![sqlite3 -has-codec]} {
# Now test that the library correctly handles bogus entries in the
# sqlite_master table (schema corruption).
do_test capi3-8.1 {
file delete -force test.db
file delete -force test.db-journal
sqlite3 db test.db
execsql {
CREATE TABLE t1(a);
}
db close
} {}
do_test capi3-8.2 {
set ::bt [btree_open test.db 10 0]
btree_begin_transaction $::bt
set ::bc [btree_cursor $::bt 1 1]
# Build a 5-field row record consisting of 5 null records. This is
# officially black magic.
catch {unset data}
set data [binary format c6 {6 0 0 0 0 0}]
btree_insert $::bc 5 $data
btree_close_cursor $::bc
btree_commit $::bt
btree_close $::bt
} {}
do_test capi3-8.3 {
sqlite3 db test.db
catchsql {
SELECT * FROM sqlite_master;
}
} {1 {malformed database schema}}
do_test capi3-8.4 {
set ::bt [btree_open test.db 10 0]
btree_begin_transaction $::bt
set ::bc [btree_cursor $::bt 1 1]
# Build a 5-field row record. The first field is a string 'table', and
# subsequent fields are all NULL. Replace the other broken record with
# this one and try to read the schema again. The broken record uses
# either UTF-8 or native UTF-16 (if this file is being run by
# utf16.test).
if { [string match UTF-16* $::ENC] } {
set data [binary format c6a10 {6 33 0 0 0 0} [utf16 table]]
} else {
set data [binary format c6a5 {6 23 0 0 0 0} table]
}
btree_insert $::bc 5 $data
btree_close_cursor $::bc
btree_commit $::bt
btree_close $::bt
} {}
do_test capi3-8.5 {
db close
sqlite3 db test.db
catchsql {
SELECT * FROM sqlite_master;
}
} {1 {malformed database schema}}
db close
} {}
do_test capi3-8.2 {
set ::bt [btree_open test.db 10 0]
btree_begin_transaction $::bt
set ::bc [btree_cursor $::bt 1 1]
# Build a 5-field row record consisting of 5 null records. This is
# officially black magic.
catch {unset data}
set data [binary format c6 {6 0 0 0 0 0}]
btree_insert $::bc 5 $data
btree_close_cursor $::bc
btree_commit $::bt
btree_close $::bt
} {}
do_test capi3-8.3 {
sqlite3 db test.db
catchsql {
SELECT * FROM sqlite_master;
}
} {1 {malformed database schema}}
do_test capi3-8.4 {
set ::bt [btree_open test.db 10 0]
btree_begin_transaction $::bt
set ::bc [btree_cursor $::bt 1 1]
# Build a 5-field row record. The first field is a string 'table', and
# subsequent fields are all NULL. Replace the other broken record with
# this one and try to read the schema again. The broken record uses
# either UTF-8 or native UTF-16 (if this file is being run by
# utf16.test).
if { [string match UTF-16* $::ENC] } {
set data [binary format c6a10 {6 33 0 0 0 0} [utf16 table]]
} else {
set data [binary format c6a5 {6 23 0 0 0 0} table]
}
btree_insert $::bc 5 $data
btree_close_cursor $::bc
btree_commit $::bt
btree_close $::bt
} {}
do_test capi3-8.5 {
db close
sqlite3 db test.db
catchsql {
SELECT * FROM sqlite_master;
}
} {1 {malformed database schema}}
db close
}
file delete -force test.db
file delete -force test.db-journal
# Test the english language string equivalents for sqlite error codes
set code2english [list \
@ -761,4 +768,3 @@ do_test capi3-12.8 {
finish_test