| 1 | //===----------------------------------------------------------------------===// | 
|---|---|
| 2 | // DuckDB | 
| 3 | // | 
| 4 | // duckdb/main/pending_query_result.hpp | 
| 5 | // | 
| 6 | // | 
| 7 | //===----------------------------------------------------------------------===// | 
| 8 | |
| 9 | #pragma once | 
| 10 | |
| 11 | #include "duckdb/main/query_result.hpp" | 
| 12 | #include "duckdb/common/enums/pending_execution_result.hpp" | 
| 13 | #include "duckdb/execution/executor.hpp" | 
| 14 | |
| 15 | namespace duckdb { | 
| 16 | class ClientContext; | 
| 17 | class ClientContextLock; | 
| 18 | class PreparedStatementData; | 
| 19 | |
| 20 | class PendingQueryResult : public BaseQueryResult { | 
| 21 | friend class ClientContext; | 
| 22 | |
| 23 | public: | 
| 24 | static constexpr const QueryResultType TYPE = QueryResultType::PENDING_RESULT; | 
| 25 | |
| 26 | public: | 
| 27 | DUCKDB_API PendingQueryResult(shared_ptr<ClientContext> context, PreparedStatementData &statement, | 
| 28 | vector<LogicalType> types, bool allow_stream_result); | 
| 29 | DUCKDB_API explicit PendingQueryResult(PreservedError error_message); | 
| 30 | DUCKDB_API ~PendingQueryResult(); | 
| 31 | |
| 32 | public: | 
| 33 | //! Executes a single task within the query, returning whether or not the query is ready. | 
| 34 | //! If this returns RESULT_READY, the Execute function can be called to obtain a pointer to the result. | 
| 35 | //! If this returns RESULT_NOT_READY, the ExecuteTask function should be called again. | 
| 36 | //! If this returns EXECUTION_ERROR, an error occurred during execution. | 
| 37 | //! The error message can be obtained by calling GetError() on the PendingQueryResult. | 
| 38 | DUCKDB_API PendingExecutionResult ExecuteTask(); | 
| 39 | |
| 40 | //! Returns the result of the query as an actual query result. | 
| 41 | //! This returns (mostly) instantly if ExecuteTask has been called until RESULT_READY was returned. | 
| 42 | DUCKDB_API unique_ptr<QueryResult> Execute(); | 
| 43 | |
| 44 | DUCKDB_API void Close(); | 
| 45 | |
| 46 | private: | 
| 47 | shared_ptr<ClientContext> context; | 
| 48 | bool allow_stream_result; | 
| 49 | |
| 50 | private: | 
| 51 | void CheckExecutableInternal(ClientContextLock &lock); | 
| 52 | |
| 53 | PendingExecutionResult ExecuteTaskInternal(ClientContextLock &lock); | 
| 54 | unique_ptr<QueryResult> ExecuteInternal(ClientContextLock &lock); | 
| 55 | unique_ptr<ClientContextLock> LockContext(); | 
| 56 | }; | 
| 57 | |
| 58 | } // namespace duckdb | 
| 59 | 
