:-) (CVS 24)
FossilOrigin-Name: 4cd98ebaeaedf66b258bbfa3a04d90c054294322
This commit is contained in:
+27
-1
@@ -23,7 +23,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing expressions.
|
||||
#
|
||||
# $Id: expr.test,v 1.1 2000/05/30 03:28:36 drh Exp $
|
||||
# $Id: expr.test,v 1.2 2000/05/31 17:59:26 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -62,6 +62,32 @@ test_expr expr-1.20 {i1=20, i2=20} {i2<>i1} 0
|
||||
test_expr expr-1.21 {i1=20, i2=20} {i2==i1} 1
|
||||
test_expr expr-1.22 {i1=1, i2=2, r1=3.0} {i1+i2*r1} {7}
|
||||
test_expr expr-1.23 {i1=1, i2=2, r1=3.0} {(i1+i2)*r1} {9}
|
||||
test_expr expr-1.24 {i1=1, i2=2} {min(i1,i2,i1+i2,i1-i2)} {-1}
|
||||
test_expr expr-1.25 {i1=1, i2=2} {max(i1,i2,i1+i2,i1-i2)} {3}
|
||||
|
||||
|
||||
test_expr expr-2.1 {r1=1.23, r2=2.34} {r1+r2} 3.57
|
||||
test_expr expr-2.2 {r1=1.23, r2=2.34} {r1-r2} -1.11
|
||||
test_expr expr-2.3 {r1=1.23, r2=2.34} {r1*r2} 2.8782
|
||||
test_expr expr-2.4 {r1=1.23, r2=2.34} {r1/r2} 0.525641
|
||||
test_expr expr-2.5 {r1=1.23, r2=2.34} {r2/r1} 1.90244
|
||||
test_expr expr-2.6 {r1=1.23, r2=2.34} {r2<r1} 0
|
||||
test_expr expr-2.7 {r1=1.23, r2=2.34} {r2<=r1} 0
|
||||
test_expr expr-2.8 {r1=1.23, r2=2.34} {r2>r1} 1
|
||||
test_expr expr-2.9 {r1=1.23, r2=2.34} {r2>=r1} 1
|
||||
test_expr expr-2.10 {r1=1.23, r2=2.34} {r2!=r1} 1
|
||||
test_expr expr-2.11 {r1=1.23, r2=2.34} {r2=r1} 0
|
||||
test_expr expr-2.12 {r1=1.23, r2=2.34} {r2<>r1} 1
|
||||
test_expr expr-2.13 {r1=1.23, r2=2.34} {r2==r1} 0
|
||||
test_expr expr-2.14 {r1=2.34, r2=2.34} {r2<r1} 0
|
||||
test_expr expr-2.15 {r1=2.34, r2=2.34} {r2<=r1} 1
|
||||
test_expr expr-2.16 {r1=2.34, r2=2.34} {r2>r1} 0
|
||||
test_expr expr-2.17 {r1=2.34, r2=2.34} {r2>=r1} 1
|
||||
test_expr expr-2.18 {r1=2.34, r2=2.34} {r2!=r1} 0
|
||||
test_expr expr-2.19 {r1=2.34, r2=2.34} {r2=r1} 1
|
||||
test_expr expr-2.20 {r1=2.34, r2=2.34} {r2<>r1} 0
|
||||
test_expr expr-2.21 {r1=2.34, r2=2.34} {r2==r1} 1
|
||||
test_expr expr-2.22 {r1=1.23, r2=2.34} {min(r1,r2,r1+r2,r1-r2)} {-1.11}
|
||||
test_expr expr-2.23 {r1=1.23, r2=2.34} {max(r1,r2,r1+r2,r1-r2)} {3.57}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,275 @@
|
||||
# Copyright (c) 1999, 2000 D. Richard Hipp
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Author contact information:
|
||||
# drh@hwaci.com
|
||||
# http://www.hwaci.com/drh/
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the SELECT statement.
|
||||
#
|
||||
# $Id: select1.test,v 1.1 2000/05/31 17:59:27 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Try to select on a non-existant table.
|
||||
#
|
||||
do_test select-1.1 {
|
||||
set v [catch {execsql {SELECT * FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {1 {no such table: test1}}
|
||||
|
||||
execsql {CREATE TABLE test1(f1 int, f2 int)}
|
||||
|
||||
do_test select-1.2 {
|
||||
set v [catch {execsql {SELECT * FROM test1, test2}} msg]
|
||||
lappend v $msg
|
||||
} {1 {no such table: test2}}
|
||||
do_test select-1.3 {
|
||||
set v [catch {execsql {SELECT * FROM test2, test1}} msg]
|
||||
lappend v $msg
|
||||
} {1 {no such table: test2}}
|
||||
|
||||
execsql {INSERT INTO test1(f1,f2) VALUES(11,22)}
|
||||
|
||||
|
||||
# Make sure the fields are extracted correctly.
|
||||
#
|
||||
do_test select-1.4 {
|
||||
execsql {SELECT f1 FROM test1}
|
||||
} {11}
|
||||
do_test select-1.5 {
|
||||
execsql {SELECT f2 FROM test1}
|
||||
} {22}
|
||||
do_test select-1.6 {
|
||||
execsql {SELECT f2, f1 FROM test1}
|
||||
} {22 11}
|
||||
do_test select-1.7 {
|
||||
execsql {SELECT f1, f2 FROM test1}
|
||||
} {11 22}
|
||||
do_test select-1.8 {
|
||||
execsql {SELECT * FROM test1}
|
||||
} {11 22}
|
||||
|
||||
execsql {CREATE TABLE test2(r1 real, r2 real)}
|
||||
execsql {INSERT INTO test2(r1,r2) VALUES(1.1,2.2)}
|
||||
|
||||
do_test select-1.9 {
|
||||
execsql {SELECT * FROM test1, test2}
|
||||
} {11 22 1.1 2.2}
|
||||
do_test select-1.10 {
|
||||
execsql {SELECT test1.f1, test2.r1 FROM test1, test2}
|
||||
} {11 1.1}
|
||||
do_test select-1.11 {
|
||||
execsql {SELECT test1.f1, test2.r1 FROM test2, test1}
|
||||
} {11 1.1}
|
||||
do_test select-1.12 {
|
||||
execsql {SELECT max(test1.f1,test2.r1), min(test1.f2,test2.r2)
|
||||
FROM test2, test1}
|
||||
} {11 2.2}
|
||||
do_test select-1.13 {
|
||||
execsql {SELECT min(test1.f1,test2.r1), max(test1.f2,test2.r2)
|
||||
FROM test1, test2}
|
||||
} {1.1 22}
|
||||
|
||||
execsql {DROP TABLE test2}
|
||||
execsql {DELETE FROM test1}
|
||||
execsql {INSERT INTO test1 VALUES(11,22)}
|
||||
execsql {INSERT INTO test1 VALUES(33,44)}
|
||||
|
||||
# Error messges from sqliteExprCheck
|
||||
#
|
||||
do_test select-2.1 {
|
||||
set v [catch {execsql {SELECT count(f1,f2) FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {1 {too many arguments to function count()}}
|
||||
do_test select-2.2 {
|
||||
set v [catch {execsql {SELECT count(f1) FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {0 2}
|
||||
do_test select-2.3 {
|
||||
set v [catch {execsql {SELECT Count() FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {0 2}
|
||||
do_test select-2.4 {
|
||||
set v [catch {execsql {SELECT COUNT(*) FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {0 2}
|
||||
do_test select-2.5 {
|
||||
set v [catch {execsql {SELECT COUNT(*)+1 FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {1 {no such function: COUNT}}
|
||||
do_test select-2.6 {
|
||||
set v [catch {execsql {SELECT min(*) FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {1 {too few arguments to function min()}}
|
||||
do_test select-2.7 {
|
||||
set v [catch {execsql {SELECT Min(f1) FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {0 11}
|
||||
do_test select-2.8 {
|
||||
set v [catch {execsql {SELECT MIN(f1,f2) FROM test1}} msg]
|
||||
lappend v [lsort $msg]
|
||||
} {0 {11 33}}
|
||||
do_test select-2.9 {
|
||||
set v [catch {execsql {SELECT MAX(*) FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {1 {too few arguments to function MAX()}}
|
||||
do_test select-2.10 {
|
||||
set v [catch {execsql {SELECT Max(f1) FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {0 33}
|
||||
do_test select-2.11 {
|
||||
set v [catch {execsql {SELECT max(f1,f2) FROM test1}} msg]
|
||||
lappend v [lsort $msg]
|
||||
} {0 {22 44}}
|
||||
do_test select-2.12 {
|
||||
set v [catch {execsql {SELECT MAX(f1,f2)+1 FROM test1}} msg]
|
||||
lappend v [lsort $msg]
|
||||
} {0 {23 45}}
|
||||
do_test select-2.13 {
|
||||
set v [catch {execsql {SELECT MAX(f1)+1 FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {1 {too few arguments to function MAX()}}
|
||||
do_test select-2.14 {
|
||||
set v [catch {execsql {SELECT SUM(*) FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {1 {too few arguments to function SUM()}}
|
||||
do_test select-2.15 {
|
||||
set v [catch {execsql {SELECT Sum(f1) FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {0 44}
|
||||
do_test select-2.16 {
|
||||
set v [catch {execsql {SELECT sum(f1,f2) FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {1 {too many arguments to function sum()}}
|
||||
do_test select-2.17 {
|
||||
set v [catch {execsql {SELECT SUM(f1)+1 FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {1 {no such function: SUM}}
|
||||
do_test select-2.18 {
|
||||
set v [catch {execsql {SELECT XYZZY(f1) FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {1 {no such function: XYZZY}}
|
||||
do_test select-2.19 {
|
||||
set v [catch {execsql {SELECT SUM(min(f1,f2)) FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {0 44}
|
||||
do_test select-2.20 {
|
||||
set v [catch {execsql {SELECT SUM(min(f1)) FROM test1}} msg]
|
||||
lappend v $msg
|
||||
} {1 {too few arguments to function min()}}
|
||||
|
||||
# WHERE clause expressions
|
||||
#
|
||||
do_test select-3.1 {
|
||||
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1<11}} msg]
|
||||
lappend v $msg
|
||||
} {0 {}}
|
||||
do_test select-3.2 {
|
||||
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1<=11}} msg]
|
||||
lappend v $msg
|
||||
} {0 11}
|
||||
do_test select-3.3 {
|
||||
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1=11}} msg]
|
||||
lappend v $msg
|
||||
} {0 11}
|
||||
do_test select-3.4 {
|
||||
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1>=11}} msg]
|
||||
lappend v [lsort $msg]
|
||||
} {0 {11 33}}
|
||||
do_test select-3.5 {
|
||||
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1>11}} msg]
|
||||
lappend v [lsort $msg]
|
||||
} {0 33}
|
||||
do_test select-3.6 {
|
||||
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1!=11}} msg]
|
||||
lappend v [lsort $msg]
|
||||
} {0 33}
|
||||
do_test select-3.7 {
|
||||
set v [catch {execsql {SELECT f1 FROM test1 WHERE min(f1,f2)!=11}} msg]
|
||||
lappend v [lsort $msg]
|
||||
} {0 33}
|
||||
do_test select-3.8 {
|
||||
set v [catch {execsql {SELECT f1 FROM test1 WHERE max(f1,f2)!=11}} msg]
|
||||
lappend v [lsort $msg]
|
||||
} {0 {11 33}}
|
||||
do_test select-3.9 {
|
||||
set v [catch {execsql {SELECT f1 FROM test1 WHERE count(f1,f2)!=11}} msg]
|
||||
lappend v $msg
|
||||
} {1 {no such function: count}}
|
||||
|
||||
# ORDER BY expressions
|
||||
#
|
||||
do_test select-4.1 {
|
||||
set v [catch {execsql {SELECT f1 FROM test1 ORDER BY f1}} msg]
|
||||
lappend v $msg
|
||||
} {0 {11 33}}
|
||||
do_test select-4.2 {
|
||||
set v [catch {execsql {SELECT f1 FROM test1 ORDER BY -f1}} msg]
|
||||
lappend v $msg
|
||||
} {0 {33 11}}
|
||||
do_test select-4.3 {
|
||||
set v [catch {execsql {SELECT f1 FROM test1 ORDER BY min(f1,f2)}} msg]
|
||||
lappend v $msg
|
||||
} {0 {11 33}}
|
||||
do_test select-4.4 {
|
||||
set v [catch {execsql {SELECT f1 FROM test1 ORDER BY min(f1)}} msg]
|
||||
lappend v $msg
|
||||
} {1 {too few arguments to function min()}}
|
||||
|
||||
# ORDER BY ignored on an aggregate query
|
||||
#
|
||||
do_test select-5.1 {
|
||||
set v [catch {execsql {SELECT max(f1) FROM test1 ORDER BY f2}} msg]
|
||||
lappend v $msg
|
||||
} {0 33}
|
||||
|
||||
execsql {CREATE TABLE test2(t1 test, t2 text)}
|
||||
execsql {INSERT INTO test2 VALUES('abc','xyz')}
|
||||
|
||||
# Check for field naming
|
||||
#
|
||||
do_test select-6.1 {
|
||||
set v [catch {execsql2 {SELECT f1 FROM test1 ORDER BY f2}} msg]
|
||||
lappend v $msg
|
||||
} {0 {f1 11 f1 33}}
|
||||
do_test select-6.2 {
|
||||
set v [catch {execsql2 {SELECT f1 as xyzzy FROM test1 ORDER BY f2}} msg]
|
||||
lappend v $msg
|
||||
} {0 {xyzzy 11 xyzzy 33}}
|
||||
do_test select-6.3 {
|
||||
set v [catch {execsql2 {SELECT f1 as "xyzzy" FROM test1 ORDER BY f2}} msg]
|
||||
lappend v $msg
|
||||
} {0 {xyzzy 11 xyzzy 33}}
|
||||
do_test select-6.4 {
|
||||
set v [catch {execsql2 {SELECT f1+F2 as xyzzy FROM test1 ORDER BY f2}} msg]
|
||||
lappend v $msg
|
||||
} {0 {xyzzy 33 xyzzy 77}}
|
||||
do_test select-6.5 {
|
||||
set v [catch {execsql2 {SELECT test1.f1+F2 FROM test1 ORDER BY f2}} msg]
|
||||
lappend v $msg
|
||||
} {0 {field1 33 field1 77}}
|
||||
do_test select-6.6 {
|
||||
set v [catch {execsql2 {SELECT test1.f1+F2, t1 FROM test1, test2
|
||||
ORDER BY f2}} msg]
|
||||
lappend v $msg
|
||||
} {0 {field1 33 test2.t1 abc field1 77 test2.t1 abc}}
|
||||
|
||||
finish_test
|
||||
+14
-1
@@ -23,7 +23,7 @@
|
||||
# This file implements some common TCL routines used for regression
|
||||
# testing the SQLite library
|
||||
#
|
||||
# $Id: tester.tcl,v 1.3 2000/05/30 00:51:27 drh Exp $
|
||||
# $Id: tester.tcl,v 1.4 2000/05/31 17:59:27 drh Exp $
|
||||
|
||||
# Create a test database
|
||||
#
|
||||
@@ -89,3 +89,16 @@ proc execsql {sql} {
|
||||
}
|
||||
return $result
|
||||
}
|
||||
|
||||
# Another procedure to execute SQL. This one includes the field
|
||||
# names in the returned list.
|
||||
#
|
||||
proc execsql2 {sql} {
|
||||
set result {}
|
||||
db eval $sql data {
|
||||
foreach f $data(*) {
|
||||
lappend result $f $data($f)
|
||||
}
|
||||
}
|
||||
return $result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user