better table print, order by/offset/limit improvements

This commit is contained in:
2021-08-01 10:40:47 +02:00
parent 34e432d031
commit 70c036f08c
17 changed files with 3037 additions and 60 deletions

View File

@@ -1,6 +1,7 @@
#include "table.h"
#include "csvreader.h"
#include "ml_string.h"
namespace usql {
@@ -8,7 +9,16 @@ namespace usql {
Table::Table(const std::string name, const std::vector<ColDefNode> columns) {
m_name = name;
m_col_defs = columns;
m_rows.clear();
m_rows.reserve(16);
}
Table::Table(const Table &other) {
m_name = other.m_name;
m_col_defs = other.m_col_defs;
m_rows.reserve(other.m_rows.size());
for(const Row& orig_row : other.m_rows) {
add_copy_of_row(orig_row);
}
}
ColDefNode Table::get_column_def(const std::string &col_name) {
@@ -96,18 +106,26 @@ int Table::load_csv_string(const std::string &content) {
}
void Table::print() {
std::cout << "** " << m_name << " **" << std::endl;
for (auto row : m_rows) {
row.print();
}
}
std::string out{"| "};
std::string out2{"+-"};
std::vector<int> col_char_sizes{};
Table::Table(const Table &other) {
m_name = other.m_name;
m_col_defs = other.m_col_defs;
for(const Row& orig_row : other.m_rows) {
add_copy_of_row(orig_row);
for(auto col_def : m_col_defs) {
int col_size = col_def.type == ColumnType::varchar_type ? col_def.length : 10;
col_char_sizes.push_back(col_size);
out.append(string_padd(col_def.name, col_size, ' ', true) + " | ");
out2.append(string_padd("-", col_size, '-', true) + "-+ ");
}
// std::cout << "** " << m_name << " **" << std::endl;
std::cout << out << std::endl;
std::cout << out2 << std::endl;
for(auto row : m_rows) {
row.print(col_char_sizes);
}
std::cout << std::endl;
}
void Table::add_row(const Row &row) {