os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/join3.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
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 joins, including outer joins, where
sl@0
    14
# there are a large number of tables involved in the join.
sl@0
    15
#
sl@0
    16
# $Id: join3.test,v 1.4 2005/01/19 23:24:51 drh 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
# An unrestricted join
sl@0
    22
#
sl@0
    23
catch {unset ::result}
sl@0
    24
set result {}
sl@0
    25
for {set N 1} {$N<=$bitmask_size} {incr N} {
sl@0
    26
  lappend result $N
sl@0
    27
  do_test join3-1.$N {
sl@0
    28
    execsql "CREATE TABLE t${N}(x);"
sl@0
    29
    execsql "INSERT INTO t$N VALUES($N)"
sl@0
    30
    set sql "SELECT * FROM t1"
sl@0
    31
    for {set i 2} {$i<=$N} {incr i} {append sql ", t$i"}
sl@0
    32
    execsql $sql
sl@0
    33
  } $result
sl@0
    34
}
sl@0
    35
sl@0
    36
# Joins with a comparison
sl@0
    37
#
sl@0
    38
set result {}
sl@0
    39
for {set N 1} {$N<=$bitmask_size} {incr N} {
sl@0
    40
  lappend result $N
sl@0
    41
  do_test join3-2.$N {
sl@0
    42
    set sql "SELECT * FROM t1"
sl@0
    43
    for {set i 2} {$i<=$N} {incr i} {append sql ", t$i"}
sl@0
    44
    set sep WHERE
sl@0
    45
    for {set i 1} {$i<$N} {incr i} {
sl@0
    46
      append sql " $sep t[expr {$i+1}].x==t$i.x+1"
sl@0
    47
      set sep AND
sl@0
    48
    }
sl@0
    49
    execsql $sql
sl@0
    50
  } $result
sl@0
    51
}
sl@0
    52
sl@0
    53
# Error of too many tables in the join
sl@0
    54
#
sl@0
    55
do_test join3-3.1 {
sl@0
    56
  set sql "SELECT * FROM t1 AS t0, t1"
sl@0
    57
  for {set i 2} {$i<=$bitmask_size} {incr i} {append sql ", t$i"}
sl@0
    58
  catchsql $sql
sl@0
    59
} [list 1 "at most $bitmask_size tables in a join"]
sl@0
    60
sl@0
    61
sl@0
    62
finish_test