SQLStatement.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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/DeprecatedString.h>
  8. #include <AK/NonnullRefPtr.h>
  9. #include <LibCore/Object.h>
  10. #include <LibSQL/AST/AST.h>
  11. #include <LibSQL/Result.h>
  12. #include <LibSQL/ResultSet.h>
  13. #include <SQLServer/DatabaseConnection.h>
  14. #include <SQLServer/Forward.h>
  15. namespace SQLServer {
  16. class SQLStatement final : public Core::Object {
  17. C_OBJECT_ABSTRACT(SQLStatement)
  18. public:
  19. static SQL::ResultOr<NonnullRefPtr<SQLStatement>> create(DatabaseConnection&, StringView sql);
  20. ~SQLStatement() override = default;
  21. static RefPtr<SQLStatement> statement_for(int statement_id);
  22. int statement_id() const { return m_statement_id; }
  23. DatabaseConnection* connection() { return dynamic_cast<DatabaseConnection*>(parent()); }
  24. void execute();
  25. private:
  26. SQLStatement(DatabaseConnection&, NonnullRefPtr<SQL::AST::Statement> statement);
  27. bool should_send_result_rows() const;
  28. void next();
  29. void report_error(SQL::Result);
  30. int m_statement_id;
  31. size_t m_index { 0 };
  32. NonnullRefPtr<SQL::AST::Statement> m_statement;
  33. Optional<SQL::ResultSet> m_result {};
  34. };
  35. }