Add has more for fetching optional result if no more rows to fetch

This commit is contained in:
Josip Mrden 2024-03-01 12:55:41 +01:00
parent 671f51f21d
commit ce9bba8e83
4 changed files with 16 additions and 1 deletions

View File

@ -871,4 +871,6 @@ inline mgp_map *pull_one(mgp_execution_result *result, mgp_graph *graph, mgp_mem
return MgInvoke<mgp_map *>(mgp_pull_one, result, graph, memory);
}
inline bool has_more_rows(mgp_execution_result *result) { return MgInvoke<bool>(mgp_has_more_rows, result); }
} // namespace mgp

View File

@ -1815,6 +1815,8 @@ enum mgp_error mgp_execute_query(struct mgp_graph *graph, struct mgp_memory *mem
enum mgp_error mgp_fetch_execution_headers(struct mgp_execution_result *exec_result,
struct mgp_execution_headers **headers);
enum mgp_error mgp_has_more_rows(struct mgp_execution_result *exec_result, bool *result);
enum mgp_error mgp_pull_one(struct mgp_execution_result *exec_result, struct mgp_graph *graph,
struct mgp_memory *memory, struct mgp_map **result);

View File

@ -1635,6 +1635,7 @@ class ExecutionResult {
public:
ExecutionResult(mgp_execution_result *result, mgp_graph *graph);
ExecutionHeaders Headers() const;
bool HasMore() const;
std::optional<ExecutionRow> PullOne() const;
private:
@ -4397,8 +4398,14 @@ inline ExecutionResult::ExecutionResult(mgp_execution_result *result, mgp_graph
inline ExecutionHeaders ExecutionResult::Headers() const { return mgp::fetch_execution_headers(result_); };
inline bool ExecutionResult::HasMore() const { return mgp::has_more_rows(result_); }
inline std::optional<ExecutionRow> ExecutionResult::PullOne() const {
return ExecutionRow(mgp::MemHandlerCallback(pull_one, result_, graph_));
if (HasMore()) {
return ExecutionRow(mgp::MemHandlerCallback(pull_one, result_, graph_));
}
return std::nullopt;
}
inline bool ExecutionHeaders::Iterator::operator==(const Iterator &other) const {

View File

@ -4106,6 +4106,10 @@ mgp_error mgp_fetch_execution_headers(mgp_execution_result *exec_result, mgp_exe
return WrapExceptions([exec_result]() { return &exec_result->headers; }, result);
}
mgp_error mgp_has_more_rows(mgp_execution_result *exec_result, bool *result) {
return WrapExceptions([exec_result]() { return exec_result->index >= exec_result->rows.rows.size(); }, result);
}
mgp_error mgp_pull_one(mgp_execution_result *exec_result, mgp_graph *graph, mgp_memory *memory, mgp_map **result) {
return WrapExceptions(
[exec_result, graph, memory]() {