test_select.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
31 function runTest () {
32 
33  var sql;
34  var q;
35  var c, c1, c2, c3;
36 
37  /*
38  * Tests taken from http://sqlzoo.net/1.htm
39  */
40 
41  q = newQuery();
42  q.baseTableName = "bbc"
43  q.addColumn(null, "name");
44  q.addColumn(null, "region");
45  q.addColumn(null, "population");
46  sql = "select name, region, population from bbc";
47  assertEqual(sql, q.toString());
48 
49  q = newQuery();
50  q.baseTableName = "bbc"
51  q.addColumn(null, "name");
52  c = q.createMatchCriterionLong(null, "population",
53  Ci.sbISQLBuilder.MATCH_GREATEREQUAL,
54  200000000);
55  q.addCriterion(c);
56  sql = "select name from bbc where population >= 200000000";
57  assertEqual(sql, q.toString());
58 
59  q = newQuery();
60  q.baseTableName = "bbc"
61  q.addColumn(null, "name");
62  q.addColumn(null, "gdp / population");
63  c = q.createMatchCriterionLong(null, "population",
64  Ci.sbISQLBuilder.MATCH_GREATEREQUAL,
65  200000000);
66  q.addCriterion(c);
67  sql = "select name, gdp / population from bbc where population >= 200000000";
68  assertEqual(sql, q.toString());
69 
70  q = newQuery();
71  q.baseTableName = "bbc"
72  q.addColumn(null, "name");
73  q.addColumn(null, "round(population / 1000000)");
74  c = q.createMatchCriterionString(null, "region",
75  Ci.sbISQLBuilder.MATCH_EQUALS,
76  "South Asia");
77  q.addCriterion(c);
78  sql = "select name, round(population / 1000000) from bbc where region = 'South Asia'";
79  assertEqual(sql, q.toString());
80 
81  q = newQuery();
82  q.baseTableName = "bbc"
83  q.addColumn(null, "name");
84  q.addColumn(null, "population");
85  c1 = q.createMatchCriterionString(null, "name",
86  Ci.sbISQLBuilder.MATCH_EQUALS,
87  "France");
88  c2 = q.createMatchCriterionString(null, "name",
89  Ci.sbISQLBuilder.MATCH_EQUALS,
90  "Germany");
91  c3 = q.createMatchCriterionString(null, "name",
92  Ci.sbISQLBuilder.MATCH_EQUALS,
93  "Italy");
94  c = q.createOrCriterion(c1, c2);
95  c = q.createOrCriterion(c, c3);
96  q.addCriterion(c);
97  sql = "select name, population from bbc where ((name = 'France' or name = 'Germany') or name = 'Italy')"
98  assertEqual(sql, q.toString());
99 
100  q = newQuery();
101  q.baseTableName = "bbc"
102  q.addColumn(null, "name");
103  c = q.createMatchCriterionString(null, "name",
104  Ci.sbISQLBuilder.MATCH_LIKE,
105  "%United%");
106  q.addCriterion(c);
107  sql = "select name from bbc where name like '%United%' ESCAPE '\\'";
108  assertEqual(sql, q.toString());
109 
110  // An additional test not taken from the same source, for > 32 bit values
111  q = newQuery();
112  q.baseTableName = "bbc"
113  q.addColumn(null, "name");
114  c = q.createMatchCriterionLongLong(null, "population",
115  Ci.sbISQLBuilder.MATCH_GREATEREQUAL,
116  20000000000);
117  q.addCriterion(c);
118  sql = "select name from bbc where population >= 20000000000";
119  assertEqual(sql, q.toString());
120 
121  return Components.results.NS_OK;
122 
123 }
124 
125 function newQuery() {
126  return Cc["@songbirdnest.com/Songbird/SQLBuilder/Select;1"]
127  .createInstance(Ci.sbISQLSelectBuilder);
128 }
129 
const Cc
function newQuery()
Definition: test_select.js:125
function assertEqual(aExpected, aActual, aMessage)
function runTest()
Test file.
Definition: test_select.js:31
return null
Definition: FeedWriter.js:1143
const Ci