rbu14.test 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # 2015 July 25
  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. # Test that an RBU data_xxx table may be a view instead of a regular
  13. # table.
  14. #
  15. source [file join [file dirname [info script]] rbu_common.tcl]
  16. if_no_rbu_support { finish_test ; return }
  17. source $testdir/lock_common.tcl
  18. set ::testprefix rbu14
  19. foreach {tn schema} {
  20. 1 {
  21. CREATE TABLE t1(a PRIMARY KEY, b, c);
  22. CREATE TABLE t2(a PRIMARY KEY, b, c);
  23. }
  24. 2 {
  25. CREATE TABLE t1(a PRIMARY KEY, b, c);
  26. CREATE TABLE t2(a PRIMARY KEY, b, c);
  27. CREATE INDEX i1 ON t1(b, c);
  28. CREATE INDEX i2 ON t2(b, c);
  29. }
  30. 3 {
  31. CREATE TABLE t1(a PRIMARY KEY, b, c) WITHOUT ROWID;
  32. CREATE TABLE t2(a PRIMARY KEY, b, c) WITHOUT ROWID;
  33. }
  34. 4 {
  35. CREATE TABLE t1(a PRIMARY KEY, b, c) WITHOUT ROWID;
  36. CREATE TABLE t2(a PRIMARY KEY, b, c) WITHOUT ROWID;
  37. CREATE INDEX i1 ON t1(b, c);
  38. CREATE INDEX i2 ON t2(b, c);
  39. }
  40. } {
  41. reset_db
  42. execsql $schema
  43. execsql {
  44. INSERT INTO t1 VALUES(50, 50, 50);
  45. INSERT INTO t1 VALUES(51, 51, 51);
  46. INSERT INTO t2 VALUES(50, 50, 50);
  47. INSERT INTO t2 VALUES(51, 51, 51);
  48. }
  49. forcedelete rbu.db
  50. do_execsql_test $tn.1 {
  51. ATTACH 'rbu.db' AS rbu;
  52. CREATE TABLE rbu.stuff(tbl, a, b, c, rbu_control);
  53. INSERT INTO stuff VALUES
  54. ('t1', 1, 2, 3, 0), -- insert into t1
  55. ('t2', 4, 5, 6, 0), -- insert into t2
  56. ('t1', 50, NULL, NULL, 1), -- delete from t1
  57. ('t2', 51, NULL, NULL, 1); -- delete from t2
  58. CREATE VIEW rbu.data_t1 AS
  59. SELECT a, b, c, rbu_control FROM stuff WHERE tbl='t1';
  60. CREATE VIEW rbu.data_t2 AS
  61. SELECT a, b, c, rbu_control FROM stuff WHERE tbl='t2';
  62. }
  63. do_test $tn.2 {
  64. while 1 {
  65. sqlite3rbu rbu test.db rbu.db
  66. set rc [rbu step]
  67. rbu close
  68. if {$rc != "SQLITE_OK"} break
  69. }
  70. set rc
  71. } {SQLITE_DONE}
  72. do_execsql_test $tn.3.1 {
  73. SELECT * FROM t1 ORDER BY a;
  74. } {1 2 3 51 51 51}
  75. do_execsql_test $tn.3.2 {
  76. SELECT * FROM t2 ORDER BY a;
  77. } {4 5 6 50 50 50}
  78. integrity_check $tn.4
  79. }
  80. finish_test