47 sbSQLSelectBuilder::GetBaseTableName(nsAString& aBaseTableName)
49 aBaseTableName.Assign(mBaseTableName);
53 sbSQLSelectBuilder::SetBaseTableName(
const nsAString& aBaseTableName)
55 mBaseTableName.Assign(aBaseTableName);
60 sbSQLSelectBuilder::GetBaseTableAlias(nsAString& aBaseTableAlias)
62 aBaseTableAlias.Assign(mBaseTableAlias);
66 sbSQLSelectBuilder::SetBaseTableAlias(
const nsAString& aBaseTableAlias)
68 mBaseTableAlias.Assign(aBaseTableAlias);
73 sbSQLSelectBuilder::GetDistinct(PRBool *aDistinct)
75 *aDistinct = mIsDistinct;
79 sbSQLSelectBuilder::SetDistinct(PRBool aDistinct)
81 mIsDistinct = aDistinct;
86 sbSQLSelectBuilder::AddColumn(
const nsAString& aTableName,
87 const nsAString& aColumnName)
89 sbColumnInfo* ci = mOutputColumns.AppendElement();
90 NS_ENSURE_TRUE(ci, NS_ERROR_OUT_OF_MEMORY);
92 ci->tableName = aTableName;
93 ci->columnName = aColumnName;
99 sbSQLSelectBuilder::ClearColumns()
101 mOutputColumns.Clear();
107 sbSQLSelectBuilder::AddOrder(
const nsAString& aTableName,
108 const nsAString& aColumnName,
111 sbOrderInfo* oi = mOrders.AppendElement();
112 NS_ENSURE_TRUE(oi, NS_ERROR_OUT_OF_MEMORY);
114 oi->tableName = aTableName;
115 oi->columnName = aColumnName;
116 oi->ascending = aAscending;
117 oi->random = PR_FALSE;
123 sbSQLSelectBuilder::AddRandomOrder()
125 sbOrderInfo* oi = mOrders.AppendElement();
126 NS_ENSURE_TRUE(oi, NS_ERROR_OUT_OF_MEMORY);
128 oi->random = PR_TRUE;
129 oi->ascending = PR_FALSE;
135 sbSQLSelectBuilder::AddGroupBy(
const nsAString& aTableName,
136 const nsAString& aColumnName)
138 sbGroupInfo* gi = mGroups.AppendElement();
139 NS_ENSURE_TRUE(gi, NS_ERROR_OUT_OF_MEMORY);
141 gi->tableName = aTableName;
142 gi->columnName = aColumnName;
151 mBaseTableName.Truncate();
152 mBaseTableAlias.Truncate();
153 mIsDistinct = PR_FALSE;
154 mOutputColumns.Clear();
168 buff.AssignLiteral(
"select ");
171 buff.AppendLiteral(
"distinct ");
175 PRUint32 len = mOutputColumns.Length();
176 for (PRUint32
i = 0;
i < len;
i++) {
180 buff.AppendLiteral(
".");
184 buff.AppendLiteral(
", ");
189 buff.AppendLiteral(
" from ");
190 buff.Append(mBaseTableName);
191 if (!mBaseTableAlias.IsEmpty()) {
192 buff.AppendLiteral(
" as ");
193 buff.Append(mBaseTableAlias);
197 for (PRUint32
i = 0;
i < len;
i++) {
199 buff.AppendLiteral(
", ( ");
203 buff.AppendLiteral(
" )");
204 if (!sq.
alias.IsEmpty()) {
205 buff.AppendLiteral(
" as ");
206 buff.Append(sq.
alias);
211 for (PRUint32
i = 0;
i < len;
i++) {
218 buff.AppendLiteral(
" left");
221 buff.AppendLiteral(
" left outer");
224 NS_NOTREACHED(
"Unknown Join Type");
226 buff.AppendLiteral(
" join ");
228 buff.AppendLiteral(
"(");
232 buff.AppendLiteral(
")");
238 buff.AppendLiteral(
" as ");
241 buff.AppendLiteral(
" on ");
249 buff.AppendLiteral(
"+");
252 buff.AppendLiteral(
".");
254 buff.AppendLiteral(
" = ");
256 buff.AppendLiteral(
"+");
260 buff.AppendLiteral(
".");
265 buff.AppendLiteral(
".");
273 NS_ENSURE_SUCCESS(rv, rv);
276 len = mGroups.Length();
278 buff.AppendLiteral(
" group by ");
279 for (PRUint32
i = 0;
i < len;
i++) {
280 const sbGroupInfo& gi = mGroups[
i];
281 if (!gi.tableName.IsEmpty()) {
282 buff.Append(gi.tableName);
283 buff.AppendLiteral(
".");
285 buff.Append(gi.columnName);
287 buff.AppendLiteral(
", ");
293 len = mOrders.Length();
295 buff.AppendLiteral(
" order by ");
296 for (PRUint32
i = 0;
i < len;
i++) {
297 const sbOrderInfo& oi = mOrders[
i];
299 buff.AppendLiteral(
"random()");
301 if (!oi.tableName.IsEmpty()) {
302 buff.Append(oi.tableName);
303 buff.AppendLiteral(
".");
305 buff.Append(oi.columnName);
307 buff.AppendLiteral(
" asc");
310 buff.AppendLiteral(
" desc");
314 buff.AppendLiteral(
", ");
321 buff.AppendLiteral(
" limit ");
323 buff.AppendLiteral(
"?");
331 buff.AppendLiteral(
" offset ");
333 buff.AppendLiteral(
"?");
340 _retval.Assign(buff);
nsTArray< sbSubqueryInfo > mSubqueries
PRPackedBool requiresJoinFromIndexUsageFix
nsCOMPtr< sbISQLSelectBuilder > subquery
nsresult AppendWhere(nsAString &aBuffer)
NS_DECL_SBISQLSELECTBUILDER NS_IMETHOD ToString(nsAString &_result)
nsString joinedColumnName
Interface for building SELECT statements.
nsString joinToColumnName
const unsigned long JOIN_LEFT_OUTER
nsString joinedTableAlias
const unsigned long JOIN_INNER
virtual ~sbSQLSelectBuilder()
nsCOMPtr< sbISQLSelectBuilder > subquery
const unsigned long JOIN_LEFT
nsTArray< sbJoinInfo > mJoins
PRPackedBool requiresJoinToIndexUsageFix
nsCOMPtr< sbISQLBuilderCriterion > criterion
PRBool mOffsetIsParameter
_getSelectedPageStyle s i
NS_IMPL_ISUPPORTS_INHERITED1(sbSQLSelectBuilder, sbSQLWhereBuilder, sbISQLSelectBuilder) sbSQLSelectBuilder