index3.test 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # 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. #
  14. # $Id: index3.test,v 1.3 2008/03/19 13:03:34 drh Exp $
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. # Ticket #1115. Make sure that when a UNIQUE index is created on a
  18. # non-unique column (or columns) that it fails and that it leaves no
  19. # residue behind.
  20. #
  21. do_test index3-1.1 {
  22. execsql {
  23. CREATE TABLE t1(a);
  24. INSERT INTO t1 VALUES(1);
  25. INSERT INTO t1 VALUES(1);
  26. SELECT * FROM t1;
  27. }
  28. } {1 1}
  29. do_test index3-1.2 {
  30. catchsql {
  31. BEGIN;
  32. CREATE UNIQUE INDEX i1 ON t1(a);
  33. }
  34. } {1 {indexed columns are not unique}}
  35. do_test index3-1.3 {
  36. catchsql COMMIT;
  37. } {0 {}}
  38. integrity_check index3-1.4
  39. # This test corrupts the database file so it must be the last test
  40. # in the series.
  41. #
  42. do_test index3-99.1 {
  43. execsql {
  44. PRAGMA writable_schema=on;
  45. UPDATE sqlite_master SET sql='nonsense';
  46. }
  47. db close
  48. catch { sqlite3 db test.db }
  49. catchsql { DROP INDEX i1 }
  50. } {1 {malformed database schema (t1) - near "nonsense": syntax error}}
  51. finish_test