1
0

stmt.test 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # 2010 February 18
  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. # The tests in this file check that SQLite uses (or does not use) a
  13. # statement journal for various SQL statements.
  14. #
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. do_test stmt-1.1 {
  18. execsql { CREATE TABLE t1(a integer primary key, b INTEGER NOT NULL) }
  19. } {}
  20. # The following tests verify the method used for the tests in this file -
  21. # that if a statement journal is required by a statement it is opened and
  22. # remains open until the current transaction is committed or rolled back.
  23. #
  24. # This only work if SQLITE_TEMP_STORE!=3
  25. #
  26. if {$::TEMP_STORE==3} {
  27. finish_test
  28. return
  29. }
  30. do_test stmt-1.2 {
  31. set sqlite_open_file_count
  32. } {1}
  33. do_test stmt-1.3 {
  34. execsql {
  35. PRAGMA temp_store = file;
  36. BEGIN;
  37. INSERT INTO t1 VALUES(1, 1);
  38. }
  39. set sqlite_open_file_count
  40. } {2}
  41. do_test stmt-1.4 {
  42. execsql {
  43. INSERT INTO t1 SELECT a+1, b+1 FROM t1;
  44. }
  45. set sqlite_open_file_count
  46. } {3}
  47. do_test stmt-1.5 {
  48. execsql COMMIT
  49. set sqlite_open_file_count
  50. } {1}
  51. do_test stmt-1.6.1 {
  52. execsql {
  53. BEGIN;
  54. INSERT INTO t1 SELECT a+2, b+2 FROM t1;
  55. }
  56. set sqlite_open_file_count
  57. } {2}
  58. do_test stmt-1.6.2 {
  59. execsql { INSERT INTO t1 SELECT a+4, b+4 FROM t1 }
  60. set sqlite_open_file_count
  61. } {3}
  62. do_test stmt-1.7 {
  63. execsql COMMIT
  64. set sqlite_open_file_count
  65. } {1}
  66. proc filecount {testname sql expected} {
  67. uplevel [list do_test $testname [subst -nocommand {
  68. execsql BEGIN
  69. execsql { $sql }
  70. set ret [set sqlite_open_file_count]
  71. execsql ROLLBACK
  72. set ret
  73. }] $expected]
  74. }
  75. filecount stmt-2.1 { INSERT INTO t1 VALUES(9, 9) } 2
  76. filecount stmt-2.2 { REPLACE INTO t1 VALUES(9, 9) } 2
  77. filecount stmt-2.3 { INSERT INTO t1 SELECT 9, 9 } 2
  78. filecount stmt-2.4 {
  79. INSERT INTO t1 SELECT 9, 9;
  80. INSERT INTO t1 SELECT 10, 10;
  81. } 3
  82. do_test stmt-2.5 {
  83. execsql { CREATE INDEX i1 ON t1(b) }
  84. } {}
  85. filecount stmt-2.6 {
  86. REPLACE INTO t1 VALUES(5, 5);
  87. REPLACE INTO t1 VALUES(5, 5);
  88. } 3
  89. finish_test