AryaWu/sqlite
0
1# 2005 September 172#3# The author disclaims copyright to this source code. In place of4# a legal notice, here is a blessing:5#6# May you do good and not evil.7# May you find forgiveness for yourself and forgive others.8# May you share freely, never taking more than you give.9#10#***********************************************************************11# This file implements regression tests for SQLite library.12#13# This file implements tests to verify that ticket #1435 has been14# fixed. 15#16#17# $Id: tkt1435.test,v 1.2 2006/01/17 09:35:02 danielk1977 Exp $18 19set testdir [file dirname $argv0]20source $testdir/tester.tcl21 22ifcapable !memorydb {23 finish_test24 return25}26 27# Construct the sample database.28#29do_test tkt1435-1.0 {30 sqlite3 db :memory:31 execsql {32 CREATE TABLE Instances(33 instanceId INTEGER PRIMARY KEY,34 troveName STR,35 versionId INT,36 flavorId INT,37 timeStamps STR,38 isPresent INT,39 pinned BOOLEAN40 );41 INSERT INTO "Instances"42 VALUES(1, 'libhello:runtime', 1, 1, 1126929880.094, 1, 1);43 INSERT INTO "Instances"44 VALUES(2, 'libhello:user', 1, 1, 1126929880.094, 1, 0);45 INSERT INTO "Instances"46 VALUES(3, 'libhello:script', 1, 1, 1126929880.094, 1, 0);47 INSERT INTO "Instances"48 VALUES(4, 'libhello', 1, 1, 1126929880.094, 1, 0);49 50 CREATE TABLE Versions(versionId INTEGER PRIMARY KEY,version STR UNIQUE);51 INSERT INTO "Versions" VALUES(0, NULL);52 INSERT INTO "Versions" VALUES(1, '/localhost@rpl:linux/0-1-1');53 54 CREATE TABLE Flavors(flavorId integer primary key, flavor str unique);55 INSERT INTO "Flavors" VALUES(0, NULL);56 INSERT INTO "Flavors" VALUES(1, '1#x86');57 58 CREATE TEMPORARY TABLE tlList (59 row INTEGER PRIMARY KEY,60 name STRING,61 version STRING,62 flavor STRING63 );64 65 INSERT INTO tlList 66 values(NULL, 'libhello:script', '/localhost@rpl:linux/0-1-1', '1#x86');67 INSERT INTO tlList 68 values(NULL, 'libhello:user', '/localhost@rpl:linux/0-1-1', '1#x86');69 INSERT INTO tlList 70 values(NULL, 'libhello:runtime', '/localhost@rpl:linux/0-1-1', '1#x86');71 }72} {}73 74# Run the query with an index75#76do_test tkt1435-1.1 {77 execsql {78 select row, pinned from tlList, Instances, Versions, Flavors79 where80 Instances.troveName = tlList.name81 and Versions.version = tlList.version82 and Instances.versionId = Versions.versionId83 and ( Flavors.flavor = tlList.flavor or Flavors.flavor is NULL84 and tlList.flavor = '')85 and Instances.flavorId = Flavors.flavorId86 order by row asc;87 }88} {1 0 2 0 3 1}89 90# Create a indices, analyze and rerun the query. 91# Verify that the results are the same92#93do_test tkt1435-1.2 {94 execsql {95 CREATE INDEX InstancesNameIdx ON Instances(troveName);96 CREATE UNIQUE INDEX InstancesIdx 97 ON Instances(troveName, versionId, flavorId);98 ANALYZE;99 select row, pinned from tlList, Instances, Versions, Flavors100 where101 Instances.troveName = tlList.name102 and Versions.version = tlList.version103 and Instances.versionId = Versions.versionId104 and ( Flavors.flavor = tlList.flavor or Flavors.flavor is NULL105 and tlList.flavor = '')106 and Instances.flavorId = Flavors.flavorId107 order by row asc;108 }109} {1 0 2 0 3 1}110 111finish_test112 