SQLStatement.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/NonnullRefPtr.h>
  8. #include <AK/String.h>
  9. #include <LibCore/Object.h>
  10. #include <LibSQL/AST/AST.h>
  11. #include <LibSQL/SQLResult.h>
  12. #include <SQLServer/DatabaseConnection.h>
  13. #include <SQLServer/Forward.h>
  14. namespace SQLServer {
  15. class SQLStatement final : public Core::Object {
  16. C_OBJECT(SQLStatement)
  17. ~SQLStatement() override = default;
  18. static RefPtr<SQLStatement> statement_for(int statement_id);
  19. int statement_id() const { return m_statement_id; }
  20. String const& sql() const { return m_sql; }
  21. DatabaseConnection* connection() { return dynamic_cast<DatabaseConnection*>(parent()); }
  22. void execute();
  23. private:
  24. SQLStatement(DatabaseConnection&, String sql);
  25. Optional<SQL::SQLError> parse();
  26. void next();
  27. void report_error(SQL::SQLError);
  28. int m_statement_id;
  29. String m_sql;
  30. size_t m_index { 0 };
  31. RefPtr<SQL::AST::Statement> m_statement { nullptr };
  32. RefPtr<SQL::SQLResult> m_result { nullptr };
  33. };
  34. }