Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hououou committed Mar 26, 2024
1 parent 9e4b419 commit e006d4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
13 changes: 6 additions & 7 deletions src/main/client_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ std::string ClientContext::getEnvVariable(const std::string& name) {

std::unique_ptr<PreparedStatement> ClientContext::prepare(std::string_view query) {
auto preparedStatement = std::unique_ptr<PreparedStatement>();
if (query.empty()) {
return preparedStatementWithError("Connection Exception: Query is empty.");
}
std::unique_lock<std::mutex> lck{mtx};
auto parsedStatements = std::vector<std::shared_ptr<Statement>>();
try {
Expand All @@ -200,9 +203,6 @@ std::unique_ptr<PreparedStatement> ClientContext::prepare(std::string_view query
return preparedStatementWithError(
"Connection Exception: We do not support prepare multiple statements.");
}
if (parsedStatements.empty()) {
return preparedStatementWithError("Connection Exception: Query is empty.");
}
return prepareNoLock(parsedStatements[0]);
}

Expand Down Expand Up @@ -231,14 +231,13 @@ std::unique_ptr<QueryResult> ClientContext::query(std::string_view queryStatemen
std::unique_ptr<QueryResult> ClientContext::query(
std::string_view query, std::string_view encodedJoin, bool enumerateAllPlans) {
lock_t lck{mtx};
// parsing
if (query.empty()) {
return queryResultWithError("Connection Exception: Query is empty.");
}
auto parsedStatements = std::vector<std::shared_ptr<Statement>>();
try {
parsedStatements = Parser::parseQuery(query);
} catch (std::exception& exception) { return queryResultWithError(exception.what()); }
if (parsedStatements.empty()) {
return queryResultWithError("Connection Exception: Query is empty.");
}
std::unique_ptr<QueryResult> queryResult;
QueryResult* lastResult = nullptr;
for (auto& statement : parsedStatements) {
Expand Down
16 changes: 4 additions & 12 deletions tools/rust_api/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,11 @@ Invalid input <MATCH (a:Person RETURN>: expected rule oC_SingleQuery (line: 1, o
conn.query("CREATE NODE TABLE Person(name STRING, age INT16, PRIMARY KEY(name));")?;
conn.query("CREATE (:Person {name: 'Alice', age: 25});")?;
conn.query("CREATE (:Person {name: 'Bob', age: 30});")?;

let mut statement = conn.prepare("MATCH (a:Person) WHERE a.age = $age RETURN a.name;")?;
let result: Error = conn
.execute(
&mut statement,
vec![("age", Value::String("25".to_string()))],
)
.expect_err("Age should be an int16!")
.into();
assert_eq!(
result.to_string(),
"Query execution failed: Parameter age has data type STRING but expects INT16."
);
for result in conn.execute(&mut statement, vec![("age", Value::String("25".to_string()))])? {
assert_eq!(result.len(), 1);
assert_eq!(result[0], Value::String("Alice".to_string()));
}
temp_dir.close()?;
Ok(())
}
Expand Down

0 comments on commit e006d4c

Please sign in to comment.