schema3.test 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # 2010 Jun 28
  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.
  12. #
  13. set testdir [file dirname $argv0]
  14. source $testdir/tester.tcl
  15. source $testdir/malloc_common.tcl
  16. source $testdir/lock_common.tcl
  17. # This block tests that if one client modifies the database schema, a
  18. # second client updates its internal cache of the database schema before
  19. # executing any queries. Specifically, it does not return a "no such column"
  20. # or "no such table" error if the table or column in question does exist
  21. # but was added after the second client loaded its cache of the database
  22. # schema.
  23. #
  24. # Types of schema modifications:
  25. #
  26. # 1. Adding a database table.
  27. # 2. Adding a database view.
  28. # 3. Adding a database index.
  29. # 4. Adding a database trigger.
  30. # 5. Adding a column to an existing table (ALTER TABLE).
  31. #
  32. do_multiclient_test tn {
  33. # Have connections [db1] and [db2] load the current database schema.
  34. #
  35. sql1 { SELECT * FROM sqlite_master }
  36. sql2 { SELECT * FROM sqlite_master }
  37. foreach {tn2 c1 c2} {
  38. 1 { CREATE TABLE t1(a, b) } { SELECT * FROM t1 }
  39. 2 { CREATE TABLE t2(a, b) } { UPDATE t2 SET a = b }
  40. 3 { CREATE TABLE t3(a, b) } { DELETE FROM t3 }
  41. 4 { CREATE TABLE t4(a, b) } { INSERT INTO t4 VALUES(1, 2) }
  42. 5 { CREATE TABLE t5(a, b) } { DROP TABLE t5 }
  43. 6 { CREATE TABLE t6(a, b) } { CREATE INDEX i1 ON t6(a) }
  44. 7 { ALTER TABLE t1 ADD COLUMN c } { SELECT a, b, c FROM t1 }
  45. 8 { ALTER TABLE t2 ADD COLUMN c } { UPDATE t2 SET a = c }
  46. 9 { ALTER TABLE t2 ADD COLUMN d } { UPDATE t2 SET d = c }
  47. 10 { ALTER TABLE t3 ADD COLUMN c } { DELETE FROM t3 WHERE c>10 }
  48. 11 { ALTER TABLE t4 ADD COLUMN c } { INSERT INTO t4(a,b,c) VALUES(1,2,3) }
  49. 12 { ALTER TABLE t6 ADD COLUMN c } { CREATE INDEX i2 ON t6(c) }
  50. 13 { ALTER TABLE t6 ADD COLUMN d } {
  51. CREATE TRIGGER tr1 AFTER UPDATE OF d ON t6 BEGIN
  52. SELECT 1, 2, 3;
  53. END;
  54. }
  55. 14 { CREATE INDEX i3 ON t1(a) } { DROP INDEX i3 }
  56. 15 { CREATE INDEX i4 ON t2(a) } {
  57. SELECT * FROM t2 INDEXED BY i4 ORDER BY a
  58. }
  59. 16 { CREATE TRIGGER tr2 AFTER INSERT ON t3 BEGIN SELECT 1 ; END } {
  60. DROP TRIGGER tr2
  61. }
  62. 17 { CREATE VIEW v1 AS SELECT * FROM t1 } { SELECT a,b,c FROM v1 }
  63. 18 { ALTER TABLE t1 ADD COLUMN d } { SELECT a,b,c,d FROM v1 }
  64. 19 { CREATE TABLE t7(a, b) } {
  65. DROP TABLE IF EXISTS t7; CREATE TABLE t7(c, d);
  66. }
  67. 20 { CREATE INDEX i5 ON t7(c, d) } {
  68. DROP INDEX IF EXISTS i5; CREATE INDEX i5 ON t7(c)
  69. }
  70. 21 { CREATE TRIGGER tr3 BEFORE DELETE ON t7 BEGIN SELECT 1, 2, 3 ; END } {
  71. DROP TRIGGER IF EXISTS tr3;
  72. CREATE TRIGGER tr3 AFTER INSERT ON t7 BEGIN SELECT 1, 2, 3 ; END
  73. }
  74. 22 { CREATE TABLE t8(a, b) } {
  75. CREATE TRIGGER tr4 AFTER UPDATE OF a ON t8 BEGIN
  76. SELECT 1, 2, 3;
  77. END;
  78. }
  79. } {
  80. do_test schema3-1.$tn.$tn2 {
  81. sql1 $c1
  82. sql2 $c2
  83. } {}
  84. }
  85. }
  86. finish_test