2016-04-10 04:00:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <string>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Block.h>
|
2021-10-11 16:11:50 +00:00
|
|
|
#include <Processors/ISource.h>
|
2019-02-15 11:46:07 +00:00
|
|
|
#include <Core/ExternalResultDescription.h>
|
2021-05-07 10:37:11 +00:00
|
|
|
#include "ODBCConnectionFactory.h"
|
2016-04-10 04:00:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
/// Allows processing results of a query to ODBC source as a sequence of Blocks, simplifies chaining
|
2021-10-11 16:11:50 +00:00
|
|
|
class ODBCSource final : public ISource
|
2016-04-10 04:00:00 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-10-11 16:11:50 +00:00
|
|
|
ODBCSource(nanodbc::ConnectionHolderPtr connection, const std::string & query_str, const Block & sample_block, UInt64 max_block_size_);
|
2016-04-10 04:00:00 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getName() const override { return "ODBC"; }
|
2016-04-10 04:00:00 +00:00
|
|
|
|
|
|
|
private:
|
2021-03-22 11:40:29 +00:00
|
|
|
using QueryResult = std::shared_ptr<nanodbc::result>;
|
|
|
|
using ValueType = ExternalResultDescription::ValueType;
|
|
|
|
|
2021-10-11 16:11:50 +00:00
|
|
|
Chunk generate() override;
|
2016-04-10 04:00:00 +00:00
|
|
|
|
2021-10-11 16:11:50 +00:00
|
|
|
static void insertValue(IColumn & column, DataTypePtr data_type, ValueType type, nanodbc::result & row, size_t idx);
|
2021-03-22 11:40:29 +00:00
|
|
|
|
|
|
|
static void insertDefaultValue(IColumn & column, const IColumn & sample_column)
|
|
|
|
{
|
|
|
|
column.insertFrom(sample_column, 0);
|
|
|
|
}
|
2016-04-10 04:00:00 +00:00
|
|
|
|
2021-03-22 11:40:29 +00:00
|
|
|
Poco::Logger * log;
|
2019-02-10 16:55:12 +00:00
|
|
|
const UInt64 max_block_size;
|
2017-04-01 07:20:54 +00:00
|
|
|
ExternalResultDescription description;
|
2017-05-15 14:16:10 +00:00
|
|
|
|
2021-03-22 11:40:29 +00:00
|
|
|
nanodbc::result result;
|
|
|
|
String query;
|
2021-10-11 16:11:50 +00:00
|
|
|
bool is_finished = false;
|
2016-04-10 04:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|