diff options
Diffstat (limited to 'Userland/Libraries/LibSQL/SQLClient.cpp')
-rw-r--r-- | Userland/Libraries/LibSQL/SQLClient.cpp | 77 |
1 files changed, 53 insertions, 24 deletions
diff --git a/Userland/Libraries/LibSQL/SQLClient.cpp b/Userland/Libraries/LibSQL/SQLClient.cpp index bab488ef0f..1b0705ed16 100644 --- a/Userland/Libraries/LibSQL/SQLClient.cpp +++ b/Userland/Libraries/LibSQL/SQLClient.cpp @@ -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); + return; + } + + 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::next_result(u64 statement_id, u64 execution_id, Vector<SQL::Value> const& row) +void SQLClient::execution_error(u64 statement_id, u64 execution_id, SQLErrorCode const& code, DeprecatedString const& message) { - if (on_next_result) { - on_next_result(statement_id, execution_id, row); + if (!on_execution_error) { + warnln("Execution error for statement_id {}: {} ({})", statement_id, message, to_underlying(code)); return; } - bool first = true; - for (auto& column : row) { - if (!first) - out(", "); - out("\"{}\"", column); - first = false; + 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; } - outln(); + + 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)); } } |