SQLClient.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #pragma once
  8. #include <AK/Platform.h>
  9. #include <LibIPC/ConnectionToServer.h>
  10. #include <LibSQL/Result.h>
  11. #include <SQLServer/SQLClientEndpoint.h>
  12. #include <SQLServer/SQLServerEndpoint.h>
  13. namespace SQL {
  14. class SQLClient
  15. : public IPC::ConnectionToServer<SQLClientEndpoint, SQLServerEndpoint>
  16. , public SQLClientEndpoint {
  17. IPC_CLIENT_CONNECTION(SQLClient, "/tmp/session/%sid/portal/sql"sv)
  18. public:
  19. #if !defined(AK_OS_SERENITY)
  20. static ErrorOr<NonnullRefPtr<SQLClient>> launch_server_and_create_client(Vector<String> candidate_server_paths);
  21. #endif
  22. virtual ~SQLClient() = default;
  23. Function<void(u64, u64, SQLErrorCode, DeprecatedString const&)> on_execution_error;
  24. Function<void(u64, u64, bool, size_t, size_t, size_t)> on_execution_success;
  25. Function<void(u64, u64, Span<SQL::Value const>)> on_next_result;
  26. Function<void(u64, u64, size_t)> on_results_exhausted;
  27. private:
  28. explicit SQLClient(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
  29. : IPC::ConnectionToServer<SQLClientEndpoint, SQLServerEndpoint>(*this, move(socket))
  30. {
  31. }
  32. virtual void execution_success(u64 statement_id, u64 execution_id, bool has_results, size_t created, size_t updated, size_t deleted) override;
  33. virtual void next_result(u64 statement_id, u64 execution_id, Vector<SQL::Value> const&) override;
  34. virtual void results_exhausted(u64 statement_id, u64 execution_id, size_t total_rows) override;
  35. virtual void execution_error(u64 statement_id, u64 execution_id, SQLErrorCode const& code, DeprecatedString const& message) override;
  36. };
  37. }