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

Allow geo coordinate numeric argument substitutions #6663

Merged
merged 3 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

### Breaking changes
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 m_args.long_for_argument(arg_no);
case type_Double:
return m_args.double_for_argument(arg_no);
case type_Float:
return 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