-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Allow null value for startAt, endAt and equalTo database queries on Android #504
Allow null value for startAt, endAt and equalTo database queries on Android #504
Conversation
@@ -83,7 +83,9 @@ private Query getQuery(FirebaseDatabase database, Map<String, Object> arguments) | |||
Object startAt = parameters.get("startAt"); | |||
if (parameters.containsKey("startAtKey")) { | |||
String startAtKey = (String) parameters.get("startAtKey"); | |||
if (startAt instanceof Boolean) { | |||
if (startAt == null) { | |||
query = query.startAt(null, startAtKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This invocation will become ambiguous, if another startAt
overload with a reference type as first argument is ever added to the Firebase API. Since we actually invoke the startAt(String, String)
method here, I suggest we collapse the null
and String
cases into one, handled by the else
branch:
if (startAt instanceof Boolean) {
query = query.startAt((Boolean) startAt, startAtKey);
} else if (startAt instanceof Number) {
query = query.startAt(((Number) startAt).doubleValue(), startAtKey);
} else {
query = query.startAt((String) startAt, startAtKey);
}
Similarly below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good point! Fixed.
@@ -70,7 +70,12 @@ - (NSDictionary *)dictionary { | |||
} | |||
id equalTo = parameters[@"equalTo"]; | |||
if (equalTo) { | |||
query = [query queryEqualToValue:equalTo]; | |||
id equalToKey = parameters[@"equalToKey"]; | |||
if (equalToKey) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we not check for equality with [NSNull null]
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simply updated this block to follow the same pattern as in startAt
and endAt
blocks where this check seems to be working as expected. I'm not an Obj-C expert by any means though.
This SO answer says that it's a right way to check for nil
(which is a literal null value for Obj-C objects).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, because you also took care to change the Dart code to ensure that if there is an equalToKey
entry in parameters
, then it maps to a non-null value. I just didn't see that on my first reading.
This should be ready for another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
query = query.equalTo(((Number) equalTo).doubleValue()); | ||
if (equalTo instanceof Boolean) { | ||
query = query.equalTo((Boolean) equalTo); | ||
} else if (equalTo instanceof String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String case should be moved to else branch here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM
Published. Thanks a lot for the contribution! |
This was quick. :) Thanks for your help as well! |
This is a companion for #353 which fixes null value handling on Android side. There are some minor cleanups on iOS and Dart side as well.
Tested behavior of null
startAt
on Android and it works as expected.