sbSQLBuilderBase.cpp
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 #include "sbSQLBuilderBase.h"
28 #include "sbSQLSelectBuilder.h"
29 #include "sbSQLBuilderCriterion.h"
30 
31 #include <nsStringGlue.h>
32 #include <nsCOMPtr.h>
33 
35 
37  mLimit(-1),
38  mLimitIsParameter(PR_FALSE),
39  mOffset(-1),
40  mOffsetIsParameter(PR_FALSE)
41 {
42  MOZ_COUNT_CTOR(sbSQLBuilderBase);
43 }
44 
46 {
47  MOZ_COUNT_DTOR(sbSQLBuilderBase);
48 }
49 
50 NS_IMETHODIMP
51 sbSQLBuilderBase::GetLimit(PRInt32 *aLimit)
52 {
53  *aLimit = mLimit;
54  return NS_OK;
55 }
56 NS_IMETHODIMP
57 sbSQLBuilderBase::SetLimit(PRInt32 aLimit)
58 {
59  mLimit = aLimit;
60  return NS_OK;
61 }
62 
63 NS_IMETHODIMP
64 sbSQLBuilderBase::GetLimitIsParameter(PRBool *aLimitIsParameter)
65 {
66  *aLimitIsParameter = mLimitIsParameter;
67  return NS_OK;
68 }
69 NS_IMETHODIMP
70 sbSQLBuilderBase::SetLimitIsParameter(PRBool aLimitIsParameter)
71 {
72  mLimitIsParameter = aLimitIsParameter;
73  return NS_OK;
74 }
75 
76 NS_IMETHODIMP
77 sbSQLBuilderBase::GetOffset(PRInt32 *aOffset)
78 {
79  *aOffset = mOffset;
80  return NS_OK;
81 }
82 NS_IMETHODIMP
83 sbSQLBuilderBase::SetOffset(PRInt32 aOffset)
84 {
85  mOffset = aOffset;
86  return NS_OK;
87 }
88 
89 NS_IMETHODIMP
90 sbSQLBuilderBase::GetOffsetIsParameter(PRBool *aOffsetIsParameter)
91 {
92  *aOffsetIsParameter = mOffsetIsParameter;
93  return NS_OK;
94 }
95 NS_IMETHODIMP
96 sbSQLBuilderBase::SetOffsetIsParameter(PRBool aOffsetIsParameter)
97 {
98  mOffsetIsParameter = aOffsetIsParameter;
99  return NS_OK;
100 }
101 
102 NS_IMETHODIMP
103 sbSQLBuilderBase::AddJoin(PRUint32 aJoinType,
104  const nsAString& aJoinedTableName,
105  const nsAString& aJoinedTableAlias,
106  const nsAString& aJoinedColumnName,
107  const nsAString& aJoinToTableName,
108  const nsAString& aJoinToColumnName)
109 {
110  sbJoinInfo* ji = mJoins.AppendElement();
111  NS_ENSURE_TRUE(ji, NS_ERROR_OUT_OF_MEMORY);
112 
113  ji->type = aJoinType;
114  ji->joinedTableName = aJoinedTableName;
115  ji->joinedTableAlias = aJoinedTableAlias;
116  ji->joinedColumnName = aJoinedColumnName;
117  ji->joinToTableName = aJoinToTableName;
118  ji->joinToColumnName = aJoinToColumnName;
119  ji->criterion = nsnull;
120  ji->subquery = nsnull;
121  ji->requiresJoinFromIndexUsageFix = PR_FALSE;
122  ji->requiresJoinToIndexUsageFix = PR_FALSE;
123 
124  return NS_OK;
125 }
126 
127 NS_IMETHODIMP
128 sbSQLBuilderBase::AddJoinWithIndexHint(PRUint32 aJoinType,
129  const nsAString& aJoinedTableName,
130  const nsAString& aJoinedTableAlias,
131  const nsAString& aJoinedColumnName,
132  const nsAString& aJoinToTableName,
133  const nsAString& aJoinToColumnName,
134  PRBool aRequiresFromTableIndexHint,
135  PRBool aRequiresToTableIndexHint)
136 {
137  sbJoinInfo* ji = mJoins.AppendElement();
138  NS_ENSURE_TRUE(ji, NS_ERROR_OUT_OF_MEMORY);
139 
140  ji->type = aJoinType;
141  ji->joinedTableName = aJoinedTableName;
142  ji->joinedTableAlias = aJoinedTableAlias;
143  ji->joinedColumnName = aJoinedColumnName;
144  ji->joinToTableName = aJoinToTableName;
145  ji->joinToColumnName = aJoinToColumnName;
146  ji->criterion = nsnull;
147  ji->subquery = nsnull;
148  ji->requiresJoinFromIndexUsageFix = aRequiresFromTableIndexHint;
149  ji->requiresJoinToIndexUsageFix = aRequiresToTableIndexHint;
150 
151  return NS_OK;
152 }
153 
154 NS_IMETHODIMP
155 sbSQLBuilderBase::AddSubqueryJoin(PRUint32 aJoinType,
156  sbISQLSelectBuilder* aJoinedSubquery,
157  const nsAString& aJoinedTableAlias,
158  const nsAString& aJoinedColumnName,
159  const nsAString& aJoinToTableName,
160  const nsAString& aJoinToColumnName)
161 {
162  NS_ENSURE_ARG_POINTER(aJoinedSubquery);
163 
164  sbJoinInfo* ji = mJoins.AppendElement();
165  NS_ENSURE_TRUE(ji, NS_ERROR_OUT_OF_MEMORY);
166 
167  ji->type = aJoinType;
168  ji->joinedTableName = EmptyString();
169  ji->joinedTableAlias = aJoinedTableAlias;
170  ji->joinedColumnName = aJoinedColumnName;
171  ji->joinToTableName = aJoinToTableName;
172  ji->joinToColumnName = aJoinToColumnName;
173  ji->criterion = nsnull;
174  ji->subquery = aJoinedSubquery;
175  ji->requiresJoinFromIndexUsageFix = PR_FALSE;
176  ji->requiresJoinToIndexUsageFix = PR_FALSE;
177 
178  return NS_OK;
179 }
180 
181 NS_IMETHODIMP
182 sbSQLBuilderBase::AddJoinWithCriterion(PRUint32 aJoinType,
183  const nsAString& aJoinedTableName,
184  const nsAString& aJoinedTableAlias,
185  sbISQLBuilderCriterion *aCriterion)
186 {
187  sbJoinInfo* ji = mJoins.AppendElement();
188  NS_ENSURE_TRUE(ji, NS_ERROR_OUT_OF_MEMORY);
189 
190  ji->type = aJoinType;
191  ji->joinedTableName = aJoinedTableName;
192  ji->joinedTableAlias = aJoinedTableAlias;
193  ji->joinedColumnName = EmptyString();
194  ji->joinToTableName = EmptyString();
195  ji->joinToColumnName = EmptyString();
196  ji->criterion = aCriterion;
197  ji->subquery = nsnull;
198  ji->requiresJoinFromIndexUsageFix = PR_FALSE;
199  ji->requiresJoinToIndexUsageFix = PR_FALSE;
200 
201  return NS_OK;
202 }
203 
204 NS_IMETHODIMP
205 sbSQLBuilderBase::AddSubquery(sbISQLSelectBuilder *aSubquery,
206  const nsAString& aAlias)
207 {
208  NS_ENSURE_ARG_POINTER(aSubquery);
209 
210  // Don't allow a query to use itself as a subquery
211  // XXX: This is bad since it assumes the implementation class of the
212  // aSubquery parameter. What is the right way to do this?
213  sbSQLSelectBuilder* sb = static_cast<sbSQLSelectBuilder*>(aSubquery);
214  NS_ENSURE_TRUE(sb != this, NS_ERROR_INVALID_ARG);
215 
216  sbSubqueryInfo* sq = mSubqueries.AppendElement();
217  NS_ENSURE_TRUE(sq, NS_ERROR_OUT_OF_MEMORY);
218 
219  sq->subquery = aSubquery;
220  sq->alias = aAlias;
221 
222  return NS_OK;
223 }
224 
225 NS_IMETHODIMP
226 sbSQLBuilderBase::Reset()
227 {
228  mLimit = -1;
229  mLimitIsParameter = PR_FALSE;
230  mOffset = -1;
231  mOffsetIsParameter = PR_FALSE;
232  mJoins.Clear();
233  mSubqueries.Clear();
234  return NS_OK;
235 }
236 
237 NS_IMETHODIMP
238 sbSQLBuilderBase::ToString(nsAString& _retval)
239 {
240  // not meant to be implemented by base class
241  return NS_ERROR_NOT_IMPLEMENTED;
242 }
243 
nsTArray< sbSubqueryInfo > mSubqueries
virtual ~sbSQLBuilderBase()
return NS_OK
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
static nsresult ToString(const nsDiscriminatedUnion &data, nsACString &outString)
Definition: sbVariant.cpp:861
Interface for building SELECT statements.
Base interface for SQL building components.
Interface for SQL critera. This interface has no public methods as it is used only as a return type f...
nsTArray< sbJoinInfo > mJoins