drh | bed8690 | 2000-06-02 13:27:59 +0000 | [diff] [blame] | 1 | # Copyright (c) 1999, 2000 D. Richard Hipp |
| 2 | # |
| 3 | # This program is free software; you can redistribute it and/or |
| 4 | # modify it under the terms of the GNU General Public |
| 5 | # License as published by the Free Software Foundation; either |
| 6 | # version 2 of the License, or (at your option) any later version. |
| 7 | # |
| 8 | # This program is distributed in the hope that it will be useful, |
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | # General Public License for more details. |
| 12 | # |
| 13 | # You should have received a copy of the GNU General Public |
| 14 | # License along with this library; if not, write to the |
| 15 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 16 | # Boston, MA 02111-1307, USA. |
| 17 | # |
| 18 | # Author contact information: |
| 19 | # drh@hwaci.com |
| 20 | # http://www.hwaci.com/drh/ |
| 21 | # |
| 22 | #*********************************************************************** |
| 23 | # This file implements regression tests for SQLite library. The |
| 24 | # focus of this file is testing the SELECT statement. |
| 25 | # |
drh | df16aed | 2000-06-02 14:27:22 +0000 | [diff] [blame^] | 26 | # $Id: select2.test,v 1.2 2000/06/02 14:27:23 drh Exp $ |
drh | bed8690 | 2000-06-02 13:27:59 +0000 | [diff] [blame] | 27 | |
| 28 | set testdir [file dirname $argv0] |
| 29 | source $testdir/tester.tcl |
| 30 | |
| 31 | execsql {CREATE TABLE tbl1(f1 int, f2 int)} |
drh | df16aed | 2000-06-02 14:27:22 +0000 | [diff] [blame^] | 32 | set f [open ./testdata1.txt w] |
drh | bed8690 | 2000-06-02 13:27:59 +0000 | [diff] [blame] | 33 | for {set i 0} {$i<=30} {incr i} { |
drh | df16aed | 2000-06-02 14:27:22 +0000 | [diff] [blame^] | 34 | puts $f "[expr {$i%9}]\t[expr {$i%10}]\n" |
drh | bed8690 | 2000-06-02 13:27:59 +0000 | [diff] [blame] | 35 | } |
drh | df16aed | 2000-06-02 14:27:22 +0000 | [diff] [blame^] | 36 | close $f |
| 37 | execsql {COPY tbl1 FROM './testdata1.txt'} |
| 38 | # file delete -force ./testdata1.txt |
drh | bed8690 | 2000-06-02 13:27:59 +0000 | [diff] [blame] | 39 | |
| 40 | # Do a second query inside a first. |
| 41 | # |
| 42 | do_test select2-1.1 { |
| 43 | set sql {SELECT DISTINCT f1 FROM tbl1 ORDER BY f1} |
| 44 | set r {} |
| 45 | db eval $sql data { |
| 46 | set f1 $data(f1) |
| 47 | lappend r $f1: |
| 48 | set sql2 "SELECT f2 FROM tbl1 WHERE f1=$f1 ORDER BY f2" |
| 49 | db eval $sql2 d2 { |
| 50 | lappend r $d2(f2) |
| 51 | } |
| 52 | } |
| 53 | set r |
| 54 | } {0: 0 7 8 9 1: 0 1 8 9 2: 0 1 2 9 3: 0 1 2 3 4: 2 3 4 5: 3 4 5 6: 4 5 6 7: 5 6 7 8: 6 7 8} |
| 55 | |
| 56 | |
| 57 | do_test select2-1.2 { |
| 58 | set sql {SELECT DISTINCT f1 FROM tbl1 WHERE f1>3 AND f1<5} |
| 59 | set r {} |
| 60 | db eval $sql data { |
| 61 | set f1 $data(f1) |
| 62 | lappend r $f1: |
| 63 | set sql2 "SELECT f2 FROM tbl1 WHERE f1=$f1 ORDER BY f2" |
| 64 | db eval $sql2 d2 { |
| 65 | lappend r $d2(f2) |
| 66 | } |
| 67 | } |
| 68 | set r |
| 69 | } {4: 2 3 4} |
| 70 | |
| 71 | finish_test |