Skip to content

Commit

Permalink
Allow geo coordinate numeric argument substitutions (#6663)
Browse files Browse the repository at this point in the history
* allow geo coordinate numeric argument substitutions

* review feedback

* explicit cast to address warning
  • Loading branch information
ironage authored May 25, 2023
1 parent 5bc5f3b commit 8339bfb
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 230 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
* Allow numeric substitutions into a geospatial query. Example `location GEOWITHIN geoCircle([$0, $1], $2)`. ([#6662](https://github.com/realm/realm-core/issues/6662))
* Access token refresh for websockets was not updating the location metadata ([#6630](https://github.com/realm/realm-core/issues/6630), since v13.9.3)
* Fix several UBSan failures which did not appear to result in functional bugs ([#6649](https://github.com/realm/realm-core/pull/6649)).
* Fix an out-of-bounds read in sectioned results when sectioned are removed by modifying all objects in that section to no longer appear in that section ([#6649](https://github.com/realm/realm-core/pull/6649), since v13.12.0)
Expand Down
29 changes: 26 additions & 3 deletions src/realm/parser/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ ParserDriver::~ParserDriver()
yylex_destroy(m_yyscanner);
}

Mixed ParserDriver::get_arg_for_index(std::string i)
Mixed ParserDriver::get_arg_for_index(const std::string& i)
{
REALM_ASSERT(i[0] == '$');
size_t arg_no = size_t(strtol(i.substr(1).c_str(), nullptr, 10));
Expand All @@ -1586,15 +1586,38 @@ Mixed ParserDriver::get_arg_for_index(std::string i)
switch (type) {
case type_Int:
return int64_t(m_args.long_for_argument(arg_no));
break;
case type_String:
return m_args.string_for_argument(arg_no);
break;
default:
throw InvalidQueryError("Invalid index type");
}
}

double ParserDriver::get_arg_for_coordinate(const std::string& str)
{
REALM_ASSERT(str[0] == '$');
size_t arg_no = size_t(strtol(str.substr(1).c_str(), nullptr, 10));
if (m_args.is_argument_null(arg_no)) {
throw InvalidQueryError(util::format("NULL cannot be used in coordinate at argument '%1'", str));
}
if (m_args.is_argument_list(arg_no)) {
throw InvalidQueryError(util::format("A list cannot be used in a coordinate at argument '%1'", str));
}

auto type = m_args.type_for_argument(arg_no);
switch (type) {
case type_Int:
return double(m_args.long_for_argument(arg_no));
case type_Double:
return m_args.double_for_argument(arg_no);
case type_Float:
return double(m_args.float_for_argument(arg_no));
default:
throw InvalidQueryError(util::format("Invalid parameter '%1' used in coordinate at argument '%2'",
get_data_type_name(type), str));
}
}

auto ParserDriver::cmp(const std::vector<ExpressionNode*>& values) -> std::pair<SubexprPtr, SubexprPtr>
{
SubexprPtr left;
Expand Down
3 changes: 2 additions & 1 deletion src/realm/parser/driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,8 @@ class ParserDriver {
parse_error = true;
}

Mixed get_arg_for_index(std::string);
Mixed get_arg_for_index(const std::string&);
double get_arg_for_coordinate(const std::string&);

template <class T>
Query simple_query(int op, ColKey col_key, T val, bool case_sensitive);
Expand Down
Loading

0 comments on commit 8339bfb

Please sign in to comment.