Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query serialisation part 3 #2989

Merged
merged 16 commits into from
Feb 14, 2018
Prev Previous commit
Next Next commit
Add a realm prefix to precondition
James Stone committed Feb 6, 2018
commit 4999d59a8f130f8eb0b5f41bea0143fe5882cec9
8 changes: 4 additions & 4 deletions src/realm/parser/collection_operator_expression.hpp
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ struct CollectionOperatorExpression
} else {
list_property_name = pre_link_table->get_column_name(pe.get_dest_ndx());
}
precondition(pe.get_dest_type() == type_LinkList || pe.dest_type_is_backlink(),
realm_precondition(pe.get_dest_type() == type_LinkList || pe.dest_type_is_backlink(),
util::format("The '%1' operation must be used on a list property, but '%2' is not a list",
util::collection_operator_to_str(OpType), list_property_name));

@@ -74,13 +74,13 @@ struct CollectionOperatorExpression

KeyPath suffix_key_path = key_path_from_string(suffix_path);

precondition(suffix_path.size() > 0 && suffix_key_path.size() > 0,
realm_precondition(suffix_path.size() > 0 && suffix_key_path.size() > 0,
util::format("A property from object '%1' must be provided to perform operation '%2'",
printable_post_link_table_name, util::collection_operator_to_str(OpType)));
size_t index = 0;
KeyPathElement element = mapping.process_next_path(post_link_table, suffix_key_path, index);

precondition(suffix_key_path.size() == 1,
realm_precondition(suffix_key_path.size() == 1,
util::format("Unable to use '%1' because collection aggreate operations are only supported "
"for direct properties at this time", suffix_path));

@@ -90,7 +90,7 @@ struct CollectionOperatorExpression
else { // !requires_suffix_path
post_link_col_type = pe.get_dest_type();

precondition(suffix_path.empty(),
realm_precondition(suffix_path.empty(),
util::format("An extraneous property '%1' was found for operation '%2'",
suffix_path, util::collection_operator_to_str(OpType)));
}
6 changes: 3 additions & 3 deletions src/realm/parser/keypath_mapping.cpp
Original file line number Diff line number Diff line change
@@ -65,10 +65,10 @@ KeyPathElement KeyPathMapping::process_next_path(ConstTableRef table, KeyPath& k

// Process backlinks which consumes 3 parts of the keypath
if (is_backlinks_prefix(keypath[index])) {
precondition(index + 2 < keypath.size(), "'@links' must be proceeded by type name and a property name");
realm_precondition(index + 2 < keypath.size(), "'@links' must be proceeded by type name and a property name");

Table::BacklinkOrigin info = table->find_backlink_origin(keypath[index + 1], keypath[index + 2]);
precondition(bool(info), util::format("No property '%1' found in type '%2' which links to type '%3'",
realm_precondition(bool(info), util::format("No property '%1' found in type '%2' which links to type '%3'",
keypath[index + 2], get_printable_table_name(keypath[index + 1]), get_printable_table_name(*table)));

if (!m_allow_backlinks) {
@@ -88,7 +88,7 @@ KeyPathElement KeyPathMapping::process_next_path(ConstTableRef table, KeyPath& k

// Process a single property
size_t col_ndx = table->get_column_index(keypath[index]);
precondition(col_ndx != realm::not_found,
realm_precondition(col_ndx != realm::not_found,
util::format("No property '%1' on object of type '%2'", keypath[index], get_printable_table_name(*table)));

DataType cur_col_type = table->get_column_type(col_ndx);
2 changes: 1 addition & 1 deletion src/realm/parser/parser_utils.hpp
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ namespace util {
// check a precondition and throw an exception if it is not met
// this should be used iff the condition being false indicates a bug in the caller
// of the function checking its preconditions
#define precondition(condition, message) if (!REALM_LIKELY(condition)) { throw std::logic_error(message); }
#define realm_precondition(condition, message) if (!REALM_LIKELY(condition)) { throw std::logic_error(message); }


template <typename T>
2 changes: 1 addition & 1 deletion src/realm/parser/property_expression.cpp
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ PropertyExpression::PropertyExpression(Query &q, const std::string &key_path_str
while (index < key_path.size()) {
KeyPathElement element = mapping.process_next_path(cur_table, key_path, index);
if (index != key_path.size()) {
precondition(element.col_type == type_Link || element.col_type == type_LinkList,
realm_precondition(element.col_type == type_Link || element.col_type == type_LinkList,
util::format("Property '%1' is not a link in object of type '%2'",
element.table->get_column_name(element.col_ndx),
get_printable_table_name(*element.table)));
6 changes: 3 additions & 3 deletions src/realm/parser/query_builder.cpp
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ void do_add_null_comparison_to_query(Query &query, Predicate::Operator op, const
template<>
void do_add_null_comparison_to_query<Link>(Query &query, Predicate::Operator op, const PropertyExpression &expr)
{
precondition(expr.link_chain.size() == 1, "KeyPath queries not supported for object comparisons.");
realm_precondition(expr.link_chain.size() == 1, "KeyPath queries not supported for object comparisons.");
switch (op) {
case Predicate::Operator::NotEqual:
query.Not();
@@ -288,7 +288,7 @@ void add_link_constraint_to_query(realm::Query &query,
const PropertyExpression &prop_expr,
const ValueExpression &value_expr) {
size_t row_index = value_expr.arguments->object_index_for_argument(stot<int>(value_expr.value->s));
precondition(prop_expr.link_chain.size() == 1, "KeyPath queries not supported for object comparisons.");
realm_precondition(prop_expr.link_chain.size() == 1, "KeyPath queries not supported for object comparisons.");
switch (op) {
case Predicate::Operator::NotEqual:
query.Not();
@@ -617,7 +617,7 @@ void apply_predicate(Query &query, const Predicate &predicate, Arguments &argume

// Test the constructed query in core
std::string validateMessage = query.validate();
precondition(validateMessage.empty(), validateMessage.c_str());
realm_precondition(validateMessage.empty(), validateMessage.c_str());
}

struct EmptyArgContext
4 changes: 2 additions & 2 deletions src/realm/parser/subquery_expression.cpp
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ SubqueryExpression::SubqueryExpression(Query &q, const std::string &key_path_str
while (index < key_path.size()) {
KeyPathElement element = mapping.process_next_path(cur_table, key_path, index);
if (index != key_path.size()) {
precondition(element.col_type == type_Link || element.col_type == type_LinkList,
realm_precondition(element.col_type == type_Link || element.col_type == type_LinkList,
util::format("Property '%1' is not a link in object of type '%2'",
element.table->get_column_name(element.col_ndx),
get_printable_table_name(*element.table)));
@@ -53,7 +53,7 @@ SubqueryExpression::SubqueryExpression(Query &q, const std::string &key_path_str
} else {
dest_type = data_type_to_str(element.col_type);
}
precondition(element.col_type == type_LinkList,
realm_precondition(element.col_type == type_LinkList,
util::format("A subquery must operate on a list property, but '%1' is type '%2'",
element.table->get_column_name(element.col_ndx),
dest_type));