sessionsize.test 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # 2021 April 22
  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. #
  13. if {![info exists testdir]} {
  14. set testdir [file join [file dirname [info script]] .. .. test]
  15. }
  16. source [file join [file dirname [info script]] session_common.tcl]
  17. source $testdir/tester.tcl
  18. ifcapable !session {finish_test; return}
  19. set testprefix sessionsize
  20. proc do_changeset_size_test {tn sql} {
  21. sqlite3session S db main
  22. S attach *
  23. db eval $sql
  24. set sz [S changeset_size]
  25. set C [S changeset]
  26. set szC [string length $C]
  27. S delete
  28. do_test $tn "expr $sz" $szC
  29. }
  30. do_execsql_test 1.0 {
  31. CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
  32. INSERT INTO t1 VALUES(1, 'abc', 'def');
  33. INSERT INTO t1 VALUES(2, 'ghi', 'jkl');
  34. }
  35. do_changeset_size_test 1.1 {
  36. INSERT INTO t1 VALUES(3, 'hello', 'world');
  37. }
  38. do_changeset_size_test 1.2 {
  39. DELETE FROM t1 WHERE a=2;
  40. }
  41. do_changeset_size_test 1.3 {
  42. DELETE FROM t1 WHERE a=3;
  43. INSERT INTO t1 VALUES(3, 1, 2);
  44. }
  45. do_changeset_size_test 1.4 {
  46. UPDATE t1 SET c='hello world' WHERE a=3;
  47. }
  48. #-------------------------------------------------------------------------
  49. do_execsql_test 2.0 {
  50. CREATE TABlE t2(a, b, c, d, PRIMARY KEY(a, b)) WITHOUT ROWID;
  51. CREATE TABlE t3(a, b, c, d PRIMARY KEY);
  52. }
  53. do_changeset_size_test 2.1 {
  54. WITH s(i) AS (
  55. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50
  56. )
  57. INSERT INTO t2 SELECT i, i+1, i+2, i+3 FROM s;
  58. UPDATE t2 SET c=randomblob(a) WHERE a>10
  59. }
  60. do_changeset_size_test 2.2 {
  61. DELETE FROM t2 WHERE a=1;
  62. INSERT INTO t2 VALUES(1, 4, 3, 4);
  63. }
  64. do_changeset_size_test 2.2 {
  65. UPDATE t2 SET b=4 WHERE a=2
  66. }
  67. do_changeset_size_test 2.3 {
  68. INSERT INTO t2 VALUES('a', 'b', 'c', 'd');
  69. UPDATE t2 SET c='qwertyuiop' WHERE a='a';
  70. }
  71. do_changeset_size_test 2.4 {
  72. DELETE FROM t2 WHERE a='a';
  73. INSERT INTO t2 VALUES('a', 'b', 'c', 'd');
  74. }
  75. do_changeset_size_test 2.5 {
  76. UPDATE t2 SET a='aa', b='bb' WHERE (a, b) = ('a', 'b');
  77. }
  78. do_changeset_size_test 2.6 {
  79. UPDATE t2 SET a='a', b='b' WHERE (a, b) = ('aa', 'bb');
  80. }
  81. do_changeset_size_test 2.7 {
  82. INSERT INTO t3 DEFAULT VALUES;
  83. INSERT INTO t3 VALUES(1,2,3,4);
  84. }
  85. #-------------------------------------------------------------------------
  86. reset_db
  87. do_execsql_test 3.0 {
  88. CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
  89. }
  90. do_test 3.1 {
  91. sqlite3session S db main
  92. S object_config size -1
  93. } 1
  94. do_test 3.2.1 { S object_config size 0 } 0
  95. do_test 3.2.2 { S object_config size -1 } 0
  96. do_test 3.2.3 { S object_config size 1 } 1
  97. do_test 3.2.4 { S object_config size -1 } 1
  98. do_test 3.3 { S attach t1 } {}
  99. do_test 3.4 { S object_config size 1 } {SQLITE_MISUSE}
  100. do_test 3.4 { S object_config size -1 } {1}
  101. S delete
  102. finish_test