slightly better print, column alias supported
This commit is contained in:
13
table.cpp
13
table.cpp
@@ -155,14 +155,15 @@ long Table::string_to_long(const std::string &s) {
|
||||
void Table::print() {
|
||||
std::string out{"| "};
|
||||
std::string out2{"+-"};
|
||||
std::vector<int> col_char_sizes{};
|
||||
|
||||
for(const auto& col_def : m_col_defs) {
|
||||
int col_size = col_def.type == ColumnType::varchar_type ? col_def.length :
|
||||
col_def.type == ColumnType::float_type ? 20 : 10;
|
||||
col_char_sizes.push_back(col_size);
|
||||
int col_size = Row::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(col_def.name, col_size, ' ', false) + " | ");
|
||||
else
|
||||
out.append(string_padd(col_def.name, col_size, ' ', true) + " | ");
|
||||
|
||||
out.append(string_padd(col_def.name, col_size, ' ', true) + " | ");
|
||||
out2.append(string_padd("-", col_size, '-', true) + "-+ ");
|
||||
}
|
||||
|
||||
@@ -171,7 +172,7 @@ void Table::print() {
|
||||
std::cout << out2 << std::endl;
|
||||
|
||||
for(auto& row : m_rows) {
|
||||
row.print(col_char_sizes);
|
||||
row.print(m_col_defs);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user