//===----------------------------------------------------------------------===// // DuckDB // // duckdb/main/pending_query_result.hpp // // //===----------------------------------------------------------------------===// #pragma once #include "duckdb/main/query_result.hpp" #include "duckdb/common/enums/pending_execution_result.hpp" #include "duckdb/execution/executor.hpp" namespace duckdb { class ClientContext; class ClientContextLock; class PreparedStatementData; class PendingQueryResult : public BaseQueryResult { friend class ClientContext; public: static constexpr const QueryResultType TYPE = QueryResultType::PENDING_RESULT; public: DUCKDB_API PendingQueryResult(shared_ptr context, PreparedStatementData &statement, vector types, bool allow_stream_result); DUCKDB_API explicit PendingQueryResult(PreservedError error_message); DUCKDB_API ~PendingQueryResult(); public: //! Executes a single task within the query, returning whether or not the query is ready. //! If this returns RESULT_READY, the Execute function can be called to obtain a pointer to the result. //! If this returns RESULT_NOT_READY, the ExecuteTask function should be called again. //! If this returns EXECUTION_ERROR, an error occurred during execution. //! The error message can be obtained by calling GetError() on the PendingQueryResult. DUCKDB_API PendingExecutionResult ExecuteTask(); //! Returns the result of the query as an actual query result. //! This returns (mostly) instantly if ExecuteTask has been called until RESULT_READY was returned. DUCKDB_API unique_ptr Execute(); DUCKDB_API void Close(); private: shared_ptr context; bool allow_stream_result; private: void CheckExecutableInternal(ClientContextLock &lock); PendingExecutionResult ExecuteTaskInternal(ClientContextLock &lock); unique_ptr ExecuteInternal(ClientContextLock &lock); unique_ptr LockContext(); }; } // namespace duckdb