@@ -95,32 +95,35 @@ - (void)validateQueryEndpointsForParams:(FQueryParams *)params {
9595 if (params.indexStartKey != [FUtilities minName ] &&
9696 params.indexStartKey != [FUtilities maxName ]) {
9797 [NSException raise: INVALID_QUERY_PARAM_ERROR
98- format: @" Can't use queryStartingAtValue:childKey: "
98+ format: @" Can't use queryStartingAtValue:childKey:, "
99+ @" queryStartingAfterValue:childKey:, "
99100 @" or queryEqualTo:andChildKey: in "
100101 @" combination with queryOrderedByKey" ];
101102 }
102103 if (![params.indexStartValue.val isKindOfClass: [NSString class ]]) {
103- [NSException
104- raise: INVALID_QUERY_PARAM_ERROR
105- format:
106- @" Can't use queryStartingAtValue: with other types "
107- @" than string in combination with queryOrderedByKey" ];
104+ [NSException raise: INVALID_QUERY_PARAM_ERROR
105+ format: @" Can't use queryStartingAtValue: or "
106+ @" queryStartingAfterValue: "
107+ @" with non-string types when used with "
108+ @" queryOrderedByKey" ];
108109 }
109110 }
110111 if ([params hasEnd ]) {
111112 if (params.indexEndKey != [FUtilities maxName ] &&
112113 params.indexEndKey != [FUtilities minName ]) {
113114 [NSException raise: INVALID_QUERY_PARAM_ERROR
114115 format: @" Can't use queryEndingAtValue:childKey: or "
116+ @" queryEndingBeforeValue:childKey: "
115117 @" queryEqualToValue:childKey: in "
116118 @" combination with queryOrderedByKey" ];
117119 }
118120 if (![params.indexEndValue.val isKindOfClass: [NSString class ]]) {
119121 [NSException
120122 raise: INVALID_QUERY_PARAM_ERROR
121- format:
122- @" Can't use queryEndingAtValue: with other types than "
123- @" string in combination with queryOrderedByKey" ];
123+ format: @" Can't use queryEndingAtValue: or "
124+ @" queryEndingBeforeValue: "
125+ @" with other types than string in combination with "
126+ @" queryOrderedByKey" ];
124127 }
125128 }
126129 } else if ([params.index isEqual: [FPriorityIndex priorityIndex ]]) {
@@ -131,7 +134,8 @@ - (void)validateQueryEndpointsForParams:(FQueryParams *)params {
131134 [NSException
132135 raise: INVALID_QUERY_PARAM_ERROR
133136 format: @" When using queryOrderedByPriority, values provided to "
134- @" queryStartingAtValue:, queryEndingAtValue:, or "
137+ @" queryStartingAtValue:, queryStartingAfterValue:, "
138+ @" queryEndingAtValue:, queryEndingBeforeValue:, or "
135139 @" queryEqualToValue: must be valid priorities." ];
136140 }
137141 }
@@ -142,13 +146,14 @@ - (void)validateEqualToCall {
142146 [NSException
143147 raise: INVALID_QUERY_PARAM_ERROR
144148 format:
145- @" Cannot combine queryEqualToValue: and queryStartingAtValue:" ];
149+ @" Cannot combine queryEqualToValue: and queryStartingAtValue: "
150+ @" or queryStartingAfterValue:" ];
146151 }
147152 if ([self .queryParams hasEnd ]) {
148153 [NSException
149154 raise: INVALID_QUERY_PARAM_ERROR
150- format:
151- @" Cannot combine queryEqualToValue: and queryEndingAtValue :" ];
155+ format: @" Cannot combine queryEqualToValue: and queryEndingAtValue: "
156+ @" or queryEndingBeforeValue :" ];
152157 }
153158}
154159
@@ -202,20 +207,25 @@ - (FIRDatabaseQuery *)queryStartingAfterValue:(id)startAfterValue {
202207
203208- (FIRDatabaseQuery *)queryStartingAfterValue : (id )startAfterValue
204209 childKey : (NSString *)childKey {
205- if ([self .queryParams.index isEqual: [FKeyIndex keyIndex ]] &&
206- childKey != nil ) {
207- @throw [[NSException alloc ]
208- initWithName: INVALID_QUERY_PARAM_ERROR
209- reason: @" You must use queryStartingAfterValue: instead of "
210- @" queryStartingAfterValue:childKey: when using "
211- @" queryOrderedByKey:"
212- userInfo: nil ];
213- }
214- if (childKey == nil ) {
215- childKey = [FUtilities maxName ];
210+ if ([self .queryParams.index isEqual: [FKeyIndex keyIndex ]]) {
211+ if (childKey != nil ) {
212+ @throw [[NSException alloc ]
213+ initWithName: INVALID_QUERY_PARAM_ERROR
214+ reason:
215+ @" You must use queryStartingAfterValue: instead of "
216+ @" queryStartingAfterValue:childKey: when using "
217+ @" queryOrderedByKey:"
218+ userInfo: nil ];
219+ }
220+ if ([startAfterValue isKindOfClass: [NSString class ]]) {
221+ startAfterValue = [FNextPushId successor: startAfterValue];
222+ }
216223 } else {
217- childKey = [FNextPushId successor: childKey];
218- NSLog (@" successor of child key %@ " , childKey);
224+ if (childKey == nil ) {
225+ childKey = [FUtilities maxName ];
226+ } else {
227+ childKey = [FNextPushId successor: childKey];
228+ }
219229 }
220230 NSString *methodName = @" queryStartingAfterValue:childKey:" ;
221231 if (childKey != nil && ![childKey isEqual: [FUtilities maxName ]]) {
@@ -234,7 +244,8 @@ - (FIRDatabaseQuery *)queryStartingAtInternal:(id<FNode>)startValue
234244 [self validateIndexValueType: startValue fromMethod: methodName];
235245 if ([self .queryParams hasStart ]) {
236246 [NSException raise: INVALID_QUERY_PARAM_ERROR
237- format: @" Can't call %@ after queryStartingAtValue or "
247+ format: @" Can't call %@ after queryStartingAtValue, "
248+ @" queryStartingAfterValue, or "
238249 @" queryEqualToValue was previously called" ,
239250 methodName];
240251 }
@@ -283,20 +294,24 @@ - (FIRDatabaseQuery *)queryEndingBeforeValue:(id)endValue {
283294
284295- (FIRDatabaseQuery *)queryEndingBeforeValue : (id )endValue
285296 childKey : (NSString *)childKey {
286- if ([self .queryParams.index isEqual: [FKeyIndex keyIndex ]] &&
287- childKey != nil ) {
288- @throw [[NSException alloc ]
289- initWithName: INVALID_QUERY_PARAM_ERROR
290- reason: @" You must use queryEndingBeforeValue: instead of "
291- @" queryEndingBeforeValue:childKey: when using "
292- @" queryOrderedByKey:"
293- userInfo: nil ];
294- }
295-
296- if (childKey == nil ) {
297- childKey = [FUtilities minName ];
297+ if ([self .queryParams.index isEqual: [FKeyIndex keyIndex ]]) {
298+ if ( childKey != nil ) {
299+ @throw [[NSException alloc ]
300+ initWithName: INVALID_QUERY_PARAM_ERROR
301+ reason: @" You must use queryEndingBeforeValue: instead of "
302+ @" queryEndingBeforeValue:childKey: when using "
303+ @" queryOrderedByKey:"
304+ userInfo: nil ];
305+ }
306+ if ([endValue isKindOfClass: [ NSString class ]]) {
307+ endValue = [FNextPushId predecessor: endValue];
308+ }
298309 } else {
299- childKey = [FNextPushId predecessor: childKey];
310+ if (childKey == nil ) {
311+ childKey = [FUtilities minName ];
312+ } else {
313+ childKey = [FNextPushId predecessor: childKey];
314+ }
300315 }
301316 NSString *methodName = @" queryEndingBeforeValue:childKey:" ;
302317 if (childKey != nil && ![childKey isEqual: [FUtilities minName ]]) {
@@ -361,12 +376,12 @@ - (FIRDatabaseQuery *)queryEqualToInternal:(id)value
361376 [FValidation validateFrom: methodName validKey: childKey];
362377 }
363378 if ([self .queryParams hasEnd ] || [self .queryParams hasStart ]) {
364- [NSException
365- raise: INVALID_QUERY_PARAM_ERROR
366- format:
367- @" Can't call %@ after queryStartingAtValue, queryEndingAtValue "
368- @" or queryEqualToValue was previously called" ,
369- methodName];
379+ [NSException raise: INVALID_QUERY_PARAM_ERROR
380+ format: @" Can't call %@ after queryStartingAtValue, "
381+ @" queryStartingAfterValue, queryEndingAtValue, "
382+ @" queryEndingBeforeValue or queryEqualToValue "
383+ @" was previously called" ,
384+ methodName];
370385 }
371386 id <FNode> node = [FSnapshotUtilities nodeFrom: value];
372387 FQueryParams *params = [[self .queryParams startAt: node
0 commit comments