SQLClient.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibSQL/SQLClient.h>
  8. namespace SQL {
  9. void SQLClient::execution_error(u64 statement_id, u64 execution_id, SQLErrorCode const& code, DeprecatedString const& message)
  10. {
  11. if (on_execution_error)
  12. on_execution_error(statement_id, execution_id, code, message);
  13. else
  14. warnln("Execution error for statement_id {}: {} ({})", statement_id, message, to_underlying(code));
  15. }
  16. void SQLClient::execution_success(u64 statement_id, u64 execution_id, bool has_results, size_t created, size_t updated, size_t deleted)
  17. {
  18. if (on_execution_success)
  19. on_execution_success(statement_id, execution_id, has_results, created, updated, deleted);
  20. else
  21. outln("{} row(s) created, {} updated, {} deleted", created, updated, deleted);
  22. }
  23. void SQLClient::next_result(u64 statement_id, u64 execution_id, Vector<SQL::Value> const& row)
  24. {
  25. if (on_next_result) {
  26. on_next_result(statement_id, execution_id, row);
  27. return;
  28. }
  29. bool first = true;
  30. for (auto& column : row) {
  31. if (!first)
  32. out(", ");
  33. out("\"{}\"", column);
  34. first = false;
  35. }
  36. outln();
  37. }
  38. void SQLClient::results_exhausted(u64 statement_id, u64 execution_id, size_t total_rows)
  39. {
  40. if (on_results_exhausted)
  41. on_results_exhausted(statement_id, execution_id, total_rows);
  42. else
  43. outln("{} total row(s)", total_rows);
  44. }
  45. }