summaryrefslogtreecommitdiff
path: root/test/whereA.test
blob: 5d0aca591ca2790ced5ec27d801d4224df27026a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# 2009 February 23
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this file is testing the reverse_select_order pragma.
#
# $Id: whereA.test,v 1.3 2009/06/10 19:33:29 drh Exp $

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

do_test whereA-1.1 {
  db eval {
    CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE, c);
    INSERT INTO t1 VALUES(1,2,3);
    INSERT INTO t1 values(2,'hello','world');
    INSERT INTO t1 VALUES(3,4.53,NULL);
    SELECT * FROM t1
  }
} {1 2 3 2 hello world 3 4.53 {}}
do_test whereA-1.2 {
  db eval {
    PRAGMA reverse_unordered_selects=1;
    SELECT * FROM t1;
  }
} {3 4.53 {} 2 hello world 1 2 3}

do_test whereA-1.3 {
  db close
  sqlite3 db test.db
  db eval {
    PRAGMA reverse_unordered_selects=1;
    SELECT * FROM t1;
  }
} {3 4.53 {} 2 hello world 1 2 3}
do_test whereA-1.4 {
  db close
  sqlite3 db test.db
  db eval {
    PRAGMA reverse_unordered_selects=1;
    SELECT * FROM t1 ORDER BY rowid;
  }
} {1 2 3 2 hello world 3 4.53 {}}
do_test whereA-1.5 {
  db eval {
    VACUUM;
    SELECT * FROM t1 ORDER BY rowid;
  }
} {1 2 3 2 hello world 3 4.53 {}}
do_test whereA-1.6 {
  db eval {
    PRAGMA reverse_unordered_selects;
  }
} {1}
do_test whereA-1.7 {
  db close
  sqlite3 db test.db
  db eval {
    PRAGMA reverse_unordered_selects=1;
    VACUUM;
    SELECT * FROM t1;
  }
} {3 4.53 {} 2 hello world 1 2 3}

do_test whereA-2.1 {
  db eval {
    PRAGMA reverse_unordered_selects=0;
    SELECT * FROM t1 WHERE a>0;
  }
} {1 2 3 2 hello world 3 4.53 {}}
do_test whereA-2.2 {
  db eval {
    PRAGMA reverse_unordered_selects=1;
    SELECT * FROM t1 WHERE a>0;
  }
} {3 4.53 {} 2 hello world 1 2 3}

do_test whereA-2.3 {
  db eval {
    PRAGMA reverse_unordered_selects=1;
    SELECT * FROM t1 WHERE a>0 ORDER BY rowid;
  }
} {1 2 3 2 hello world 3 4.53 {}}

do_test whereA-3.1 {
  db eval {
    PRAGMA reverse_unordered_selects=0;
    SELECT * FROM t1 WHERE b>0;
  }
} {1 2 3 3 4.53 {} 2 hello world}
do_test whereA-3.2 {
  db eval {
    PRAGMA reverse_unordered_selects=1;
    SELECT * FROM t1 WHERE b>0;
  }
} {2 hello world 3 4.53 {} 1 2 3}
do_test whereA-3.3 {
  db eval {
    PRAGMA reverse_unordered_selects=1;
    SELECT * FROM t1 WHERE b>0 ORDER BY b;
  }
} {1 2 3 3 4.53 {} 2 hello world}

do_test whereA-4.1 {
  db eval {
    CREATE TABLE t2(x);
    INSERT INTO t2 VALUES(1);
    INSERT INTO t2 VALUES(2);
    SELECT x FROM t2;
  }
} {2 1}
# Do an SQL statement.  Append the search count to the end of the result.
#
proc count sql {
  set ::sqlite_sort_count 0
  return [concat [execsql $sql] $::sqlite_sort_count]
}
do_test whereA-4.2 {   ;# Ticket #3904
  db eval {
    CREATE INDEX t2x ON t2(x);
  }
  count {
    SELECT x FROM t2;
  }
} {2 1 0}
do_test whereA-4.3 {
  count {
    SELECT x FROM t2 ORDER BY x;
  }
} {1 2 0}
do_test whereA-4.4 {
  count {
    SELECT x FROM t2 ORDER BY x DESC;
  }
} {2 1 0}
do_test whereA-4.5 {
  db eval {DROP INDEX t2x;}
  count {
    SELECT x FROM t2 ORDER BY x;
  }
} {1 2 1}
do_test whereA-4.6 {
  count {
    SELECT x FROM t2 ORDER BY x DESC;
  }
} {2 1 1}


finish_test