sl@0
|
1 |
# 2005 September 17
|
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 to verify that ticket #1435 has been
|
sl@0
|
14 |
# fixed.
|
sl@0
|
15 |
#
|
sl@0
|
16 |
#
|
sl@0
|
17 |
# $Id: tkt1435.test,v 1.2 2006/01/17 09:35:02 danielk1977 Exp $
|
sl@0
|
18 |
|
sl@0
|
19 |
set testdir [file dirname $argv0]
|
sl@0
|
20 |
source $testdir/tester.tcl
|
sl@0
|
21 |
|
sl@0
|
22 |
ifcapable !memorydb {
|
sl@0
|
23 |
finish_test
|
sl@0
|
24 |
return
|
sl@0
|
25 |
}
|
sl@0
|
26 |
|
sl@0
|
27 |
# Construct the sample database.
|
sl@0
|
28 |
#
|
sl@0
|
29 |
do_test tkt1435-1.0 {
|
sl@0
|
30 |
sqlite3 db :memory:
|
sl@0
|
31 |
execsql {
|
sl@0
|
32 |
CREATE TABLE Instances(
|
sl@0
|
33 |
instanceId INTEGER PRIMARY KEY,
|
sl@0
|
34 |
troveName STR,
|
sl@0
|
35 |
versionId INT,
|
sl@0
|
36 |
flavorId INT,
|
sl@0
|
37 |
timeStamps STR,
|
sl@0
|
38 |
isPresent INT,
|
sl@0
|
39 |
pinned BOOLEAN
|
sl@0
|
40 |
);
|
sl@0
|
41 |
INSERT INTO "Instances"
|
sl@0
|
42 |
VALUES(1, 'libhello:runtime', 1, 1, 1126929880.094, 1, 1);
|
sl@0
|
43 |
INSERT INTO "Instances"
|
sl@0
|
44 |
VALUES(2, 'libhello:user', 1, 1, 1126929880.094, 1, 0);
|
sl@0
|
45 |
INSERT INTO "Instances"
|
sl@0
|
46 |
VALUES(3, 'libhello:script', 1, 1, 1126929880.094, 1, 0);
|
sl@0
|
47 |
INSERT INTO "Instances"
|
sl@0
|
48 |
VALUES(4, 'libhello', 1, 1, 1126929880.094, 1, 0);
|
sl@0
|
49 |
|
sl@0
|
50 |
CREATE TABLE Versions(versionId INTEGER PRIMARY KEY,version STR UNIQUE);
|
sl@0
|
51 |
INSERT INTO "Versions" VALUES(0, NULL);
|
sl@0
|
52 |
INSERT INTO "Versions" VALUES(1, '/localhost@rpl:linux/0-1-1');
|
sl@0
|
53 |
|
sl@0
|
54 |
CREATE TABLE Flavors(flavorId integer primary key, flavor str unique);
|
sl@0
|
55 |
INSERT INTO "Flavors" VALUES(0, NULL);
|
sl@0
|
56 |
INSERT INTO "Flavors" VALUES(1, '1#x86');
|
sl@0
|
57 |
|
sl@0
|
58 |
CREATE TEMPORARY TABLE tlList (
|
sl@0
|
59 |
row INTEGER PRIMARY KEY,
|
sl@0
|
60 |
name STRING,
|
sl@0
|
61 |
version STRING,
|
sl@0
|
62 |
flavor STRING
|
sl@0
|
63 |
);
|
sl@0
|
64 |
|
sl@0
|
65 |
INSERT INTO tlList
|
sl@0
|
66 |
values(NULL, 'libhello:script', '/localhost@rpl:linux/0-1-1', '1#x86');
|
sl@0
|
67 |
INSERT INTO tlList
|
sl@0
|
68 |
values(NULL, 'libhello:user', '/localhost@rpl:linux/0-1-1', '1#x86');
|
sl@0
|
69 |
INSERT INTO tlList
|
sl@0
|
70 |
values(NULL, 'libhello:runtime', '/localhost@rpl:linux/0-1-1', '1#x86');
|
sl@0
|
71 |
}
|
sl@0
|
72 |
} {}
|
sl@0
|
73 |
|
sl@0
|
74 |
# Run the query with an index
|
sl@0
|
75 |
#
|
sl@0
|
76 |
do_test tkt1435-1.1 {
|
sl@0
|
77 |
execsql {
|
sl@0
|
78 |
select row, pinned from tlList, Instances, Versions, Flavors
|
sl@0
|
79 |
where
|
sl@0
|
80 |
Instances.troveName = tlList.name
|
sl@0
|
81 |
and Versions.version = tlList.version
|
sl@0
|
82 |
and Instances.versionId = Versions.versionId
|
sl@0
|
83 |
and ( Flavors.flavor = tlList.flavor or Flavors.flavor is NULL
|
sl@0
|
84 |
and tlList.flavor = '')
|
sl@0
|
85 |
and Instances.flavorId = Flavors.flavorId
|
sl@0
|
86 |
order by row asc;
|
sl@0
|
87 |
}
|
sl@0
|
88 |
} {1 0 2 0 3 1}
|
sl@0
|
89 |
|
sl@0
|
90 |
# Create a indices, analyze and rerun the query.
|
sl@0
|
91 |
# Verify that the results are the same
|
sl@0
|
92 |
#
|
sl@0
|
93 |
do_test tkt1435-1.2 {
|
sl@0
|
94 |
execsql {
|
sl@0
|
95 |
CREATE INDEX InstancesNameIdx ON Instances(troveName);
|
sl@0
|
96 |
CREATE UNIQUE INDEX InstancesIdx
|
sl@0
|
97 |
ON Instances(troveName, versionId, flavorId);
|
sl@0
|
98 |
ANALYZE;
|
sl@0
|
99 |
select row, pinned from tlList, Instances, Versions, Flavors
|
sl@0
|
100 |
where
|
sl@0
|
101 |
Instances.troveName = tlList.name
|
sl@0
|
102 |
and Versions.version = tlList.version
|
sl@0
|
103 |
and Instances.versionId = Versions.versionId
|
sl@0
|
104 |
and ( Flavors.flavor = tlList.flavor or Flavors.flavor is NULL
|
sl@0
|
105 |
and tlList.flavor = '')
|
sl@0
|
106 |
and Instances.flavorId = Flavors.flavorId
|
sl@0
|
107 |
order by row asc;
|
sl@0
|
108 |
}
|
sl@0
|
109 |
} {1 0 2 0 3 1}
|
sl@0
|
110 |
|
sl@0
|
111 |
finish_test
|