SQLite

Check-in [9f9a95cc80]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add tests for the EXISTS operator to e_expr.test.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9f9a95cc80961b2733d34bd66cfccfbffb358ed6
User & Date: dan 2010-09-02 11:53:12.000
Context
2010-09-02
14:00
Fix the computation of the offset on the mmap() for the Nth shared memory region. Because of the way shared memory is accessed, the old computation, though wrong, still happened to always get the right answer. Nevertheless, it is good to do the computation correctly. (check-in: 36397f62f2 user: drh tags: trunk)
11:53
Add tests for the EXISTS operator to e_expr.test. (check-in: 9f9a95cc80 user: dan tags: trunk)
10:08
If MEM_STATUS is disabled, avoid holding the STATIC_MEM mutex when calling the user-defined xMalloc method. Holding the mutex causes problems for memsys3 and memsys5. (check-in: 4f20f8ba73 user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to test/e_expr.test.
13
14
15
16
17
18
19











20
21
22
23
24
25
26
# the lang_expr.html document are correct.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl












# Set up three global variables:
#
#   ::opname         An array mapping from SQL operator to an easy to parse
#                    name. The names are used as part of test case names.
#
#   ::opprec         An array mapping from SQL operator to a numeric
#                    precedence value. Operators that group more tightly







>
>
>
>
>
>
>
>
>
>
>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# the lang_expr.html document are correct.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl


proc do_expr_test {tn expr type value} {
  uplevel do_execsql_test $tn [list "SELECT typeof($expr), $expr"] [
    list [list $type $value]
  ]
}

proc do_qexpr_test {tn expr value} {
  uplevel do_execsql_test $tn [list "SELECT quote($expr)"] [list $value]
}

# Set up three global variables:
#
#   ::opname         An array mapping from SQL operator to an easy to parse
#                    name. The names are used as part of test case names.
#
#   ::opprec         An array mapping from SQL operator to a numeric
#                    precedence value. Operators that group more tightly
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
do_execsql_test e_expr-27.1.2 {
  SELECT 
    typeof(CAST(X'555655' as TEXT)), CAST(X'555655' as TEXT),
    typeof(CAST('1.23abc' as REAL)), CAST('1.23abc' as REAL),
    typeof(CAST(4.5 as INTEGER)), CAST(4.5 as INTEGER)
} {text UVU real 1.23 integer 4}

proc do_expr_test {tn expr type value} {
  uplevel do_execsql_test $tn [list "SELECT typeof($expr), $expr"] [
    list [list $type $value]
  ]
}
proc do_qexpr_test {tn expr value} {
  uplevel do_execsql_test $tn [list "SELECT quote($expr)"] [list $value]
}

# EVIDENCE-OF: R-27225-65050 If the value of <expr> is NULL, then
# the result of the CAST expression is also NULL.
#
do_expr_test e_expr-27.2.1 { CAST(NULL AS integer) } null {}
do_expr_test e_expr-27.2.2 { CAST(NULL AS text) }    null {}
do_expr_test e_expr-27.2.3 { CAST(NULL AS blob) }    null {}
do_expr_test e_expr-27.2.4 { CAST(NULL AS number) }  null {}







<
<
<
<
<
<
<
<
<







1406
1407
1408
1409
1410
1411
1412









1413
1414
1415
1416
1417
1418
1419
do_execsql_test e_expr-27.1.2 {
  SELECT 
    typeof(CAST(X'555655' as TEXT)), CAST(X'555655' as TEXT),
    typeof(CAST('1.23abc' as REAL)), CAST('1.23abc' as REAL),
    typeof(CAST(4.5 as INTEGER)), CAST(4.5 as INTEGER)
} {text UVU real 1.23 integer 4}










# EVIDENCE-OF: R-27225-65050 If the value of <expr> is NULL, then
# the result of the CAST expression is also NULL.
#
do_expr_test e_expr-27.2.1 { CAST(NULL AS integer) } null {}
do_expr_test e_expr-27.2.2 { CAST(NULL AS text) }    null {}
do_expr_test e_expr-27.2.3 { CAST(NULL AS blob) }    null {}
do_expr_test e_expr-27.2.4 { CAST(NULL AS number) }  null {}
1642
1643
1644
1645
1646
1647
1648
1649






















































































1650

  }

  do_test e_expr-33.1.$tn {set res} 1
}
db1 close
db2 close
db3 close























































































finish_test









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
  }

  do_test e_expr-33.1.$tn {set res} 1
}
db1 close
db2 close
db3 close

#-------------------------------------------------------------------------
# Test statements related to the EXISTS and NOT EXISTS operators.
#
catch { db close }
file delete -force test.db
sqlite3 db test.db

do_execsql_test e_expr-34.1 {
  CREATE TABLE t1(a, b);
  INSERT INTO t1 VALUES(1, 2);
  INSERT INTO t1 VALUES(NULL, 2);
  INSERT INTO t1 VALUES(1, NULL);
  INSERT INTO t1 VALUES(NULL, NULL);
} {}

# EVIDENCE-OF: R-25588-27181 The EXISTS operator always evaluates to one
# of the integer values 0 and 1.
#
# This statement is not tested by itself. Instead, all e_expr-34.* tests 
# following this point explicitly test that specific invocations of EXISTS
# return either integer 0 or integer 1.
#

# EVIDENCE-OF: R-58553-63740 If executing the SELECT statement specified
# as the right-hand operand of the EXISTS operator would return one or
# more rows, then the EXISTS operator evaluates to 1.
#
foreach {tn expr} {
    1 { EXISTS ( SELECT a FROM t1 ) }
    2 { EXISTS ( SELECT b FROM t1 ) }
    3 { EXISTS ( SELECT 24 ) }
    4 { EXISTS ( SELECT NULL ) }
    5 { EXISTS ( SELECT a FROM t1 WHERE a IS NULL ) }
} {
  do_expr_test e_expr-34.2.$tn $expr integer 1
}

# EVIDENCE-OF: R-19673-40972 If executing the SELECT would return no
# rows at all, then the EXISTS operator evaluates to 0.
#
foreach {tn expr} {
    1 { EXISTS ( SELECT a FROM t1 WHERE 0) }
    2 { EXISTS ( SELECT b FROM t1 WHERE a = 5) }
    3 { EXISTS ( SELECT 24 WHERE 0) }
    4 { EXISTS ( SELECT NULL WHERE 1=2) }
} {
  do_expr_test e_expr-34.3.$tn $expr integer 0
}

# EVIDENCE-OF: R-35109-49139 The number of columns in each row returned
# by the SELECT statement (if any) and the specific values returned have
# no effect on the results of the EXISTS operator.
#
foreach {tn expr res} {
    1 { EXISTS ( SELECT * FROM t1 ) }                          1
    2 { EXISTS ( SELECT *, *, * FROM t1 ) }                    1
    3 { EXISTS ( SELECT 24, 25 ) }                             1
    4 { EXISTS ( SELECT NULL, NULL, NULL ) }                   1
    5 { EXISTS ( SELECT a,b,a||b FROM t1 WHERE a IS NULL ) }   1

    6 { EXISTS ( SELECT a, a FROM t1 WHERE 0) }                0
    7 { EXISTS ( SELECT b, b, a FROM t1 WHERE a = 5) }         0
    8 { EXISTS ( SELECT 24, 46, 89 WHERE 0) }                  0
    9 { EXISTS ( SELECT NULL, NULL WHERE 1=2) }                0
} {
  do_expr_test e_expr-34.4.$tn $expr integer $res
}

# EVIDENCE-OF: R-10645-12439 In particular, rows containing NULL values
# are not handled any differently from rows without NULL values.
#
foreach {tn e1 e2} {
  1 { EXISTS (SELECT 'not null') }    { EXISTS (SELECT NULL) }
  2 { EXISTS (SELECT NULL FROM t1) }  { EXISTS (SELECT 'bread' FROM t1) }
} {
  set res [db one "SELECT $e1"]
  do_expr_test e_expr-34.5.${tn}a $e1 integer $res
  do_expr_test e_expr-34.5.${tn}b $e2 integer $res
}



#-------------------------------------------------------------------------
# Test statements related to the IN and NOT IN operators.
#

finish_test