rbupartial.test 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # 2019 April 11
  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. source [file join [file dirname [info script]] rbu_common.tcl]
  13. if_no_rbu_support { finish_test ; return }
  14. set ::testprefix rbupartial
  15. db close
  16. foreach {tn without_rowid a b c d} {
  17. 1 "" a b c d
  18. 2 "WITHOUT ROWID" aaa bbb ccc ddd
  19. 3 "WITHOUT ROWID" "\"hello\"" {"one'two"} {[c]} ddd
  20. 4 "WITHOUT ROWID" {`a b`} {"one'two"} {[c c c]} ddd
  21. 5 "" a b c {"d""d"}
  22. 6 "" {'one''two'} b {"c""c"} {"d""d"}
  23. } {
  24. eval [string map [list \
  25. %WITHOUT_ROWID% $without_rowid %A% $a %B% $b %C% $c %D% $d
  26. ] {
  27. reset_db
  28. do_execsql_test $tn.1.0 {
  29. CREATE TABLE t1(%A% PRIMARY KEY, %B%, %C%, %D%) %WITHOUT_ROWID% ;
  30. CREATE INDEX i1b ON t1(%B%);
  31. CREATE INDEX i1b2 ON t1(%B%) WHERE %C%<5;
  32. CREATE INDEX i1b3 ON t1(%B%) WHERE %C%>=5;
  33. CREATE INDEX i1c ON t1(%C%);
  34. CREATE INDEX i1c2 ON t1(%C%) WHERE %C% IS NULL;
  35. CREATE INDEX i1c3 ON t1(%C%) WHERE %C% IS NOT NULL;
  36. CREATE INDEX i1c4 ON t1(%C%) WHERE %D% < 'd';
  37. CREATE INDEX i1c5 ON t1(
  38. %C% -- for (c = ... expressions
  39. ) WHERE %D% < 'd';
  40. CREATE INDEX i1c6 ON t1(
  41. %C% /* Again, for (c=... expr */, %D%
  42. ) WHERE %D% < 'd';
  43. CREATE INDEX i1c7 ON t1(
  44. %C% /* As before, for (c=... "expr */) WHERE %D% < 'd';
  45. }
  46. do_execsql_test $tn.1.1 {
  47. INSERT INTO t1 VALUES(0, NULL, NULL, 'a');
  48. INSERT INTO t1 VALUES(1, 2, 3, 'b');
  49. INSERT INTO t1 VALUES(4, 5, 6, 'c');
  50. INSERT INTO t1 VALUES(7, 8, 9, 'd');
  51. }
  52. forcedelete rbu.db
  53. do_test $tn.1.2 {
  54. sqlite3 rbu rbu.db
  55. rbu eval {
  56. CREATE TABLE data_t1(%A%, %B%, %C%, %D%, rbu_control);
  57. INSERT INTO data_t1 VALUES(10, 11, 12, 'e', 0);
  58. INSERT INTO data_t1 VALUES(13, 14, NULL, 'f', 0);
  59. INSERT INTO data_t1 VALUES(0, NULL, NULL, NULL, 1);
  60. INSERT INTO data_t1 VALUES(4, NULL, NULL, NULL, 1);
  61. INSERT INTO data_t1 VALUES(7, NULL, 4, NULL, '..x.');
  62. INSERT INTO data_t1 VALUES(1, 10, NULL, NULL, '.xx.');
  63. }
  64. rbu close
  65. } {}
  66. do_test $tn.1.3 {
  67. run_rbu test.db rbu.db
  68. execsql { PRAGMA integrity_check }
  69. } {ok}
  70. do_execsql_test $tn.1.4 {
  71. SELECT * FROM t1 ORDER BY %A%;
  72. } {
  73. 1 10 {} b 7 8 4 d 10 11 12 e 13 14 {} f
  74. }
  75. set step 0
  76. do_rbu_vacuum_test $tn.1.5 0
  77. do_test $tn.1.6 {
  78. execsql { PRAGMA integrity_check }
  79. } {ok}
  80. }]
  81. }
  82. finish_test