slightly better print, column alias supported

This commit is contained in:
2021-08-14 20:01:15 +02:00
parent 5201f32023
commit fb5098cf1d
9 changed files with 61 additions and 29 deletions

17
row.cpp
View File

@@ -164,14 +164,27 @@ int Row::compare(const Row &other) const {
return 0;
}
void Row::print(const std::vector<int> &col_char_sizes) {
void Row::print(const std::vector<ColDefNode> &col_defs) {
std::string out{"| "};
for (int ci = 0; ci < m_columns.size(); ci++) {
out.append(string_padd(m_columns[ci]->getStringValue(), col_char_sizes[ci], ' ', false) + " | ");
auto & col_def = col_defs[ci];
int col_size = print_get_column_size(col_def);
if (col_def.type==ColumnType::integer_type || col_def.type==ColumnType::float_type || col_def.type==ColumnType::bool_type)
out.append(string_padd(m_columns[ci]->getStringValue(), col_size, ' ', false) + " | ");
else
out.append(string_padd(m_columns[ci]->getStringValue(), col_size, ' ', true) + " | ");
}
std::cout << out << std::endl;
}
int Row::print_get_column_size(const ColDefNode &col_def) {
int col_size = col_def.type == ColumnType::varchar_type ? col_def.length :
col_def.type == ColumnType::float_type ? 20 : 10;
return col_size;
}
} // namespace