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
|
|
|
|
|
|
|
|
#include <AK/NonnullRefPtr.h>
|
|
|
|
#include <AK/String.h>
|
|
|
|
#include <LibCore/Object.h>
|
|
|
|
#include <LibSQL/AST/AST.h>
|
|
|
|
#include <LibSQL/SQLResult.h>
|
|
|
|
#include <SQLServer/DatabaseConnection.h>
|
|
|
|
#include <SQLServer/Forward.h>
|
|
|
|
|
|
|
|
namespace SQLServer {
|
|
|
|
|
|
|
|
class SQLStatement final : public Core::Object {
|
|
|
|
C_OBJECT(SQLStatement)
|
2021-11-01 01:38:04 +03:00
|
|
|
|
|
|
|
public:
|
2021-06-29 04:15:17 +03:00
|
|
|
~SQLStatement() override = default;
|
|
|
|
|
|
|
|
static RefPtr<SQLStatement> statement_for(int statement_id);
|
|
|
|
int statement_id() const { return m_statement_id; }
|
|
|
|
String const& sql() const { return m_sql; }
|
|
|
|
DatabaseConnection* connection() { return dynamic_cast<DatabaseConnection*>(parent()); }
|
|
|
|
void execute();
|
|
|
|
|
|
|
|
private:
|
|
|
|
SQLStatement(DatabaseConnection&, String sql);
|
2022-02-09 23:57:57 +03:00
|
|
|
Optional<SQL::Result> parse();
|
2021-06-29 04:15:17 +03:00
|
|
|
void next();
|
2022-02-09 23:57:57 +03:00
|
|
|
void report_error();
|
2021-06-29 04:15:17 +03:00
|
|
|
|
|
|
|
int m_statement_id;
|
|
|
|
String m_sql;
|
|
|
|
size_t m_index { 0 };
|
|
|
|
RefPtr<SQL::AST::Statement> m_statement { nullptr };
|
2022-02-09 23:57:57 +03:00
|
|
|
Optional<SQL::Result> m_result {};
|
2021-06-29 04:15:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|