31 #include <sbIDatabaseQuery.h>
32 #include <sbIDatabaseResult.h>
33 #include <sbILocalDatabasePropertyCache.h>
34 #include <sbISQLBuilder.h>
36 #include <nsComponentManagerUtils.h>
41 #define COUNT_COLUMN NS_LITERAL_STRING("count(1)")
42 #define CREATED_COLUMN NS_LITERAL_STRING("created")
43 #define GUID_COLUMN NS_LITERAL_STRING("guid")
44 #define OBJ_COLUMN NS_LITERAL_STRING("obj")
45 #define OBJSORTABLE_COLUMN NS_LITERAL_STRING("obj_sortable")
46 #define OBJSECONDARYSORTABLE_COLUMN NS_LITERAL_STRING("obj_secondary_sortable")
47 #define MEDIAITEMID_COLUMN NS_LITERAL_STRING("media_item_id")
48 #define PROPERTYID_COLUMN NS_LITERAL_STRING("property_id")
49 #define ORDINAL_COLUMN NS_LITERAL_STRING("ordinal")
50 #define PROPERTYNAME_COLUMN NS_LITERAL_STRING("property_name")
51 #define MEDIALISTYPEID_COLUMN NS_LITERAL_STRING("media_list_type_id")
52 #define ISLIST_COLUMN NS_LITERAL_STRING("is_list")
53 #define ROWID_COLUMN NS_LITERAL_STRING("rowid")
55 #define PROPERTIES_TABLE NS_LITERAL_STRING("resource_properties")
56 #define PROPERTIES_FTS_TABLE NS_LITERAL_STRING("resource_properties_fts")
57 #define PROPERTIES_FTS_ALL_TABLE NS_LITERAL_STRING("resource_properties_fts_all")
58 #define MEDIAITEMS_TABLE NS_LITERAL_STRING("media_items")
59 #define SIMPLEMEDIALISTS_TABLE NS_LITERAL_STRING("simple_media_lists")
60 #define PROPERTYIDS_TABLE NS_LITERAL_STRING("properties")
62 #define MEDIAITEMS_ALIAS NS_LITERAL_STRING("_mi")
63 #define CONSTRAINT_ALIAS NS_LITERAL_STRING("_con")
64 #define GETNOTNULL_ALIAS NS_LITERAL_STRING("_getnotnull")
65 #define GETNULL_ALIAS NS_LITERAL_STRING("_getnull")
66 #define SORT_ALIAS NS_LITERAL_STRING("_sort")
67 #define DISTINCT_ALIAS NS_LITERAL_STRING("_d")
68 #define CONPROP_ALIAS NS_LITERAL_STRING("_conprop")
70 #define ORDINAL_PROPERTY NS_LITERAL_STRING(SB_PROPERTY_ORDINAL)
71 #define ISLIST_PROPERTY NS_LITERAL_STRING(SB_PROPERTY_ISLIST)
74 const nsAString& aBaseConstraintColumn,
75 PRUint32 aBaseConstraintValue,
76 const nsAString& aBaseForeignKeyColumn,
77 nsTArray<sbLocalDatabaseGUIDArray::FilterSpec>* aFilters,
78 nsTArray<sbLocalDatabaseGUIDArray::SortSpec>* aSorts,
80 PRBool aDistinctWithSortableValues,
82 mBaseTable(aBaseTable),
83 mBaseConstraintColumn(aBaseConstraintColumn),
84 mBaseConstraintValue(aBaseConstraintValue),
85 mBaseForeignKeyColumn(aBaseForeignKeyColumn),
88 mIsDistinct(aIsDistinct),
89 mDistinctWithSortableValues(aDistinctWithSortableValues),
90 mPropertyCache(aPropertyCache),
96 NS_ASSERTION(mBuilder,
"Could not create builder");
101 PRUint32 len = mFilters->Length();
102 for (PRUint32
i = 0;
i < len;
i++) {
103 if (mFilters->ElementAt(
i).isSearch) {
104 mHasSearch = PR_TRUE;
116 rv = mBuilder->Reset();
117 NS_ENSURE_SUCCESS(rv, rv);
119 rv = AddCountColumns();
120 NS_ENSURE_SUCCESS(rv, rv);
123 NS_ENSURE_SUCCESS(rv, rv);
126 rv = AddDistinctConstraint();
127 NS_ENSURE_SUCCESS(rv, rv);
131 NS_ENSURE_SUCCESS(rv, rv);
133 rv = mBuilder->ToString(aQuery);
134 NS_ENSURE_SUCCESS(rv, rv);
144 rv = mBuilder->Reset();
145 NS_ENSURE_SUCCESS(rv, rv);
147 rv = AddGuidColumns(PR_FALSE);
148 NS_ENSURE_SUCCESS(rv, rv);
151 NS_ENSURE_SUCCESS(rv, rv);
154 NS_ENSURE_SUCCESS(rv, rv);
157 rv = AddDistinctGroupBy();
158 NS_ENSURE_SUCCESS(rv, rv);
166 nsAutoString columnName;
168 NS_ENSURE_SUCCESS(rv, rv);
170 nsCOMPtr<sbISQLBuilderCriterion> criterion;
174 getter_AddRefs(criterion));
175 rv = mBuilder->AddCriterion(criterion);
176 NS_ENSURE_SUCCESS(rv, rv);
179 rv = AddPrimarySort();
180 NS_ENSURE_SUCCESS(rv, rv);
183 NS_ENSURE_SUCCESS(rv, rv);
185 rv = mBuilder->ToString(aQuery);
186 NS_ENSURE_SUCCESS(rv, rv);
196 rv = mBuilder->Reset();
197 NS_ENSURE_SUCCESS(rv, rv);
201 aQuery = EmptyString();
205 rv = AddCountColumns();
206 NS_ENSURE_SUCCESS(rv, rv);
209 NS_ENSURE_SUCCESS(rv, rv);
212 NS_ENSURE_SUCCESS(rv, rv);
214 rv = AddNonNullPrimarySortConstraint();
215 NS_ENSURE_SUCCESS(rv, rv);
217 rv = mBuilder->ToString(aQuery);
218 NS_ENSURE_SUCCESS(rv, rv);
228 rv = mBuilder->Reset();
229 NS_ENSURE_SUCCESS(rv, rv);
233 aQuery = EmptyString();
237 rv = AddGuidColumns(PR_TRUE);
238 NS_ENSURE_SUCCESS(rv, rv);
241 NS_ENSURE_SUCCESS(rv, rv);
244 NS_ENSURE_SUCCESS(rv, rv);
246 rv = AddJoinToGetNulls();
247 NS_ENSURE_SUCCESS(rv, rv);
253 NS_ENSURE_SUCCESS(rv, rv);
256 NS_ENSURE_SUCCESS(rv, rv);
258 rv = mBuilder->ToString(aQuery);
259 NS_ENSURE_SUCCESS(rv, rv);
269 rv = mBuilder->Reset();
270 NS_ENSURE_SUCCESS(rv, rv);
272 rv = AddCountColumns();
273 NS_ENSURE_SUCCESS(rv, rv);
276 NS_ENSURE_SUCCESS(rv, rv);
279 rv = AddDistinctConstraint();
280 NS_ENSURE_SUCCESS(rv, rv);
284 NS_ENSURE_SUCCESS(rv, rv);
286 rv = AddPrimarySort();
287 NS_ENSURE_SUCCESS(rv, rv);
289 nsCOMPtr<sbISQLBuilderCriterion> criterion;
292 nsAutoString baseTable;
293 rv = mBuilder->GetBaseTableName(baseTable);
294 NS_ENSURE_SUCCESS(rv, rv);
300 getter_AddRefs(criterion));
301 NS_ENSURE_SUCCESS(rv, rv);
308 rv = mBuilder->CreateMatchCriterionParameter(
SORT_ALIAS,
311 getter_AddRefs(criterion));
312 NS_ENSURE_SUCCESS(rv, rv);
314 rv = mBuilder->AddCriterion(criterion);
315 NS_ENSURE_SUCCESS(rv, rv);
317 rv = mBuilder->ToString(aQuery);
318 NS_ENSURE_SUCCESS(rv, rv);
326 NS_ENSURE_FALSE(mIsDistinct, NS_ERROR_UNEXPECTED);
327 NS_ENSURE_TRUE(mSorts->Length() > 1, NS_ERROR_UNEXPECTED);
331 rv = mBuilder->Reset();
332 NS_ENSURE_SUCCESS(rv, rv);
334 rv = AddResortColumns();
335 NS_ENSURE_SUCCESS(rv, rv);
338 NS_ENSURE_SUCCESS(rv, rv);
341 nsCOMPtr<sbISQLBuilderCriterion> criterion;
349 NS_ENSURE_SUCCESS(rv, rv);
354 getter_AddRefs(criterion));
355 NS_ENSURE_SUCCESS(rv, rv);
356 rv = mBuilder->AddCriterion(criterion);
357 NS_ENSURE_SUCCESS(rv, rv);
367 NS_ENSURE_SUCCESS(rv, rv);
372 GetPropertyId(mSorts->ElementAt(0).property),
373 getter_AddRefs(criterion));
374 NS_ENSURE_SUCCESS(rv, rv);
375 rv = mBuilder->AddCriterion(criterion);
376 NS_ENSURE_SUCCESS(rv, rv);
381 getter_AddRefs(criterion));
382 NS_ENSURE_SUCCESS(rv, rv);
383 rv = mBuilder->AddCriterion(criterion);
384 NS_ENSURE_SUCCESS(rv, rv);
388 NS_ENSURE_SUCCESS(rv, rv);
390 rv = AddMultiSorts();
391 NS_ENSURE_SUCCESS(rv, rv);
393 rv = mBuilder->ToString(aQuery);
394 NS_ENSURE_SUCCESS(rv, rv);
402 NS_ENSURE_FALSE(mIsDistinct, NS_ERROR_UNEXPECTED);
403 NS_ENSURE_TRUE(mSorts->Length() > 1, NS_ERROR_UNEXPECTED);
406 return NS_ERROR_NOT_IMPLEMENTED;
411 rv = mBuilder->Reset();
412 NS_ENSURE_SUCCESS(rv, rv);
414 rv = AddResortColumns();
415 NS_ENSURE_SUCCESS(rv, rv);
418 NS_ENSURE_SUCCESS(rv, rv);
421 NS_ENSURE_SUCCESS(rv, rv);
425 nsCOMPtr<sbISQLBuilderCriterion> criterionGuid;
426 rv = mBuilder->CreateMatchCriterionTable(NS_LITERAL_STRING(
"_pX"),
431 getter_AddRefs(criterionGuid));
432 NS_ENSURE_SUCCESS(rv, rv);
434 nsCOMPtr<sbISQLBuilderCriterion> criterionProperty;
435 rv = mBuilder->CreateMatchCriterionLong(NS_LITERAL_STRING(
"_pX"),
436 NS_LITERAL_STRING(
"property_id"),
438 GetPropertyId(mSorts->ElementAt(0).property),
439 getter_AddRefs(criterionProperty));
440 NS_ENSURE_SUCCESS(rv, rv);
442 nsCOMPtr<sbISQLBuilderCriterion> criterion;
443 rv = mBuilder->CreateAndCriterion(criterionGuid,
445 getter_AddRefs(criterion));
446 NS_ENSURE_SUCCESS(rv, rv);
450 NS_LITERAL_STRING(
"_pX"),
452 NS_ENSURE_SUCCESS(rv, rv);
454 rv = mBuilder->CreateMatchCriterionNull(NS_LITERAL_STRING(
"_pX"),
457 getter_AddRefs(criterion));
458 NS_ENSURE_SUCCESS(rv, rv);
460 rv = mBuilder->AddCriterion(criterion);
461 NS_ENSURE_SUCCESS(rv, rv);
463 rv = AddMultiSorts();
464 NS_ENSURE_SUCCESS(rv, rv);
466 rv = mBuilder->ToString(aQuery);
467 NS_ENSURE_SUCCESS(rv, rv);
475 return mIsFullLibrary;
479 sbLocalDatabaseQuery::AddCountColumns()
485 nsAutoString columnName;
488 NS_ENSURE_SUCCESS(rv, rv);
491 count.AssignLiteral(
"count(distinct _mi.");
492 count.Append(columnName);
493 count.AppendLiteral(
")");
495 rv = mBuilder->AddColumn(EmptyString(), count);
496 NS_ENSURE_SUCCESS(rv, rv);
499 rv = mBuilder->AddColumn(EmptyString(),
500 NS_LITERAL_STRING(
"count(distinct _d.obj_sortable)"));
501 NS_ENSURE_SUCCESS(rv, rv);
506 NS_ENSURE_SUCCESS(rv, rv);
513 sbLocalDatabaseQuery::AddGuidColumns(PRBool aIsNull)
518 NS_ENSURE_SUCCESS(rv, rv);
521 NS_ENSURE_SUCCESS(rv, rv);
524 rv = mBuilder->AddColumn(EmptyString(), NS_LITERAL_STRING(
"''"));
525 NS_ENSURE_SUCCESS(rv, rv);
529 nsAutoString columnName;
531 NS_ENSURE_SUCCESS(rv, rv);
534 NS_ENSURE_SUCCESS(rv, rv);
542 NS_ENSURE_SUCCESS(rv, rv);
546 if (mIsDistinct && !mDistinctWithSortableValues) {
548 NS_ENSURE_SUCCESS(rv, rv);
552 NS_ENSURE_SUCCESS(rv, rv);
563 NS_ENSURE_SUCCESS(rv, rv);
566 rv = mBuilder->AddColumn(EmptyString(), NS_LITERAL_STRING(
"''"));
567 NS_ENSURE_SUCCESS(rv, rv);
573 if (mIsFullLibrary) {
581 NS_ENSURE_SUCCESS(rv, rv);
587 sbLocalDatabaseQuery::AddBaseTable()
591 if (mIsFullLibrary) {
593 NS_ENSURE_SUCCESS(rv, rv);
596 NS_ENSURE_SUCCESS(rv, rv);
603 rv = mBuilder->SetBaseTableName(mBaseTable);
604 NS_ENSURE_SUCCESS(rv, rv);
607 NS_ENSURE_SUCCESS(rv, rv);
609 nsCOMPtr<sbISQLBuilderCriterion> criterion;
611 mBaseConstraintColumn,
613 mBaseConstraintValue,
614 getter_AddRefs(criterion));
615 NS_ENSURE_SUCCESS(rv, rv);
617 rv = mBuilder->AddCriterion(criterion);
618 NS_ENSURE_SUCCESS(rv, rv);
625 mBaseForeignKeyColumn);
626 NS_ENSURE_SUCCESS(rv, rv);
633 sbLocalDatabaseQuery::AddFilters()
637 PRUint32 joinNum = 0;
640 PRUint32 len = mFilters->Length();
641 for (PRUint32
i = 0;
i < len;
i++) {
647 nsCOMPtr<sbISQLBuilderCriterion> criterion;
653 PRUint32 numValues = fs.
values.Length();
654 NS_ENSURE_STATE(numValues);
655 nsCOMPtr<sbISQLBuilderCriterion> nullCriterion;
657 if (fs.
values[0].EqualsLiteral(
"0")) {
676 nsString indexKillingAlias;
677 indexKillingAlias.AssignLiteral(
"+");
680 rv = mBuilder->CreateMatchCriterionNull(indexKillingAlias,
683 getter_AddRefs(nullCriterion));
684 NS_ENSURE_SUCCESS(rv, rv);
686 rv = mBuilder->AddCriterion(nullCriterion);
687 NS_ENSURE_SUCCESS(rv, rv);
690 nsCOMPtr<sbISQLBuilderCriterionIn> inCriterion;
691 if (isTopLevelProperty) {
694 nsAutoString columnName;
696 NS_ENSURE_SUCCESS(rv, rv);
700 getter_AddRefs(inCriterion));
701 NS_ENSURE_SUCCESS(rv, rv);
704 nsAutoString tableAlias;
705 tableAlias.AppendLiteral(
"_p");
706 tableAlias.AppendInt(joinNum++);
714 NS_ENSURE_SUCCESS(rv, rv);
717 rv = mBuilder->CreateMatchCriterionLong(tableAlias,
718 NS_LITERAL_STRING(
"property_id"),
721 getter_AddRefs(criterion));
722 NS_ENSURE_SUCCESS(rv, rv);
724 rv = mBuilder->AddCriterion(criterion);
725 NS_ENSURE_SUCCESS(rv, rv);
727 rv = mBuilder->CreateMatchCriterionIn(tableAlias,
729 getter_AddRefs(inCriterion));
730 NS_ENSURE_SUCCESS(rv, rv);
734 PRUint32 numValues = fs.
values.Length();
735 for (PRUint32 j = 0; j < numValues; j++) {
736 const nsAString& filterTerm = fs.
values[j];
737 rv = inCriterion->AddString(filterTerm);
738 NS_ENSURE_SUCCESS(rv, rv);
741 rv = mBuilder->AddCriterion(inCriterion);
742 NS_ENSURE_SUCCESS(rv, rv);
749 PRInt32 searchIndex = -1;
750 PRBool isEverythingSearch = PR_FALSE;
752 for (PRUint32
i = 0;
i < len;
i++) {
755 if (searchIndex < 0) {
758 NS_WARNING(
"Top level properties not supported in search");
759 return NS_ERROR_INVALID_ARG;
763 if (fs.
property.EqualsLiteral(
"*")) {
764 isEverythingSearch = PR_TRUE;
771 if (searchIndex >= 0) {
787 isEverythingSearch = PR_TRUE;
789 if (isEverythingSearch) {
794 NS_LITERAL_STRING(
"_fts"),
798 NS_ENSURE_SUCCESS(rv, rv);
827 mFilters->ElementAt(searchIndex);
829 for (PRUint32
i = 0;
i < fs.
values.Length();
i++) {
831 nsString stripped(fs.
values[
i]);
840 if(static_cast<PRUint32>(pos) + 1 < stripped.Length() &&
841 stripped[pos + 1] !=
'*' &&
842 stripped[pos + 1] !=
'-' &&
843 stripped[pos + 1] !=
' ') {
844 stripped.Replace(pos, 1, NS_LITERAL_STRING(
" NEAR/0 "));
848 stripped.Cut(pos, 1);
862 NS_LITERAL_STRING(
"\""),
863 NS_LITERAL_STRING(
"\\\""));
865 NS_LITERAL_STRING(
"'"),
866 NS_LITERAL_STRING(
"\\'"));
868 match.AppendLiteral(
"'");
869 match.Append(stripped);
870 match.AppendLiteral(
"*'");
872 if (
i + 1 < fs.
values.Length()) {
873 match.AppendLiteral(
" ");
877 nsCOMPtr<sbISQLBuilderCriterion> criterion;
878 rv = mBuilder->CreateMatchCriterionString(NS_LITERAL_STRING(
"_fts"),
880 NS_LITERAL_STRING(
"alldata") :
881 NS_LITERAL_STRING(
"obj_searchable"),
884 getter_AddRefs(criterion));
885 NS_ENSURE_SUCCESS(rv, rv);
887 rv = mBuilder->AddCriterion(criterion);
888 NS_ENSURE_SUCCESS(rv, rv);
891 if (!isEverythingSearch) {
892 nsCOMPtr<sbISQLBuilderCriterion> criterion;
893 rv = mBuilder->CreateMatchCriterionLong(NS_LITERAL_STRING(
"_fts"),
894 NS_LITERAL_STRING(
"propertyid"),
897 getter_AddRefs(criterion));
898 NS_ENSURE_SUCCESS(rv, rv);
900 rv = mBuilder->AddCriterion(criterion);
901 NS_ENSURE_SUCCESS(rv, rv);
909 nsCOMPtr<sbISQLBuilderCriterion> criterion;
910 nsAutoString columnName;
912 NS_ENSURE_SUCCESS(rv, rv);
917 getter_AddRefs(criterion));
918 NS_ENSURE_SUCCESS(rv, rv);
919 rv = mBuilder->AddCriterion(criterion);
920 NS_ENSURE_SUCCESS(rv, rv);
927 sbLocalDatabaseQuery::AddRange()
931 rv = mBuilder->SetOffsetIsParameter(PR_TRUE);
932 NS_ENSURE_SUCCESS(rv, rv);
934 rv = mBuilder->SetLimitIsParameter(PR_TRUE);
935 NS_ENSURE_SUCCESS(rv, rv);
941 sbLocalDatabaseQuery::AddPrimarySort()
949 nsAutoString columnName;
951 NS_ENSURE_SUCCESS(rv, rv);
955 mSorts->ElementAt(0).ascending);
956 NS_ENSURE_SUCCESS(rv, rv);
963 mSorts->ElementAt(0).ascending);
964 NS_ENSURE_SUCCESS(rv, rv);
975 nsAutoString baseTable;
976 rv = mBuilder->GetBaseTableName(baseTable);
977 NS_ENSURE_SUCCESS(rv, rv);
982 mSorts->ElementAt(0).ascending);
983 NS_ENSURE_SUCCESS(rv, rv);
992 mSorts->ElementAt(0).ascending);
993 NS_ENSURE_SUCCESS(rv, rv);
1006 NS_ENSURE_SUCCESS(rv, rv);
1011 nsCOMPtr<sbISQLBuilderCriterion> criterion;
1012 rv = mBuilder->CreateMatchCriterionLong(
SORT_ALIAS,
1015 GetPropertyId(mSorts->ElementAt(0).property),
1016 getter_AddRefs(criterion));
1017 NS_ENSURE_SUCCESS(rv, rv);
1019 rv = mBuilder->AddCriterion(criterion);
1020 NS_ENSURE_SUCCESS(rv, rv);
1027 mSorts->ElementAt(0).ascending);
1028 NS_ENSURE_SUCCESS(rv, rv);
1039 mSorts->ElementAt(0).ascending);
1040 NS_ENSURE_SUCCESS(rv, rv);
1050 mSorts->ElementAt(0).ascending);
1051 NS_ENSURE_SUCCESS(rv, rv);
1061 sbLocalDatabaseQuery::AddNonNullPrimarySortConstraint()
1065 nsCOMPtr<sbISQLBuilderCriterion> criterion;
1068 nsAutoString columnName;
1070 NS_ENSURE_SUCCESS(rv, rv);
1075 getter_AddRefs(criterion));
1076 rv = mBuilder->AddCriterion(criterion);
1077 NS_ENSURE_SUCCESS(rv, rv);
1082 nsAutoString baseTable;
1083 rv = mBuilder->GetBaseTableName(baseTable);
1084 NS_ENSURE_SUCCESS(rv, rv);
1090 getter_AddRefs(criterion));
1091 rv = mBuilder->AddCriterion(criterion);
1092 NS_ENSURE_SUCCESS(rv, rv);
1102 NS_ENSURE_SUCCESS(rv, rv);
1107 GetPropertyId(mSorts->ElementAt(0).property),
1108 getter_AddRefs(criterion));
1109 NS_ENSURE_SUCCESS(rv, rv);
1110 rv = mBuilder->AddCriterion(criterion);
1111 NS_ENSURE_SUCCESS(rv, rv);
1119 sbLocalDatabaseQuery::AddDistinctConstraint()
1126 nsAutoString columnName;
1128 NS_ENSURE_SUCCESS(rv, rv);
1130 nsCOMPtr<sbISQLBuilderCriterion> notNull;
1134 getter_AddRefs(notNull));
1135 NS_ENSURE_SUCCESS(rv, rv);
1137 nsCOMPtr<sbISQLBuilderCriterion> notEmptyString;
1142 getter_AddRefs(notEmptyString));
1143 NS_ENSURE_SUCCESS(rv, rv);
1146 nsCOMPtr<sbISQLBuilderCriterion> criterion;
1147 rv = mBuilder->CreateAndCriterion(notNull,
1149 getter_AddRefs(criterion));
1150 NS_ENSURE_SUCCESS(rv, rv);
1152 rv = mBuilder->AddCriterion(criterion);
1153 NS_ENSURE_SUCCESS(rv, rv);
1162 NS_ENSURE_SUCCESS(rv, rv);
1164 nsCOMPtr<sbISQLBuilderCriterion> property;
1168 GetPropertyId(mSorts->ElementAt(0).property),
1169 getter_AddRefs(property));
1170 NS_ENSURE_SUCCESS(rv, rv);
1172 nsCOMPtr<sbISQLBuilderCriterion> notEmptyString;
1177 getter_AddRefs(notEmptyString));
1178 NS_ENSURE_SUCCESS(rv, rv);
1180 nsCOMPtr<sbISQLBuilderCriterion> criterion;
1181 rv = mBuilder->CreateAndCriterion(property,
1183 getter_AddRefs(criterion));
1184 NS_ENSURE_SUCCESS(rv, rv);
1186 rv = mBuilder->AddCriterion(criterion);
1187 NS_ENSURE_SUCCESS(rv, rv);
1194 sbLocalDatabaseQuery::AddDistinctGroupBy()
1199 nsAutoString columnName;
1201 NS_ENSURE_SUCCESS(rv, rv);
1204 nsCOMPtr<sbISQLBuilderCriterion> notEmptyString;
1209 getter_AddRefs(notEmptyString));
1210 NS_ENSURE_SUCCESS(rv, rv);
1212 rv = mBuilder->AddCriterion(notEmptyString);
1213 NS_ENSURE_SUCCESS(rv, rv);
1216 NS_ENSURE_SUCCESS(rv, rv);
1225 NS_ENSURE_SUCCESS(rv, rv);
1229 nsCOMPtr<sbISQLBuilderCriterion> notEmptyString;
1230 rv = mBuilder->CreateMatchCriterionString(
SORT_ALIAS,
1234 getter_AddRefs(notEmptyString));
1235 NS_ENSURE_SUCCESS(rv, rv);
1237 rv = mBuilder->AddCriterion(notEmptyString);
1238 NS_ENSURE_SUCCESS(rv, rv);
1241 NS_ENSURE_SUCCESS(rv, rv);
1249 sbLocalDatabaseQuery::AddJoinToGetNulls()
1254 nsAutoString columnName;
1256 NS_ENSURE_SUCCESS(rv, rv);
1258 nsCOMPtr<sbISQLBuilderCriterion> criterion;
1262 getter_AddRefs(criterion));
1263 NS_ENSURE_SUCCESS(rv, rv);
1265 rv = mBuilder->AddCriterion(criterion);
1266 NS_ENSURE_SUCCESS(rv, rv);
1269 nsCOMPtr<sbISQLBuilderCriterion> criterionGuid;
1275 getter_AddRefs(criterionGuid));
1276 NS_ENSURE_SUCCESS(rv, rv);
1278 nsCOMPtr<sbISQLBuilderCriterion> criterionProperty;
1282 GetPropertyId(mSorts->ElementAt(0).property),
1283 getter_AddRefs(criterionProperty));
1284 NS_ENSURE_SUCCESS(rv, rv);
1286 nsCOMPtr<sbISQLBuilderCriterion> criterion;
1287 rv = mBuilder->CreateAndCriterion(criterionGuid,
1289 getter_AddRefs(criterion));
1290 NS_ENSURE_SUCCESS(rv, rv);
1296 NS_ENSURE_SUCCESS(rv, rv);
1301 getter_AddRefs(criterion));
1302 NS_ENSURE_SUCCESS(rv, rv);
1304 rv = mBuilder->AddCriterion(criterion);
1305 NS_ENSURE_SUCCESS(rv, rv);
1312 sbLocalDatabaseQuery::AddResortColumns()
1316 rv = mBuilder->SetDistinct(PR_TRUE);
1317 NS_ENSURE_SUCCESS(rv, rv);
1320 NS_ENSURE_SUCCESS(rv, rv);
1323 NS_ENSURE_SUCCESS(rv, rv);
1325 if (mIsFullLibrary) {
1326 rv = mBuilder->AddColumn(EmptyString(), NS_LITERAL_STRING(
"''"));
1327 NS_ENSURE_SUCCESS(rv, rv);
1330 NS_ENSURE_SUCCESS(rv, rv);
1334 NS_ENSURE_SUCCESS(rv, rv);
1337 NS_ENSURE_SUCCESS(rv, rv);
1344 sbLocalDatabaseQuery::AddMultiSorts()
1347 PRUint32 numSorts = mSorts->Length();
1348 for (PRUint32
i = 1;
i < numSorts;
i++) {
1352 joinedAlias.AppendInt(
i);
1354 nsCOMPtr<sbISQLBuilderCriterion> criterionGuid;
1355 rv = mBuilder->CreateMatchCriterionTable(joinedAlias,
1360 getter_AddRefs(criterionGuid));
1361 NS_ENSURE_SUCCESS(rv, rv);
1363 nsCOMPtr<sbISQLBuilderCriterion> criterion;
1369 NS_ENSURE_SUCCESS(rv, rv);
1371 nsString columnName;
1373 NS_ENSURE_SUCCESS(rv, rv);
1375 mBuilder->AddOrder(joinedAlias, columnName, sort.
ascending);
1376 NS_ENSURE_SUCCESS(rv, rv);
1379 nsCOMPtr<sbISQLBuilderCriterion> criterionProperty;
1380 rv = mBuilder->CreateMatchCriterionLong(joinedAlias,
1381 NS_LITERAL_STRING(
"property_id"),
1384 getter_AddRefs(criterionProperty));
1385 NS_ENSURE_SUCCESS(rv, rv);
1387 rv = mBuilder->CreateAndCriterion(criterionGuid,
1389 getter_AddRefs(criterion));
1390 NS_ENSURE_SUCCESS(rv, rv);
1396 NS_ENSURE_SUCCESS(rv, rv);
1399 NS_ENSURE_SUCCESS(rv, rv);
1407 NS_ENSURE_SUCCESS(rv, rv);
1413 sbLocalDatabaseQuery::GetPropertyId(
const nsAString& aProperty)
1419 sbLocalDatabaseQuery::MaxExpr(
const nsAString& aAlias,
1420 const nsAString& aColumn,
1424 buff.AssignLiteral(
"max(");
1425 buff.Append(aAlias);
1426 buff.AppendLiteral(
".");
1427 buff.Append(aColumn);
1428 buff.AppendLiteral(
")");
nsresult GetNullResortQuery(nsAString &aQuery)
#define MEDIALISTYPEID_COLUMN
nsresult GetFullGuidRangeQuery(nsAString &aQuery)
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
nsresult GetResortQuery(nsAString &aQuery)
nsresult GetFullCountQuery(nsAString &aQuery)
void nsString_ReplaceSubstring(nsAString &aString, const nsAString &aOldString, const nsAString &aNewString)
nsresult GetNonNullCountQuery(nsAString &aQuery)
static nsresult SB_GetTopLevelPropertyColumn(const nsAString &aProperty, nsAString &aColumnName)
nsresult GetNullGuidRangeQuery(nsAString &aQuery)
static PRBool SB_IsTopLevelProperty(PRUint32 aPropertyDBID)
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)
#define MEDIAITEMID_COLUMN
#define OBJSECONDARYSORTABLE_COLUMN
#define SB_SQLBUILDER_SELECT_CONTRACTID
static PRInt32 SB_GetPropertyId(const nsAString &aProperty, sbILocalDatabasePropertyCache *aPropertyCache)
const unsigned long MATCH_LESS
const unsigned long MATCH_MATCH
const unsigned long JOIN_INNER
ExtensionSchemeMatcher prototype match
const unsigned long JOIN_LEFT
const unsigned long MATCH_NOTEQUALS
#define PROPERTYID_COLUMN
#define PROPERTIES_FTS_ALL_TABLE
nsTArray< nsString > values
#define OBJSORTABLE_COLUMN
#define SIMPLEMEDIALISTS_TABLE
PRBool GetIsFullLibrary()
_getSelectedPageStyle s i
PRInt32 nsString_FindCharInSet(const nsAString &aString, const char *aPattern, PRInt32 aOffset)
nsresult GetPrefixSearchQuery(nsAString &aQuery)
const unsigned long MATCH_EQUALS