1
0

tkt1644.test 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # 2006 January 30
  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. # This file implements tests to verify that ticket #1644 is
  14. # fixed. Ticket #1644 complains that precompiled statements
  15. # are not expired correctly as a result of changes to TEMP
  16. # views and triggers.
  17. #
  18. set testdir [file dirname $argv0]
  19. source $testdir/tester.tcl
  20. ifcapable !tempdb||!view {
  21. finish_test
  22. return
  23. }
  24. # Create two tables T1 and T2 and make V1 point to T1.
  25. do_test tkt1644-1.1 {
  26. execsql {
  27. CREATE TABLE t1(a);
  28. INSERT INTO t1 VALUES(1);
  29. CREATE TABLE t2(b);
  30. INSERT INTO t2 VALUES(99);
  31. CREATE TEMP VIEW v1 AS SELECT * FROM t1;
  32. SELECT * FROM v1;
  33. }
  34. } {1}
  35. # The "SELECT * FROM v1" should be in the TCL interface cache below.
  36. # It will continue to point to T1 unless the cache is invalidated when
  37. # the view changes.
  38. #
  39. do_test tkt1644-1.2 {
  40. execsql {
  41. DROP VIEW v1;
  42. CREATE TEMP VIEW v1 AS SELECT * FROM t2;
  43. SELECT * FROM v1;
  44. }
  45. } {99}
  46. # Cache an access to the T1 table.
  47. #
  48. do_test tkt1644-1.3 {
  49. execsql {
  50. SELECT * FROM t1;
  51. }
  52. } {1}
  53. # Create a temp table T1. Make sure the cache is invalidated so that
  54. # the statement is recompiled and refers to the empty temp table.
  55. #
  56. do_test tkt1644-1.4 {
  57. execsql {
  58. CREATE TEMP TABLE t1(x);
  59. }
  60. execsql {
  61. SELECT * FROM t1;
  62. }
  63. } {}
  64. ifcapable view {
  65. do_test tkt1644-2.1 {
  66. execsql {
  67. CREATE TEMP TABLE temp_t1(a, b);
  68. }
  69. set ::DB [sqlite3_connection_pointer db]
  70. set ::STMT [sqlite3_prepare $::DB "SELECT * FROM temp_t1" -1 DUMMY]
  71. execsql {
  72. DROP TABLE temp_t1;
  73. }
  74. list [sqlite3_step $::STMT] [sqlite3_finalize $::STMT]
  75. } {SQLITE_ERROR SQLITE_SCHEMA}
  76. do_test tkt1644-2.2 {
  77. execsql {
  78. CREATE TABLE real_t1(a, b);
  79. CREATE TEMP VIEW temp_v1 AS SELECT * FROM real_t1;
  80. }
  81. set ::DB [sqlite3_connection_pointer db]
  82. set ::STMT [sqlite3_prepare $::DB "SELECT * FROM temp_v1" -1 DUMMY]
  83. execsql {
  84. DROP VIEW temp_v1;
  85. }
  86. list [sqlite3_step $::STMT] [sqlite3_finalize $::STMT]
  87. } {SQLITE_ERROR SQLITE_SCHEMA}
  88. do_test tkt1644-2.3 {
  89. execsql {
  90. CREATE TEMP VIEW temp_v1 AS SELECT * FROM real_t1 LIMIT 10 OFFSET 10;
  91. }
  92. set ::DB [sqlite3_connection_pointer db]
  93. set ::STMT [sqlite3_prepare $::DB "SELECT * FROM temp_v1" -1 DUMMY]
  94. execsql {
  95. DROP VIEW temp_v1;
  96. }
  97. list [sqlite3_step $::STMT] [sqlite3_finalize $::STMT]
  98. } {SQLITE_ERROR SQLITE_SCHEMA}
  99. }
  100. finish_test