index4.test 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # 2011 July 9
  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. The
  12. # focus of this file is testing the CREATE INDEX statement.
  13. #
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. set testprefix index4
  17. do_execsql_test 1.1 {
  18. BEGIN;
  19. CREATE TABLE t1(x);
  20. INSERT INTO t1 VALUES(randomblob(102));
  21. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 2
  22. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 4
  23. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 8
  24. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 16
  25. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 32
  26. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 64
  27. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 128
  28. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 256
  29. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 512
  30. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 1024
  31. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 2048
  32. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 4096
  33. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 8192
  34. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 16384
  35. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 32768
  36. INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 65536
  37. COMMIT;
  38. }
  39. do_execsql_test 1.2 {
  40. CREATE INDEX i1 ON t1(x);
  41. }
  42. do_execsql_test 1.3 {
  43. PRAGMA integrity_check
  44. } {ok}
  45. # The same test again - this time with limited memory.
  46. #
  47. ifcapable memorymanage {
  48. set soft_limit [sqlite3_soft_heap_limit 50000]
  49. db close
  50. sqlite3 db test.db
  51. do_execsql_test 1.4 {
  52. PRAGMA cache_size = 10;
  53. CREATE INDEX i2 ON t1(x);
  54. }
  55. do_execsql_test 1.5 {
  56. PRAGMA integrity_check
  57. } {ok}
  58. sqlite3_soft_heap_limit $soft_limit
  59. }
  60. do_execsql_test 1.6 {
  61. BEGIN;
  62. DROP TABLE t1;
  63. CREATE TABLE t1(x);
  64. INSERT INTO t1 VALUES('a');
  65. INSERT INTO t1 VALUES('b');
  66. INSERT INTO t1 VALUES('c');
  67. INSERT INTO t1 VALUES('d');
  68. INSERT INTO t1 VALUES('e');
  69. INSERT INTO t1 VALUES('f');
  70. INSERT INTO t1 VALUES('g');
  71. INSERT INTO t1 VALUES(NULL);
  72. INSERT INTO t1 SELECT randomblob(1202) FROM t1; -- 16
  73. INSERT INTO t1 SELECT randomblob(2202) FROM t1; -- 32
  74. INSERT INTO t1 SELECT randomblob(3202) FROM t1; -- 64
  75. INSERT INTO t1 SELECT randomblob(4202) FROM t1; -- 128
  76. INSERT INTO t1 SELECT randomblob(5202) FROM t1; -- 256
  77. COMMIT;
  78. CREATE INDEX i1 ON t1(x);
  79. PRAGMA integrity_check
  80. } {ok}
  81. do_execsql_test 1.7 {
  82. BEGIN;
  83. DROP TABLE t1;
  84. CREATE TABLE t1(x);
  85. INSERT INTO t1 VALUES('a');
  86. COMMIT;
  87. CREATE INDEX i1 ON t1(x);
  88. PRAGMA integrity_check
  89. } {ok}
  90. do_execsql_test 1.8 {
  91. BEGIN;
  92. DROP TABLE t1;
  93. CREATE TABLE t1(x);
  94. COMMIT;
  95. CREATE INDEX i1 ON t1(x);
  96. PRAGMA integrity_check
  97. } {ok}
  98. do_execsql_test 2.1 {
  99. BEGIN;
  100. CREATE TABLE t2(x);
  101. INSERT INTO t2 VALUES(14);
  102. INSERT INTO t2 VALUES(35);
  103. INSERT INTO t2 VALUES(15);
  104. INSERT INTO t2 VALUES(35);
  105. INSERT INTO t2 VALUES(16);
  106. COMMIT;
  107. }
  108. do_catchsql_test 2.2 {
  109. CREATE UNIQUE INDEX i3 ON t2(x);
  110. } {1 {indexed columns are not unique}}
  111. finish_test