tempdb.test 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # 2008 April 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.
  12. # The focus of this file is in making sure that rolling back
  13. # a statement journal works correctly.
  14. #
  15. # $Id: tempdb.test,v 1.4 2009/06/05 17:09:12 drh Exp $
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. # Use a temporary database.
  19. #
  20. db close
  21. sqlite3 db {}
  22. # Force a statement journal rollback on a database file that
  23. # has never been opened.
  24. #
  25. do_test tempdb-1.1 {
  26. execsql {
  27. BEGIN;
  28. CREATE TABLE t1(x UNIQUE);
  29. CREATE TABLE t2(y);
  30. INSERT INTO t2 VALUES('hello');
  31. INSERT INTO t2 VALUES(NULL);
  32. }
  33. # Because of the transaction, the temporary database file
  34. # has not even been opened yet. The following statement
  35. # will cause a statement journal rollback on this non-existant
  36. # file.
  37. catchsql {
  38. INSERT INTO t1
  39. SELECT CASE WHEN y IS NULL THEN test_error('oops', 11) ELSE y END
  40. FROM t2;
  41. }
  42. } {1 oops}
  43. # Verify that no writes occurred in t1.
  44. #
  45. do_test tempdb-1.2 {
  46. execsql {
  47. SELECT * FROM t1
  48. }
  49. } {}
  50. do_test tempdb-2.1 {
  51. # Set $::jrnl_in_memory if the journal file is expected to be in-memory.
  52. # Similarly, set $::subj_in_memory if the sub-journal file is expected
  53. # to be in memory. These variables are used to calculate the expected
  54. # number of open files in the test cases below.
  55. #
  56. set jrnl_in_memory [expr {[permutation] eq "inmemory_journal"}]
  57. set subj_in_memory [expr {$jrnl_in_memory || $TEMP_STORE>=2}]
  58. db close
  59. sqlite3 db test.db
  60. } {}
  61. do_test tempdb-2.2 {
  62. execsql {
  63. CREATE TABLE t1 (a PRIMARY KEY, b, c);
  64. CREATE TABLE t2 (a, b, c);
  65. BEGIN;
  66. INSERT INTO t1 VALUES(1, 2, 3);
  67. INSERT INTO t1 VALUES(4, 5, 6);
  68. INSERT INTO t2 VALUES(7, 8, 9);
  69. INSERT INTO t2 SELECT * FROM t1;
  70. }
  71. catchsql { INSERT INTO t1 SELECT * FROM t2 }
  72. set sqlite_open_file_count
  73. } [expr 1 + (0==$jrnl_in_memory) + (0==$subj_in_memory)]
  74. do_test tempdb-2.3 {
  75. execsql {
  76. PRAGMA temp_store = 'memory';
  77. ROLLBACK;
  78. BEGIN;
  79. INSERT INTO t1 VALUES(1, 2, 3);
  80. INSERT INTO t1 VALUES(4, 5, 6);
  81. INSERT INTO t2 SELECT * FROM t1;
  82. }
  83. catchsql { INSERT INTO t1 SELECT * FROM t2 }
  84. set sqlite_open_file_count
  85. } [expr 1 + (0==$jrnl_in_memory)]
  86. finish_test