sbLocalDatabaseQuery.h
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 
27 #ifndef __SBLOCALDATABASEQUERY_H__
28 #define __SBLOCALDATABASEQUERY_H__
29 
30 #include <nsClassHashtable.h>
31 #include <nsCOMPtr.h>
32 #include <nsStringGlue.h>
33 #include "sbLocalDatabaseGUIDArray.h" // for FilterSpec
34 
35 class sbIDatabaseQuery;
37 class sbISQLBuilder;
38 
40 {
41  typedef nsTArray<PRUint32> sbUint32Array;
42 
43 public:
44  explicit
45  sbLocalDatabaseQuery(const nsAString& aBaseTable,
46  const nsAString& aBaseConstraintColumn,
47  PRUint32 aBaseConstraintValue,
48  const nsAString& aBaseForeignKeyColumn,
49  nsTArray<sbLocalDatabaseGUIDArray::FilterSpec>* aFilters,
50  nsTArray<sbLocalDatabaseGUIDArray::SortSpec>* aSorts,
51  PRBool aIsDistinct,
52  PRBool aDistinctWithSortableValues,
53  sbILocalDatabasePropertyCache* aPropertyCache);
54 
55  nsresult GetFullCountQuery(nsAString& aQuery);
56  nsresult GetFullGuidRangeQuery(nsAString& aQuery);
57  nsresult GetNonNullCountQuery(nsAString& aQuery);
58  nsresult GetNullGuidRangeQuery(nsAString& aQuery);
59  nsresult GetPrefixSearchQuery(nsAString& aQuery);
60  nsresult GetResortQuery(nsAString& aQuery);
61  nsresult GetNullResortQuery(nsAString& aQuery);
62  PRBool GetIsFullLibrary();
63 
64 private:
65  struct sbAddJoinInfo {
66  sbAddJoinInfo(sbISQLSelectBuilder* aBuilder) :
67  joinCounter(0),
68  builder(aBuilder)
69  {
70  NS_ASSERTION(aBuilder, "aBuilder is null");
71  };
72 
73  PRUint32 joinCounter;
74  nsCOMPtr<sbISQLSelectBuilder> builder;
75  nsCOMPtr<sbISQLBuilderCriterion> criterion;
76  nsString match;
77  };
78 
79  nsresult AddCountColumns();
80  nsresult AddGuidColumns(PRBool aIsNull);
81  nsresult AddBaseTable();
82  nsresult AddFilters();
83  nsresult AddRange();
84  nsresult AddPrimarySort();
85  nsresult AddNonNullPrimarySortConstraint();
86  nsresult AddJoinToGetNulls();
87  nsresult AddDistinctConstraint();
88  nsresult AddDistinctGroupBy();
89  nsresult AddResortColumns();
90  nsresult AddMultiSorts();
91 
92  PRInt32 GetPropertyId(const nsAString& aProperty);
93 
94  static void MaxExpr(const nsAString& aAlias,
95  const nsAString& aColumn,
96  nsAString& aExpr);
97 
98  nsString mBaseTable;
99  nsString mBaseConstraintColumn;
100  PRUint32 mBaseConstraintValue;
101  nsString mBaseForeignKeyColumn;
102  nsTArray<sbLocalDatabaseGUIDArray::FilterSpec>* mFilters;
103  nsTArray<sbLocalDatabaseGUIDArray::SortSpec>* mSorts;
104  PRPackedBool mIsDistinct;
105  PRPackedBool mDistinctWithSortableValues;
106 
107  nsCOMPtr<sbISQLSelectBuilder> mBuilder;
108  PRBool mIsFullLibrary;
109  nsCOMPtr<sbILocalDatabasePropertyCache> mPropertyCache;
110  PRBool mHasSearch;
111 };
112 
113 #endif /* __SBLOCALDATABASEQUERY_H__ */
nsresult GetNullResortQuery(nsAString &aQuery)
nsresult GetFullGuidRangeQuery(nsAString &aQuery)
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
nsresult GetResortQuery(nsAString &aQuery)
nsresult GetFullCountQuery(nsAString &aQuery)
nsresult GetNonNullCountQuery(nsAString &aQuery)
nsresult GetNullGuidRangeQuery(nsAString &aQuery)
sbLocalDatabaseQuery(const nsAString &aBaseTable, const nsAString &aBaseConstraintColumn, PRUint32 aBaseConstraintValue, const nsAString &aBaseForeignKeyColumn, nsTArray< sbLocalDatabaseGUIDArray::FilterSpec > *aFilters, nsTArray< sbLocalDatabaseGUIDArray::SortSpec > *aSorts, PRBool aIsDistinct, PRBool aDistinctWithSortableValues, sbILocalDatabasePropertyCache *aPropertyCache)
Interface for building SELECT statements.
Base interface for SQL building components.
ExtensionSchemeMatcher prototype match
An object responsible for executing SQL queries on the database.
nsresult GetPrefixSearchQuery(nsAString &aQuery)