1#pragma once
2
3#include <string>
4#include <Core/Block.h>
5#include <Processors/Formats/IOutputFormat.h>
6#include <Formats/FormatSettings.h>
7
8
9namespace DB
10{
11class WriteBuffer;
12
13
14/** A data format designed to simplify the implementation of the ODBC driver.
15 * ODBC driver is designed to be build for different platforms without dependencies from the main code,
16 * so the format is made that way so that it can be as easy as possible to parse it.
17 * A header is displayed with the required information.
18 * The data is then output in the order of the rows. Each value is displayed as follows: length in Int32 format (-1 for NULL), then data in text form.
19 */
20class ODBCDriver2BlockOutputFormat final : public IOutputFormat
21{
22public:
23 ODBCDriver2BlockOutputFormat(WriteBuffer & out_, const Block & header_, const FormatSettings & format_settings_);
24
25 String getName() const override { return "ODBCDriver2BlockOutputFormat"; }
26
27 void consume(Chunk) override;
28 void consumeTotals(Chunk) override;
29 void finalize() override;
30
31 std::string getContentType() const override
32 {
33 return "application/octet-stream";
34 }
35
36private:
37 const FormatSettings format_settings;
38 bool prefix_written = false;
39
40 void writePrefixIfNot()
41 {
42 if (!prefix_written)
43 writePrefix();
44
45 prefix_written = true;
46 }
47
48 void writeRow(const Block & header, const Columns & columns, size_t row_idx, std::string & buffer);
49 void write(Chunk chunk, PortKind port_kind);
50 void writePrefix();
51};
52
53
54
55}
56