1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +00:00
serenity/Userland/Services/SQLServer/SQLStatement.h
Timothy Flynn 6620f19979 LibSQL+SQLServer: Return the new Result class from statement executions
We can now TRY anything that returns a SQL::Result or an AK::Error.
2022-02-10 12:20:35 +00:00

44 lines
1.1 KiB
C++

/*
* 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)
public:
~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);
Optional<SQL::Result> parse();
void next();
void report_error();
int m_statement_id;
String m_sql;
size_t m_index { 0 };
RefPtr<SQL::AST::Statement> m_statement { nullptr };
Optional<SQL::Result> m_result {};
};
}