2021-06-28 21:15:17 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
|
2022-03-04 13:22:31 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2021-06-28 21:15:17 -04:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-02-25 12:27:37 +02:00
|
|
|
#include <LibIPC/ConnectionToServer.h>
|
2022-12-02 16:25:27 -05:00
|
|
|
#include <LibSQL/Result.h>
|
2021-06-28 21:15:17 -04:00
|
|
|
#include <SQLServer/SQLClientEndpoint.h>
|
|
|
|
|
#include <SQLServer/SQLServerEndpoint.h>
|
|
|
|
|
|
|
|
|
|
namespace SQL {
|
|
|
|
|
|
|
|
|
|
class SQLClient
|
2022-02-25 12:27:37 +02:00
|
|
|
: public IPC::ConnectionToServer<SQLClientEndpoint, SQLServerEndpoint>
|
2021-06-28 21:15:17 -04:00
|
|
|
, public SQLClientEndpoint {
|
2022-09-06 00:04:06 -06:00
|
|
|
IPC_CLIENT_CONNECTION(SQLClient, "/tmp/session/%sid/portal/sql"sv)
|
2022-03-04 13:22:31 -07:00
|
|
|
virtual ~SQLClient() = default;
|
2021-06-28 21:15:17 -04:00
|
|
|
|
2022-12-02 16:25:27 -05:00
|
|
|
Function<void(u64, DeprecatedString const&)> on_connected;
|
|
|
|
|
Function<void(u64)> on_disconnected;
|
|
|
|
|
Function<void(u64, SQLErrorCode, DeprecatedString const&)> on_connection_error;
|
|
|
|
|
Function<void(u64, SQLErrorCode, DeprecatedString const&)> on_execution_error;
|
|
|
|
|
Function<void(u64, bool, size_t, size_t, size_t)> on_execution_success;
|
|
|
|
|
Function<void(u64, Vector<DeprecatedString> const&)> on_next_result;
|
|
|
|
|
Function<void(u64, size_t)> on_results_exhausted;
|
2021-06-28 21:15:17 -04:00
|
|
|
|
|
|
|
|
private:
|
2022-01-14 13:12:49 +00:00
|
|
|
SQLClient(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
|
2022-02-25 12:27:37 +02:00
|
|
|
: IPC::ConnectionToServer<SQLClientEndpoint, SQLServerEndpoint>(*this, move(socket))
|
2021-06-28 21:15:17 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-02 16:25:27 -05:00
|
|
|
virtual void connected(u64 connection_id, DeprecatedString const& connected_to_database) override;
|
|
|
|
|
virtual void connection_error(u64 connection_id, SQLErrorCode const& code, DeprecatedString const& message) override;
|
|
|
|
|
virtual void execution_success(u64 statement_id, bool has_results, size_t created, size_t updated, size_t deleted) override;
|
|
|
|
|
virtual void next_result(u64 statement_id, Vector<DeprecatedString> const&) override;
|
|
|
|
|
virtual void results_exhausted(u64 statement_id, size_t total_rows) override;
|
|
|
|
|
virtual void execution_error(u64 statement_id, SQLErrorCode const& code, DeprecatedString const& message) override;
|
|
|
|
|
virtual void disconnected(u64 connection_id) override;
|
2021-06-28 21:15:17 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|