-
Type: Bug
-
Resolution: Cannot Reproduce
-
Priority: Trivial - P5
-
None
-
Affects Version/s: None
-
Component/s: None
Goals
Create predicate within the String argument of the filter method. Without the need to create a NSPredicate instance.
Expected Results
Actual filtered results, based on the predicate.
Actual Results
*** Terminating app due to uncaught exception 'Invalid value', reason: 'NSArray object must contain exactly two objects for BETWEEN operations'
Relevant part of thrown stack
`*** First throw call stack:
(
0 CoreFoundation 0x00007fff20421af6 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff20177e78 objc_exception_throw + 48
2 Realm 0x0000000104e44e42 _ZL15RLMPreconditionbP8NSStringS0_z + 626
3 Realm 0x0000000104ee310d ZN12_GLOBAL_N_134validate_and_extract_between_rangeEP11objc_objectP11RLMPropertyPU15_autoreleasingS1_S5
- 237
4 Realm 0x0000000104ecee4d ZN12_GLOBAL_N_112QueryBuilder22add_between_constraintERKNS_15ColumnReferenceEP11objc_object + 1037
5 Realm 0x0000000104e48188 ZN12_GLOBAL_N_112QueryBuilder22apply_value_expressionEP15RLMObjectSchemaP8NSStringP11objc_objectP21NSComparisonPredicate + 424
6 Realm 0x0000000104e46449 ZN12_GLOBAL_N_112QueryBuilder15apply_predicateEP11NSPredicateP15RLMObjectSchema + 4345
7 Realm 0x0000000104e44faf _Z19RLMPredicateToQueryP11NSPredicateP15RLMObjectSchemaP9RLMSchemaRN5realm5GroupE + 271`
Steps for others to Reproduce
Run a query using the following NSPredicate string and array as options:
`
let dateRange = [date1, date2]
let test = Realm.objects(RealmObject.self).filter("startTime BETWEEN %@", dateRange)
`
Code Sample
Actual method crashing : Link to Method
void QueryBuilder::add_between_constraint(const ColumnReference& column, id value) { if (column.has_any_to_many_links()) { auto link_column = column.last_link_column(); Query subquery = get_table(m_group, link_column.link_target_object_schema()).where(); QueryBuilder(subquery, m_group, m_schema).add_between_constraint(column.column_ignoring_links(subquery), value); m_query.and_query(link_column.resolve<Link>(std::move(subquery)).count() > 0); return; } id from, to; validate_and_extract_between_range(value, column.property(), &from, &to); RLMPropertyType type = column.type(); m_query.group(); add_constraint(type, NSGreaterThanOrEqualToPredicateOperatorType, 0, column, from); add_constraint(type, NSLessThanOrEqualToPredicateOperatorType, 0, column, to); m_query.end_group(); }
Workaround:
Pass the first object of the array, since it's the one that contains the actual variables array. It's not been tested throughout, maybe it's causing other errors.
validate_and_extract_between_range(value[0], column.property(), &from, &to);
Version of Realm and Tooling
Realm framework version:
- Realm (= 10.5.0)
- RealmSwift (= 10.5.0)
Realm Object Server version: N/a
Xcode version: Xcode 12.4 (12D4e)
iOS/OSX version: iOS 14.4
Dependency manager + version: Cocoapods 1.10.0