blob: a9f9b7ae6faf3d0ded00413fe5df5c5e185f5c46 [file] [log] [blame]
drhaee128d2005-02-14 20:48:18 +00001# 2005 February 14
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library. The
12# focus of this file is testing the CREATE INDEX statement.
13#
drh34533152008-03-19 13:03:33 +000014# $Id: index3.test,v 1.3 2008/03/19 13:03:34 drh Exp $
drhaee128d2005-02-14 20:48:18 +000015
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20# Ticket #1115. Make sure that when a UNIQUE index is created on a
21# non-unique column (or columns) that it fails and that it leaves no
22# residue behind.
23#
24do_test index3-1.1 {
25 execsql {
26 CREATE TABLE t1(a);
27 INSERT INTO t1 VALUES(1);
28 INSERT INTO t1 VALUES(1);
29 SELECT * FROM t1;
30 }
31} {1 1}
32do_test index3-1.2 {
33 catchsql {
34 BEGIN;
35 CREATE UNIQUE INDEX i1 ON t1(a);
36 }
drhf9c8ce32013-11-05 13:33:55 +000037} {1 {UNIQUE constraint failed: t1.a}}
drhaee128d2005-02-14 20:48:18 +000038do_test index3-1.3 {
39 catchsql COMMIT;
40} {0 {}}
41integrity_check index3-1.4
42
drh85c23c62005-08-20 03:03:04 +000043# This test corrupts the database file so it must be the last test
44# in the series.
45#
46do_test index3-99.1 {
47 execsql {
48 PRAGMA writable_schema=on;
49 UPDATE sqlite_master SET sql='nonsense';
50 }
51 db close
dancb354602010-07-08 09:44:42 +000052 catch { sqlite3 db test.db }
53 catchsql { DROP INDEX i1 }
drh34533152008-03-19 13:03:33 +000054} {1 {malformed database schema (t1) - near "nonsense": syntax error}}
drh85c23c62005-08-20 03:03:04 +000055
drhaee128d2005-02-14 20:48:18 +000056finish_test