intarray.test 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # 2009 November 10
  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. # This file implements tests for the "intarray" object implemented
  14. # in test_intarray.c.
  15. #
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. ifcapable !vtab {
  19. return
  20. }
  21. do_test intarray-1.0 {
  22. db eval {
  23. CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
  24. }
  25. for {set i 1} {$i<=999} {incr i} {
  26. set b [format {x%03d} $i]
  27. db eval {INSERT INTO t1(a,b) VALUES($i,$b)}
  28. }
  29. db eval {
  30. CREATE TABLE t2(x INTEGER PRIMARY KEY, y);
  31. INSERT INTO t2 SELECT * FROM t1;
  32. SELECT b FROM t1 WHERE a IN (12,34,56,78) ORDER BY a
  33. }
  34. } {x012 x034 x056 x078}
  35. do_test intarray-1.1 {
  36. set ia1 [sqlite3_intarray_create db ia1]
  37. set ia2 [sqlite3_intarray_create db ia2]
  38. set ia3 [sqlite3_intarray_create db ia3]
  39. set ia4 [sqlite3_intarray_create db ia4]
  40. db eval {
  41. SELECT type, name FROM sqlite_temp_master
  42. ORDER BY name
  43. }
  44. } {table ia1 table ia2 table ia3 table ia4}
  45. do_test intarray-1.2 {
  46. db eval {
  47. SELECT b FROM t1 WHERE a IN ia3 ORDER BY a
  48. }
  49. } {}
  50. do_test intarray-1.3 {
  51. sqlite3_intarray_bind $ia3 45 123 678
  52. db eval {
  53. SELECT b FROM t1 WHERE a IN ia3 ORDER BY a
  54. }
  55. } {x045 x123 x678}
  56. do_test intarray-1.4 {
  57. db eval {
  58. SELECT count(b) FROM t1 WHERE a NOT IN ia3 ORDER BY a
  59. }
  60. } {996}
  61. #explain {SELECT b FROM t1 WHERE a NOT IN ia3}
  62. do_test intarray-1.5 {
  63. set cmd sqlite3_intarray_bind
  64. lappend cmd $ia1
  65. for {set i 1} {$i<=999} {incr i} {
  66. lappend cmd $i
  67. lappend cmd [expr {$i+1000}]
  68. lappend cmd [expr {$i+2000}]
  69. }
  70. eval $cmd
  71. db eval {
  72. REPLACE INTO t1 SELECT * FROM t2;
  73. DELETE FROM t1 WHERE a NOT IN ia1;
  74. SELECT count(*) FROM t1;
  75. }
  76. } {999}
  77. do_test intarray-1.6 {
  78. db eval {
  79. DELETE FROM t1 WHERE a IN ia1;
  80. SELECT count(*) FROM t1;
  81. }
  82. } {0}
  83. do_test intarray-2.1 {
  84. db eval {
  85. CREATE TEMP TABLE t3(p,q);
  86. INSERT INTO t3 SELECT * FROM t2;
  87. SELECT count(*) FROM t3 WHERE p IN ia1;
  88. }
  89. } {999}
  90. do_test intarray-2.2 {
  91. set ia5 [sqlite3_intarray_create db ia5]
  92. db eval {
  93. SELECT count(*) FROM t3 WHERE p IN ia1;
  94. }
  95. } {999}
  96. finish_test