sl@0: # 2005 September 17 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. sl@0: # sl@0: # This file implements tests to verify that ticket #1435 has been sl@0: # fixed. sl@0: # sl@0: # sl@0: # $Id: tkt1435.test,v 1.2 2006/01/17 09:35:02 danielk1977 Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable !memorydb { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Construct the sample database. sl@0: # sl@0: do_test tkt1435-1.0 { sl@0: sqlite3 db :memory: sl@0: execsql { sl@0: CREATE TABLE Instances( sl@0: instanceId INTEGER PRIMARY KEY, sl@0: troveName STR, sl@0: versionId INT, sl@0: flavorId INT, sl@0: timeStamps STR, sl@0: isPresent INT, sl@0: pinned BOOLEAN sl@0: ); sl@0: INSERT INTO "Instances" sl@0: VALUES(1, 'libhello:runtime', 1, 1, 1126929880.094, 1, 1); sl@0: INSERT INTO "Instances" sl@0: VALUES(2, 'libhello:user', 1, 1, 1126929880.094, 1, 0); sl@0: INSERT INTO "Instances" sl@0: VALUES(3, 'libhello:script', 1, 1, 1126929880.094, 1, 0); sl@0: INSERT INTO "Instances" sl@0: VALUES(4, 'libhello', 1, 1, 1126929880.094, 1, 0); sl@0: sl@0: CREATE TABLE Versions(versionId INTEGER PRIMARY KEY,version STR UNIQUE); sl@0: INSERT INTO "Versions" VALUES(0, NULL); sl@0: INSERT INTO "Versions" VALUES(1, '/localhost@rpl:linux/0-1-1'); sl@0: sl@0: CREATE TABLE Flavors(flavorId integer primary key, flavor str unique); sl@0: INSERT INTO "Flavors" VALUES(0, NULL); sl@0: INSERT INTO "Flavors" VALUES(1, '1#x86'); sl@0: sl@0: CREATE TEMPORARY TABLE tlList ( sl@0: row INTEGER PRIMARY KEY, sl@0: name STRING, sl@0: version STRING, sl@0: flavor STRING sl@0: ); sl@0: sl@0: INSERT INTO tlList sl@0: values(NULL, 'libhello:script', '/localhost@rpl:linux/0-1-1', '1#x86'); sl@0: INSERT INTO tlList sl@0: values(NULL, 'libhello:user', '/localhost@rpl:linux/0-1-1', '1#x86'); sl@0: INSERT INTO tlList sl@0: values(NULL, 'libhello:runtime', '/localhost@rpl:linux/0-1-1', '1#x86'); sl@0: } sl@0: } {} sl@0: sl@0: # Run the query with an index sl@0: # sl@0: do_test tkt1435-1.1 { sl@0: execsql { sl@0: select row, pinned from tlList, Instances, Versions, Flavors sl@0: where sl@0: Instances.troveName = tlList.name sl@0: and Versions.version = tlList.version sl@0: and Instances.versionId = Versions.versionId sl@0: and ( Flavors.flavor = tlList.flavor or Flavors.flavor is NULL sl@0: and tlList.flavor = '') sl@0: and Instances.flavorId = Flavors.flavorId sl@0: order by row asc; sl@0: } sl@0: } {1 0 2 0 3 1} sl@0: sl@0: # Create a indices, analyze and rerun the query. sl@0: # Verify that the results are the same sl@0: # sl@0: do_test tkt1435-1.2 { sl@0: execsql { sl@0: CREATE INDEX InstancesNameIdx ON Instances(troveName); sl@0: CREATE UNIQUE INDEX InstancesIdx sl@0: ON Instances(troveName, versionId, flavorId); sl@0: ANALYZE; sl@0: select row, pinned from tlList, Instances, Versions, Flavors sl@0: where sl@0: Instances.troveName = tlList.name sl@0: and Versions.version = tlList.version sl@0: and Instances.versionId = Versions.versionId sl@0: and ( Flavors.flavor = tlList.flavor or Flavors.flavor is NULL sl@0: and tlList.flavor = '') sl@0: and Instances.flavorId = Flavors.flavorId sl@0: order by row asc; sl@0: } sl@0: } {1 0 2 0 3 1} sl@0: sl@0: finish_test