xref: /sqlite-3.40.0/test/corrupt5.test (revision 6ab91a7a)
1c046f400Sdrh# 2008 Jan 22
2c046f400Sdrh#
3c046f400Sdrh# The author disclaims copyright to this source code.  In place of
4c046f400Sdrh# a legal notice, here is a blessing:
5c046f400Sdrh#
6c046f400Sdrh#    May you do good and not evil.
7c046f400Sdrh#    May you find forgiveness for yourself and forgive others.
8c046f400Sdrh#    May you share freely, never taking more than you give.
9c046f400Sdrh#
10c046f400Sdrh#***********************************************************************
11c046f400Sdrh# This file implements regression tests for SQLite library.
12c046f400Sdrh#
13c046f400Sdrh# This file implements tests to make sure SQLite does not crash or
14e71169baSshane# segfault if it sees a corrupt database file.  Checks for
15e71169baSshane# malformed schema.
16c046f400Sdrh#
17e71169baSshane# $Id: corrupt5.test,v 1.3 2009/06/04 02:47:04 shane Exp $
18c046f400Sdrh
19c046f400Sdrhset testdir [file dirname $argv0]
20c046f400Sdrhsource $testdir/tester.tcl
21c046f400Sdrh
2209fe6143Sdrh# These tests deal with corrupt database files
2309fe6143Sdrh#
2409fe6143Sdrhdatabase_may_be_corrupt
2509fe6143Sdrh
26c046f400Sdrh# We must have the page_size pragma for these tests to work.
27c046f400Sdrh#
28c046f400Sdrhifcapable !pager_pragmas {
29c046f400Sdrh  finish_test
30c046f400Sdrh  return
31c046f400Sdrh}
32c046f400Sdrh
33c046f400Sdrh# Create a database with a freelist containing at least two pages.
34c046f400Sdrh#
35c046f400Sdrhdo_test corrupt5-1.1 {
36*6ab91a7aSdrh  sqlite3_db_config db DEFENSIVE 0
37c046f400Sdrh  execsql {
38c046f400Sdrh    CREATE TABLE t1(a,b,c);
39c046f400Sdrh    CREATE INDEX i1 ON t1(a,b);
40c046f400Sdrh    PRAGMA writable_schema=ON;
41c046f400Sdrh    UPDATE sqlite_master SET name=NULL, sql=NULL WHERE name='i1';
42c046f400Sdrh  }
43c046f400Sdrh  db close
44c046f400Sdrh  sqlite3 db test.db
45c046f400Sdrh  catchsql {
46c046f400Sdrh    SELECT * FROM t1
47c046f400Sdrh  }
4834533150Sdrh} {1 {malformed database schema (?)}}
49c046f400Sdrh
50c046f400Sdrhfinish_test
51