os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/join4.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# 2002 May 24
sl@0
     2
#
sl@0
     3
# The author disclaims copyright to this source code.  In place of
sl@0
     4
# a legal notice, here is a blessing:
sl@0
     5
#
sl@0
     6
#    May you do good and not evil.
sl@0
     7
#    May you find forgiveness for yourself and forgive others.
sl@0
     8
#    May you share freely, never taking more than you give.
sl@0
     9
#
sl@0
    10
#***********************************************************************
sl@0
    11
# This file implements regression tests for SQLite library.
sl@0
    12
#
sl@0
    13
# This file implements tests for left outer joins containing WHERE
sl@0
    14
# clauses that restrict the scope of the left term of the join.
sl@0
    15
#
sl@0
    16
# $Id: join4.test,v 1.4 2005/03/29 03:11:00 danielk1977 Exp $
sl@0
    17
sl@0
    18
set testdir [file dirname $argv0]
sl@0
    19
source $testdir/tester.tcl
sl@0
    20
sl@0
    21
ifcapable tempdb {
sl@0
    22
  do_test join4-1.1 {
sl@0
    23
    execsql {
sl@0
    24
      create temp table t1(a integer, b varchar(10));
sl@0
    25
      insert into t1 values(1,'one');
sl@0
    26
      insert into t1 values(2,'two');
sl@0
    27
      insert into t1 values(3,'three');
sl@0
    28
      insert into t1 values(4,'four');
sl@0
    29
  
sl@0
    30
      create temp table t2(x integer, y varchar(10), z varchar(10));
sl@0
    31
      insert into t2 values(2,'niban','ok');
sl@0
    32
      insert into t2 values(4,'yonban','err');
sl@0
    33
    }
sl@0
    34
    execsql {
sl@0
    35
      select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok'
sl@0
    36
    }
sl@0
    37
  } {2 two 2 niban ok}
sl@0
    38
} else {
sl@0
    39
  do_test join4-1.1 {
sl@0
    40
    execsql {
sl@0
    41
      create table t1(a integer, b varchar(10));
sl@0
    42
      insert into t1 values(1,'one');
sl@0
    43
      insert into t1 values(2,'two');
sl@0
    44
      insert into t1 values(3,'three');
sl@0
    45
      insert into t1 values(4,'four');
sl@0
    46
  
sl@0
    47
      create table t2(x integer, y varchar(10), z varchar(10));
sl@0
    48
      insert into t2 values(2,'niban','ok');
sl@0
    49
      insert into t2 values(4,'yonban','err');
sl@0
    50
    }
sl@0
    51
    execsql {
sl@0
    52
      select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok'
sl@0
    53
    }
sl@0
    54
  } {2 two 2 niban ok}
sl@0
    55
}
sl@0
    56
do_test join4-1.2 {
sl@0
    57
  execsql {
sl@0
    58
    select * from t1 left outer join t2 on t1.a=t2.x and t2.z='ok'
sl@0
    59
  }
sl@0
    60
} {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
sl@0
    61
do_test join4-1.3 {
sl@0
    62
  execsql {
sl@0
    63
    create index i2 on t2(z);
sl@0
    64
  }
sl@0
    65
  execsql {
sl@0
    66
    select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok'
sl@0
    67
  }
sl@0
    68
} {2 two 2 niban ok}
sl@0
    69
do_test join4-1.4 {
sl@0
    70
  execsql {
sl@0
    71
    select * from t1 left outer join t2 on t1.a=t2.x and t2.z='ok'
sl@0
    72
  }
sl@0
    73
} {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
sl@0
    74
do_test join4-1.5 {
sl@0
    75
  execsql {
sl@0
    76
    select * from t1 left outer join t2 on t1.a=t2.x where t2.z>='ok'
sl@0
    77
  }
sl@0
    78
} {2 two 2 niban ok}
sl@0
    79
do_test join4-1.4 {
sl@0
    80
  execsql {
sl@0
    81
    select * from t1 left outer join t2 on t1.a=t2.x and t2.z>='ok'
sl@0
    82
  }
sl@0
    83
} {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
sl@0
    84
ifcapable subquery {
sl@0
    85
  do_test join4-1.6 {
sl@0
    86
    execsql {
sl@0
    87
      select * from t1 left outer join t2 on t1.a=t2.x where t2.z IN ('ok')
sl@0
    88
    }
sl@0
    89
  } {2 two 2 niban ok}
sl@0
    90
  do_test join4-1.7 {
sl@0
    91
    execsql {
sl@0
    92
      select * from t1 left outer join t2 on t1.a=t2.x and t2.z IN ('ok')
sl@0
    93
    }
sl@0
    94
  } {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
sl@0
    95
}
sl@0
    96
sl@0
    97
sl@0
    98
finish_test