| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <string> |
| 4 | #include <Core/Block.h> |
| 5 | #include <DataStreams/IBlockInputStream.h> |
| 6 | #include <mysqlxx/PoolWithFailover.h> |
| 7 | #include <mysqlxx/Query.h> |
| 8 | #include <Core/ExternalResultDescription.h> |
| 9 | |
| 10 | |
| 11 | namespace DB |
| 12 | { |
| 13 | /// Allows processing results of a MySQL query as a sequence of Blocks, simplifies chaining |
| 14 | class MySQLBlockInputStream final : public IBlockInputStream |
| 15 | { |
| 16 | public: |
| 17 | MySQLBlockInputStream( |
| 18 | const mysqlxx::PoolWithFailover::Entry & entry_, |
| 19 | const std::string & query_str, |
| 20 | const Block & sample_block, |
| 21 | const UInt64 max_block_size_, |
| 22 | const bool auto_close_ = false); |
| 23 | |
| 24 | String getName() const override { return "MySQL"; } |
| 25 | |
| 26 | Block getHeader() const override { return description.sample_block.cloneEmpty(); } |
| 27 | |
| 28 | private: |
| 29 | Block readImpl() override; |
| 30 | |
| 31 | mysqlxx::PoolWithFailover::Entry entry; |
| 32 | mysqlxx::Query query; |
| 33 | mysqlxx::UseQueryResult result; |
| 34 | const UInt64 max_block_size; |
| 35 | const bool auto_close; |
| 36 | ExternalResultDescription description; |
| 37 | }; |
| 38 | |
| 39 | } |
| 40 |