/* * Copyright (c) 2021, Jan de Visser * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include namespace SQLServer { class SQLStatement final : public RefCounted { public: static SQL::ResultOr> create(DatabaseConnection&, StringView sql); static RefPtr statement_for(SQL::StatementID statement_id); SQL::StatementID statement_id() const { return m_statement_id; } DatabaseConnection& connection() { return m_connection; } Optional execute(Vector placeholder_values); void ready_for_next_result(SQL::ExecutionID); private: SQLStatement(DatabaseConnection&, NonnullRefPtr statement); bool should_send_result_rows(SQL::ResultSet const& result) const; void report_error(SQL::Result, SQL::ExecutionID execution_id); DatabaseConnection& m_connection; SQL::StatementID m_statement_id { 0 }; struct Execution { SQL::ResultSet result; size_t result_size { 0 }; }; HashMap m_ongoing_executions; SQL::ExecutionID m_next_execution_id { 0 }; NonnullRefPtr m_statement; }; }