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

Add SingleQueryHasNextQueryResult test case #3311

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/include/main/query_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class QueryResult {

bool isEnd() const { return currentResult == nullptr; }

bool hasNextQueryResult() const { return currentResult->nextQueryResult != nullptr; }

QueryResult* getCurrentResult() const { return currentResult; }
};

Expand Down
9 changes: 3 additions & 6 deletions src/main/query_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,12 @@ bool QueryResult::hasNext() const {
}

bool QueryResult::hasNextQueryResult() const {
if (!queryResultIterator.isEnd()) {
return true;
}
return false;
return queryResultIterator.hasNextQueryResult();
}

QueryResult* QueryResult::getNextQueryResult() {
++queryResultIterator;
if (!queryResultIterator.isEnd()) {
if (hasNextQueryResult()) {
++queryResultIterator;
return queryResultIterator.getCurrentResult();
}
return nullptr;
Expand Down
8 changes: 7 additions & 1 deletion test/main/connection_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ TEST_F(ApiTest, MultipleQuery) {
ASSERT_EQ(result->getNextQueryResult()->toString(), "3\n3\n");
}

TEST_F(ApiTest, SingleQueryHasNextQueryResult) {
auto result = conn->query("MATCH (a:person) RETURN a.fName;");
ASSERT_TRUE(result->isSuccess());
ASSERT_FALSE(result->hasNextQueryResult());
}

TEST_F(ApiTest, Prepare) {
auto result = conn->prepare("");
ASSERT_EQ(result->getErrorMessage(), "Connection Exception: Query is empty.");
Expand All @@ -137,4 +143,4 @@ TEST_F(ApiTest, Prepare) {
"N, MANY_MANY);MATCH (a:N)-[:E]->(b:N) WHERE a.ID = 0 return b.ID;");
ASSERT_EQ(result->getErrorMessage(),
"Connection Exception: We do not support prepare multiple statements.");
}
}