2021-06-29 04:15:17 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-12-04 21:02:33 +03:00
|
|
|
#include <AK/DeprecatedString.h>
|
2021-06-29 04:15:17 +03:00
|
|
|
#include <AK/NonnullRefPtr.h>
|
2022-12-02 16:17:50 +03:00
|
|
|
#include <AK/Vector.h>
|
2021-06-29 04:15:17 +03:00
|
|
|
#include <LibCore/Object.h>
|
|
|
|
#include <LibSQL/AST/AST.h>
|
2022-02-10 00:02:49 +03:00
|
|
|
#include <LibSQL/Result.h>
|
2022-02-10 22:43:00 +03:00
|
|
|
#include <LibSQL/ResultSet.h>
|
2021-06-29 04:15:17 +03:00
|
|
|
#include <SQLServer/DatabaseConnection.h>
|
|
|
|
#include <SQLServer/Forward.h>
|
|
|
|
|
|
|
|
namespace SQLServer {
|
|
|
|
|
|
|
|
class SQLStatement final : public Core::Object {
|
2022-12-02 16:04:05 +03:00
|
|
|
C_OBJECT_ABSTRACT(SQLStatement)
|
2021-11-01 01:38:04 +03:00
|
|
|
|
|
|
|
public:
|
2022-12-02 16:04:05 +03:00
|
|
|
static SQL::ResultOr<NonnullRefPtr<SQLStatement>> create(DatabaseConnection&, StringView sql);
|
2021-06-29 04:15:17 +03:00
|
|
|
~SQLStatement() override = default;
|
|
|
|
|
2022-12-03 00:25:27 +03:00
|
|
|
static RefPtr<SQLStatement> statement_for(u64 statement_id);
|
|
|
|
u64 statement_id() const { return m_statement_id; }
|
2021-06-29 04:15:17 +03:00
|
|
|
DatabaseConnection* connection() { return dynamic_cast<DatabaseConnection*>(parent()); }
|
2022-12-03 01:14:56 +03:00
|
|
|
Optional<u64> execute(Vector<SQL::Value> placeholder_values);
|
2021-06-29 04:15:17 +03:00
|
|
|
|
|
|
|
private:
|
2022-12-02 16:04:05 +03:00
|
|
|
SQLStatement(DatabaseConnection&, NonnullRefPtr<SQL::AST::Statement> statement);
|
|
|
|
|
2022-02-10 22:43:00 +03:00
|
|
|
bool should_send_result_rows() const;
|
2022-12-03 01:14:56 +03:00
|
|
|
void next(u64 execution_id);
|
|
|
|
void report_error(SQL::Result, u64 execution_id);
|
2021-06-29 04:15:17 +03:00
|
|
|
|
2022-12-03 00:25:27 +03:00
|
|
|
u64 m_statement_id { 0 };
|
2021-06-29 04:15:17 +03:00
|
|
|
size_t m_index { 0 };
|
2022-12-03 01:14:56 +03:00
|
|
|
|
|
|
|
HashTable<u64> m_ongoing_executions;
|
|
|
|
u64 m_next_execution_id { 0 };
|
|
|
|
|
2022-12-02 16:04:05 +03:00
|
|
|
NonnullRefPtr<SQL::AST::Statement> m_statement;
|
2022-02-10 22:43:00 +03:00
|
|
|
Optional<SQL::ResultSet> m_result {};
|
2021-06-29 04:15:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|