tkt1435.test 3.3 KB

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