tkt2820.test 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # 2007 Dec 4
  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. #
  12. # This file is to test that ticket #2820 has been fixed.
  13. # Ticket #2820 observes that a DROP TABLE statement that
  14. # occurs while a query is in process will fail with a
  15. # "database is locked" error, but the entry in the sqlite_master
  16. # table will still be removed. This is incorrect. The
  17. # entry in the sqlite_master table should persist when
  18. # the DROP fails due to an error.
  19. #
  20. # $Id: tkt2820.test,v 1.1 2007/12/04 16:54:53 drh Exp $
  21. #
  22. set testdir [file dirname $argv0]
  23. source $testdir/tester.tcl
  24. proc test_schema_change {testid init ddl res} {
  25. db close
  26. forcedelete test.db test.db-journal
  27. sqlite3 db test.db
  28. execsql $init
  29. do_test tkt2820-$testid.1 {
  30. set STMT [sqlite3_prepare db {SELECT * FROM sqlite_master} -1 DUMMY]
  31. sqlite3_step $STMT
  32. } {SQLITE_ROW}
  33. #if {$testid==3} {execsql {PRAGMA vdbe_trace=ON}}
  34. do_test tkt2820-$testid.2 "catchsql [list $ddl]" \
  35. {1 {database table is locked}}
  36. do_test tkt2820-$testid.3 {
  37. sqlite3_finalize $STMT
  38. execsql {SELECT name FROM sqlite_master ORDER BY 1}
  39. } $res
  40. integrity_check tkt2820-$testid.4
  41. db close
  42. sqlite3 db test.db
  43. integrity_check tkt2820-$testid.5
  44. }
  45. test_schema_change 1 {
  46. CREATE TABLE t1(a);
  47. } {
  48. DROP TABLE t1
  49. } {t1}
  50. test_schema_change 2 {
  51. CREATE TABLE t1(a);
  52. CREATE TABLE t2(b);
  53. } {
  54. DROP TABLE t2
  55. } {t1 t2}
  56. test_schema_change 3 {
  57. CREATE TABLE t1(a);
  58. CREATE INDEX i1 ON t1(a);
  59. } {
  60. DROP INDEX i1
  61. } {i1 t1}
  62. # We further observe that prior to the fix associated with ticket #2820,
  63. # no statement journal would be created on an SQL statement that was run
  64. # while a second statement was active, as long as we are in autocommit
  65. # mode. This is incorrect.
  66. #
  67. do_test tkt2820-4.1 {
  68. db close
  69. forcedelete test.db test.db-journal
  70. sqlite3 db test.db
  71. db eval {
  72. CREATE TABLE t1(a INTEGER PRIMARY KEY);
  73. INSERT INTO t1 VALUES(1);
  74. INSERT INTO t1 VALUES(2);
  75. }
  76. # The INSERT statement within the loop should fail on a
  77. # constraint violation on the second inserted row. This
  78. # should cause the entire INSERT to rollback using a statement
  79. # journal.
  80. #
  81. db eval {SELECT name FROM sqlite_master} {
  82. catch {db eval {
  83. INSERT INTO t1 SELECT a+1 FROM t1 ORDER BY a DESC
  84. }}
  85. }
  86. db eval {SELECT a FROM t1 ORDER BY a}
  87. } {1 2}
  88. finish_test