mirror of
https://github.com/RGBCube/serenity
synced 2025-05-21 15:25:07 +00:00
LibSQL+Userland: Pass SQL IPC results to clients in a structure
SQLClient exists as a wrapper around SQL IPC to provide a bit friendlier interface for clients to deal with. Though right now, it mostly forwards values as-is from IPC to the clients. This makes it a bit verbose to add values to IPC responses, as we then have to add it to the callbacks used by all clients. It's also a bit confusing seeing a sea of "auto" as the parameter types for these callbacks. This patch moves these response values to named structures instead. This will allow adding values without needing to simultaneously update all clients. We can then separately handle the new values in interested clients only.
This commit is contained in:
parent
f0441ee16a
commit
d6dee8c0e8
6 changed files with 127 additions and 62 deletions
|
@ -154,45 +154,74 @@ ErrorOr<NonnullRefPtr<SQLClient>> SQLClient::launch_server_and_create_client(Vec
|
|||
|
||||
#endif
|
||||
|
||||
void SQLClient::execution_error(u64 statement_id, u64 execution_id, SQLErrorCode const& code, DeprecatedString const& message)
|
||||
{
|
||||
if (on_execution_error)
|
||||
on_execution_error(statement_id, execution_id, code, message);
|
||||
else
|
||||
warnln("Execution error for statement_id {}: {} ({})", statement_id, message, to_underlying(code));
|
||||
}
|
||||
|
||||
void SQLClient::execution_success(u64 statement_id, u64 execution_id, bool has_results, size_t created, size_t updated, size_t deleted)
|
||||
{
|
||||
if (on_execution_success)
|
||||
on_execution_success(statement_id, execution_id, has_results, created, updated, deleted);
|
||||
else
|
||||
if (!on_execution_success) {
|
||||
outln("{} row(s) created, {} updated, {} deleted", created, updated, deleted);
|
||||
}
|
||||
|
||||
void SQLClient::next_result(u64 statement_id, u64 execution_id, Vector<SQL::Value> const& row)
|
||||
{
|
||||
if (on_next_result) {
|
||||
on_next_result(statement_id, execution_id, row);
|
||||
return;
|
||||
}
|
||||
|
||||
bool first = true;
|
||||
for (auto& column : row) {
|
||||
if (!first)
|
||||
out(", ");
|
||||
out("\"{}\"", column);
|
||||
first = false;
|
||||
ExecutionSuccess success {
|
||||
.statement_id = statement_id,
|
||||
.execution_id = execution_id,
|
||||
.has_results = has_results,
|
||||
.rows_created = created,
|
||||
.rows_updated = updated,
|
||||
.rows_deleted = deleted,
|
||||
};
|
||||
|
||||
on_execution_success(move(success));
|
||||
}
|
||||
|
||||
void SQLClient::execution_error(u64 statement_id, u64 execution_id, SQLErrorCode const& code, DeprecatedString const& message)
|
||||
{
|
||||
if (!on_execution_error) {
|
||||
warnln("Execution error for statement_id {}: {} ({})", statement_id, message, to_underlying(code));
|
||||
return;
|
||||
}
|
||||
outln();
|
||||
|
||||
ExecutionError error {
|
||||
.statement_id = statement_id,
|
||||
.execution_id = execution_id,
|
||||
.error_code = code,
|
||||
.error_message = move(const_cast<DeprecatedString&>(message)),
|
||||
};
|
||||
|
||||
on_execution_error(move(error));
|
||||
}
|
||||
|
||||
void SQLClient::next_result(u64 statement_id, u64 execution_id, Vector<Value> const& row)
|
||||
{
|
||||
if (!on_next_result) {
|
||||
StringBuilder builder;
|
||||
builder.join(", "sv, row, "\"{}\""sv);
|
||||
outln("{}", builder.string_view());
|
||||
return;
|
||||
}
|
||||
|
||||
ExecutionResult result {
|
||||
.statement_id = statement_id,
|
||||
.execution_id = execution_id,
|
||||
.values = move(const_cast<Vector<Value>&>(row)),
|
||||
};
|
||||
|
||||
on_next_result(move(result));
|
||||
}
|
||||
|
||||
void SQLClient::results_exhausted(u64 statement_id, u64 execution_id, size_t total_rows)
|
||||
{
|
||||
if (on_results_exhausted)
|
||||
on_results_exhausted(statement_id, execution_id, total_rows);
|
||||
else
|
||||
if (!on_results_exhausted) {
|
||||
outln("{} total row(s)", total_rows);
|
||||
return;
|
||||
}
|
||||
|
||||
ExecutionComplete success {
|
||||
.statement_id = statement_id,
|
||||
.execution_id = execution_id,
|
||||
.total_rows = total_rows,
|
||||
};
|
||||
|
||||
on_results_exhausted(move(success));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue