sessionwor.test 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # 2017 Jan 31
  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 focus of this file is testing the session module. Specifically,
  13. # testing support for WITHOUT ROWID tables.
  14. #
  15. if {![info exists testdir]} {
  16. set testdir [file join [file dirname [info script]] .. .. test]
  17. }
  18. source [file join [file dirname [info script]] session_common.tcl]
  19. source $testdir/tester.tcl
  20. ifcapable !session {finish_test; return}
  21. set testprefix sessionwor
  22. proc test_reset {} {
  23. catch { db close }
  24. catch { db2 close }
  25. forcedelete test.db test.db2
  26. sqlite3 db test.db
  27. sqlite3 db2 test.db2
  28. }
  29. foreach {tn wo} {
  30. 1 ""
  31. 2 "WITHOUT ROWID"
  32. } {
  33. reset_db
  34. do_execsql_test 1.$tn.0 "CREATE TABLE t1(a PRIMARY KEY, b) $wo ;"
  35. do_iterator_test 1.$tn.1 t1 {
  36. INSERT INTO t1 VALUES('one', 'two');
  37. } {
  38. {INSERT t1 0 X. {} {t one t two}}
  39. }
  40. do_iterator_test 1.$tn.2 t1 {
  41. UPDATE t1 SET b='three'
  42. } {
  43. {UPDATE t1 0 X. {t one t two} {{} {} t three}}
  44. }
  45. do_iterator_test 1.$tn.3 t1 {
  46. REPLACE INTO t1 VALUES('one', 'four');
  47. } {
  48. {UPDATE t1 0 X. {t one t three} {{} {} t four}}
  49. }
  50. do_iterator_test 1.$tn.4 t1 {
  51. DELETE FROM t1;
  52. } {
  53. {DELETE t1 0 X. {t one t four} {}}
  54. }
  55. }
  56. foreach {tn wo} {
  57. 1 ""
  58. 2 "WITHOUT ROWID"
  59. } {
  60. reset_db
  61. do_execsql_test 2.$tn.0.1 "CREATE TABLE t1(a INTEGER PRIMARY KEY, b) $wo ;"
  62. do_execsql_test 2.$tn.0.2 "CREATE TABLE t2(a INTEGER PRIMARY KEY, b) $wo ;"
  63. do_execsql_test 2.$tn.0.3 "CREATE TABLE t3(a INTEGER PRIMARY KEY, b) $wo ;"
  64. do_iterator_test 1.1 t1 {
  65. INSERT INTO t1 VALUES(1, 'two');
  66. } {
  67. {INSERT t1 0 X. {} {i 1 t two}}
  68. }
  69. do_iterator_test 2.$tn.2 t1 {
  70. UPDATE t1 SET b='three'
  71. } {
  72. {UPDATE t1 0 X. {i 1 t two} {{} {} t three}}
  73. }
  74. do_iterator_test 2.$tn.3 t1 {
  75. REPLACE INTO t1 VALUES(1, 'four');
  76. } {
  77. {UPDATE t1 0 X. {i 1 t three} {{} {} t four}}
  78. }
  79. do_iterator_test 2.$tn.4 t1 {
  80. DELETE FROM t1;
  81. } {
  82. {DELETE t1 0 X. {i 1 t four} {}}
  83. }
  84. do_execsql_test 2.$tn.5 {
  85. INSERT INTO t1 VALUES(1, 'one');
  86. INSERT INTO t1 VALUES(2, 'two');
  87. INSERT INTO t1 VALUES(3, 'three');
  88. }
  89. do_iterator_test 2.$tn.6 t2 {
  90. INSERT INTO t2 SELECT a, b FROM t1
  91. } {
  92. {INSERT t2 0 X. {} {i 1 t one}}
  93. {INSERT t2 0 X. {} {i 2 t two}}
  94. {INSERT t2 0 X. {} {i 3 t three}}
  95. }
  96. do_iterator_test 2.$tn.7 t3 {
  97. INSERT INTO t3 SELECT * FROM t1
  98. } {
  99. {INSERT t3 0 X. {} {i 1 t one}}
  100. {INSERT t3 0 X. {} {i 2 t two}}
  101. {INSERT t3 0 X. {} {i 3 t three}}
  102. }
  103. }
  104. finish_test