drop table added
This commit is contained in:
39
table.cpp
39
table.cpp
@@ -1,5 +1,7 @@
|
||||
|
||||
#include "table.h"
|
||||
#include "csvreader.h"
|
||||
|
||||
|
||||
namespace usql {
|
||||
|
||||
@@ -49,6 +51,43 @@ std::string Table::csv_string() {
|
||||
return out_string;
|
||||
}
|
||||
|
||||
int Table::load_csv_string(const std::string &content) {
|
||||
int row_cnt = 0;
|
||||
|
||||
CsvReader csvparser{};
|
||||
auto csv = csvparser.parseCSV(content);
|
||||
|
||||
std::vector<ColDefNode> &colDefs = m_col_defs;
|
||||
|
||||
for (auto it = csv.begin() + 1; it != csv.end(); ++it) {
|
||||
std::vector<std::string> csv_line = *it;
|
||||
|
||||
// prepare empty new_row
|
||||
Row new_row = create_empty_row();
|
||||
|
||||
// copy values
|
||||
for (size_t i = 0; i < columns_count(); i++) {
|
||||
ColDefNode col_def = get_column_def(colDefs[i].name);
|
||||
|
||||
// TODO validate value
|
||||
if (col_def.type == ColumnType::integer_type) {
|
||||
new_row.setColumnValue(col_def.order, std::stol(csv_line[i]));
|
||||
} else if (col_def.type == ColumnType::float_type) {
|
||||
new_row.setColumnValue(col_def.order, std::stof(csv_line[i]));
|
||||
} else {
|
||||
new_row.setColumnValue(col_def.order, csv_line[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// append new_row
|
||||
add_row(new_row);
|
||||
|
||||
row_cnt++;
|
||||
}
|
||||
|
||||
return row_cnt;
|
||||
}
|
||||
|
||||
void Table::print() {
|
||||
std::cout << "** " << m_name << " **" << std::endl;
|
||||
for (auto row : m_rows) {
|
||||
|
||||
Reference in New Issue
Block a user