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