join4.test 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # 2002 May 24
  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 WHERE
  14. # clauses that restrict the scope of the left term of the join.
  15. #
  16. # $Id: join4.test,v 1.4 2005/03/29 03:11:00 danielk1977 Exp $
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. ifcapable tempdb {
  20. do_test join4-1.1 {
  21. execsql {
  22. create temp table t1(a integer, b varchar(10));
  23. insert into t1 values(1,'one');
  24. insert into t1 values(2,'two');
  25. insert into t1 values(3,'three');
  26. insert into t1 values(4,'four');
  27. create temp table t2(x integer, y varchar(10), z varchar(10));
  28. insert into t2 values(2,'niban','ok');
  29. insert into t2 values(4,'yonban','err');
  30. }
  31. execsql {
  32. select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok'
  33. }
  34. } {2 two 2 niban ok}
  35. } else {
  36. do_test join4-1.1 {
  37. execsql {
  38. create table t1(a integer, b varchar(10));
  39. insert into t1 values(1,'one');
  40. insert into t1 values(2,'two');
  41. insert into t1 values(3,'three');
  42. insert into t1 values(4,'four');
  43. create table t2(x integer, y varchar(10), z varchar(10));
  44. insert into t2 values(2,'niban','ok');
  45. insert into t2 values(4,'yonban','err');
  46. }
  47. execsql {
  48. select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok'
  49. }
  50. } {2 two 2 niban ok}
  51. }
  52. do_test join4-1.2 {
  53. execsql {
  54. select * from t1 left outer join t2 on t1.a=t2.x and t2.z='ok'
  55. }
  56. } {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
  57. do_test join4-1.3 {
  58. execsql {
  59. create index i2 on t2(z);
  60. }
  61. execsql {
  62. select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok'
  63. }
  64. } {2 two 2 niban ok}
  65. do_test join4-1.4 {
  66. execsql {
  67. select * from t1 left outer join t2 on t1.a=t2.x and t2.z='ok'
  68. }
  69. } {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
  70. do_test join4-1.5 {
  71. execsql {
  72. select * from t1 left outer join t2 on t1.a=t2.x where t2.z>='ok'
  73. }
  74. } {2 two 2 niban ok}
  75. do_test join4-1.4 {
  76. execsql {
  77. select * from t1 left outer join t2 on t1.a=t2.x and t2.z>='ok'
  78. }
  79. } {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
  80. ifcapable subquery {
  81. do_test join4-1.6 {
  82. execsql {
  83. select * from t1 left outer join t2 on t1.a=t2.x where t2.z IN ('ok')
  84. }
  85. } {2 two 2 niban ok}
  86. do_test join4-1.7 {
  87. execsql {
  88. select * from t1 left outer join t2 on t1.a=t2.x and t2.z IN ('ok')
  89. }
  90. } {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
  91. }
  92. finish_test