join5.test 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # 2005 September 19
  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 left outer joins containing ON
  14. # clauses that restrict the scope of the left term of the join.
  15. #
  16. # $Id: join5.test,v 1.2 2007/06/08 00:20:48 drh Exp $
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. do_test join5-1.1 {
  20. execsql {
  21. BEGIN;
  22. CREATE TABLE t1(a integer primary key, b integer, c integer);
  23. CREATE TABLE t2(x integer primary key, y);
  24. CREATE TABLE t3(p integer primary key, q);
  25. INSERT INTO t3 VALUES(11,'t3-11');
  26. INSERT INTO t3 VALUES(12,'t3-12');
  27. INSERT INTO t2 VALUES(11,'t2-11');
  28. INSERT INTO t2 VALUES(12,'t2-12');
  29. INSERT INTO t1 VALUES(1, 5, 0);
  30. INSERT INTO t1 VALUES(2, 11, 2);
  31. INSERT INTO t1 VALUES(3, 12, 1);
  32. COMMIT;
  33. }
  34. } {}
  35. do_test join5-1.2 {
  36. execsql {
  37. select * from t1 left join t2 on t1.b=t2.x and t1.c=1
  38. }
  39. } {1 5 0 {} {} 2 11 2 {} {} 3 12 1 12 t2-12}
  40. do_test join5-1.3 {
  41. execsql {
  42. select * from t1 left join t2 on t1.b=t2.x where t1.c=1
  43. }
  44. } {3 12 1 12 t2-12}
  45. do_test join5-1.4 {
  46. execsql {
  47. select * from t1 left join t2 on t1.b=t2.x and t1.c=1
  48. left join t3 on t1.b=t3.p and t1.c=2
  49. }
  50. } {1 5 0 {} {} {} {} 2 11 2 {} {} 11 t3-11 3 12 1 12 t2-12 {} {}}
  51. do_test join5-1.5 {
  52. execsql {
  53. select * from t1 left join t2 on t1.b=t2.x and t1.c=1
  54. left join t3 on t1.b=t3.p where t1.c=2
  55. }
  56. } {2 11 2 {} {} 11 t3-11}
  57. # Ticket #2403
  58. #
  59. do_test join5-2.1 {
  60. execsql {
  61. CREATE TABLE ab(a,b);
  62. INSERT INTO "ab" VALUES(1,2);
  63. INSERT INTO "ab" VALUES(3,NULL);
  64. CREATE TABLE xy(x,y);
  65. INSERT INTO "xy" VALUES(2,3);
  66. INSERT INTO "xy" VALUES(NULL,1);
  67. }
  68. execsql {SELECT * FROM xy LEFT JOIN ab ON 0}
  69. } {2 3 {} {} {} 1 {} {}}
  70. do_test join5-2.2 {
  71. execsql {SELECT * FROM xy LEFT JOIN ab ON 1}
  72. } {2 3 1 2 2 3 3 {} {} 1 1 2 {} 1 3 {}}
  73. do_test join5-2.3 {
  74. execsql {SELECT * FROM xy LEFT JOIN ab ON NULL}
  75. } {2 3 {} {} {} 1 {} {}}
  76. do_test join5-2.4 {
  77. execsql {SELECT * FROM xy LEFT JOIN ab ON 0 WHERE 0}
  78. } {}
  79. do_test join5-2.5 {
  80. execsql {SELECT * FROM xy LEFT JOIN ab ON 1 WHERE 0}
  81. } {}
  82. do_test join5-2.6 {
  83. execsql {SELECT * FROM xy LEFT JOIN ab ON NULL WHERE 0}
  84. } {}
  85. do_test join5-2.7 {
  86. execsql {SELECT * FROM xy LEFT JOIN ab ON 0 WHERE 1}
  87. } {2 3 {} {} {} 1 {} {}}
  88. do_test join5-2.8 {
  89. execsql {SELECT * FROM xy LEFT JOIN ab ON 1 WHERE 1}
  90. } {2 3 1 2 2 3 3 {} {} 1 1 2 {} 1 3 {}}
  91. do_test join5-2.9 {
  92. execsql {SELECT * FROM xy LEFT JOIN ab ON NULL WHERE 1}
  93. } {2 3 {} {} {} 1 {} {}}
  94. do_test join5-2.10 {
  95. execsql {SELECT * FROM xy LEFT JOIN ab ON 0 WHERE NULL}
  96. } {}
  97. do_test join5-2.11 {
  98. execsql {SELECT * FROM xy LEFT JOIN ab ON 1 WHERE NULL}
  99. } {}
  100. do_test join5-2.12 {
  101. execsql {SELECT * FROM xy LEFT JOIN ab ON NULL WHERE NULL}
  102. } {}
  103. finish_test