SQLClient.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibSQL/SQLClient.h>
  7. namespace SQL {
  8. SQLClient::~SQLClient()
  9. {
  10. }
  11. void SQLClient::connected(int connection_id)
  12. {
  13. if (on_connected)
  14. on_connected(connection_id);
  15. }
  16. void SQLClient::disconnected(int connection_id)
  17. {
  18. if (on_disconnected)
  19. on_disconnected(connection_id);
  20. }
  21. void SQLClient::connection_error(int connection_id, int code, String const& message)
  22. {
  23. if (on_connection_error)
  24. on_connection_error(connection_id, code, message);
  25. else
  26. warnln("Connection error for connection_id {}: {} ({})", connection_id, message, code);
  27. }
  28. void SQLClient::execution_error(int statement_id, int code, String const& message)
  29. {
  30. if (on_execution_error)
  31. on_execution_error(statement_id, code, message);
  32. else
  33. warnln("Execution error for statement_id {}: {} ({})", statement_id, message, code);
  34. }
  35. void SQLClient::execution_success(int statement_id, bool has_results, int created, int updated, int deleted)
  36. {
  37. if (on_execution_success)
  38. on_execution_success(statement_id, has_results, created, updated, deleted);
  39. else
  40. outln("{} row(s) created, {} updated, {} deleted", created, updated, deleted);
  41. }
  42. void SQLClient::next_result(int statement_id, Vector<String> const& row)
  43. {
  44. if (on_next_result) {
  45. on_next_result(statement_id, row);
  46. return;
  47. }
  48. bool first = true;
  49. for (auto& column : row) {
  50. if (!first)
  51. out(", ");
  52. out("\"{}\"", column);
  53. first = false;
  54. }
  55. outln();
  56. }
  57. void SQLClient::results_exhausted(int statement_id, int total_rows)
  58. {
  59. if (on_results_exhausted)
  60. on_results_exhausted(statement_id, total_rows);
  61. else
  62. outln("{} total row(s)", total_rows);
  63. }
  64. }