2017-01-21 04:24:28 +00:00
|
|
|
#include <DB/IO/WriteBuffer.h>
|
|
|
|
#include <DB/IO/WriteHelpers.h>
|
|
|
|
#include <DB/Core/Block.h>
|
2016-01-13 02:20:12 +00:00
|
|
|
#include <DB/DataStreams/ODBCDriverBlockOutputStream.h>
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2016-01-13 02:20:12 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
ODBCDriverBlockOutputStream::ODBCDriverBlockOutputStream(WriteBuffer & out_)
|
|
|
|
: out(out_) {}
|
|
|
|
|
2016-08-13 01:57:35 +00:00
|
|
|
void ODBCDriverBlockOutputStream::flush()
|
|
|
|
{
|
|
|
|
out.next();
|
|
|
|
}
|
2016-01-13 02:20:12 +00:00
|
|
|
|
|
|
|
void ODBCDriverBlockOutputStream::write(const Block & block)
|
|
|
|
{
|
|
|
|
size_t rows = block.rows();
|
|
|
|
size_t columns = block.columns();
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
/// Header.
|
2016-01-13 02:20:12 +00:00
|
|
|
if (is_first)
|
|
|
|
{
|
|
|
|
is_first = false;
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
/// Number of columns.
|
2016-01-13 02:20:12 +00:00
|
|
|
writeVarUInt(columns, out);
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
/// Names and types of columns.
|
2016-01-13 02:20:12 +00:00
|
|
|
for (size_t j = 0; j < columns; ++j)
|
|
|
|
{
|
2017-01-02 20:12:12 +00:00
|
|
|
const ColumnWithTypeAndName & col = block.getByPosition(j);
|
2016-01-13 02:20:12 +00:00
|
|
|
|
|
|
|
writeStringBinary(col.name, out);
|
|
|
|
writeStringBinary(col.type->getName(), out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String text_value;
|
|
|
|
for (size_t i = 0; i < rows; ++i)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < columns; ++j)
|
|
|
|
{
|
|
|
|
text_value.resize(0);
|
2017-01-02 20:12:12 +00:00
|
|
|
const ColumnWithTypeAndName & col = block.getByPosition(j);
|
2016-01-13 02:20:12 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
WriteBufferFromString text_out(text_value);
|
2016-02-16 16:39:39 +00:00
|
|
|
col.type->serializeText(*col.column.get(), i, text_out);
|
2016-01-13 02:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
writeStringBinary(text_value, out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|