some more TODOs resolved
This commit is contained in:
parent
0f586aab8a
commit
fc0ce36e8d
|
|
@ -18,27 +18,27 @@ namespace usql {
|
|||
}
|
||||
|
||||
|
||||
int CsvReader::parseCSV(const std::string &filename, std::vector<ColDefNode> &cols_def, Table& table) {
|
||||
int CsvReader::parseCSV(const std::string &filename, std::vector<ColDefNode> &cols_def, Table &table) {
|
||||
|
||||
std::vector<ColDefNode> cdefs;
|
||||
cdefs.reserve(cols_def.size());
|
||||
for(auto & cd : cols_def) {
|
||||
for (auto &cd : cols_def) {
|
||||
cdefs.emplace_back(table.get_column_def(cd.name));
|
||||
}
|
||||
|
||||
int row_cnt = 0;
|
||||
bool inQuote(false);
|
||||
std::string field;
|
||||
std::string csvSource;
|
||||
int row_cnt = 0;
|
||||
bool inQuote(false);
|
||||
std::string field;
|
||||
std::string csvSource;
|
||||
|
||||
std::vector<std::string> line;
|
||||
line.reserve(32);
|
||||
|
||||
std::fstream newfile;
|
||||
newfile.open(filename, std::ios::in);
|
||||
/// if (newfile.is_open()){ //checking whether the file is open
|
||||
/// if (newfile.is_open()){ //checking whether the file is open
|
||||
|
||||
while(getline(newfile, csvSource)){
|
||||
while (getline(newfile, csvSource)) {
|
||||
if (skip_header && !header_skiped) {
|
||||
header_skiped = true;
|
||||
continue;
|
||||
|
|
@ -69,13 +69,13 @@ namespace usql {
|
|||
|
||||
field.clear();
|
||||
line.clear();
|
||||
|
||||
// DEBUG if (row_cnt > 1000) break;
|
||||
}
|
||||
|
||||
newfile.close();
|
||||
newfile.close();
|
||||
|
||||
return row_cnt;
|
||||
}
|
||||
}
|
||||
|
||||
int CsvReader::parseCSV2(const std::string &csvSource, std::vector<ColDefNode> &cols_def, Table& table) {
|
||||
int row_cnt = 0;
|
||||
|
|
|
|||
20
main.cpp
20
main.cpp
|
|
@ -79,6 +79,7 @@ void close_linenoise() {
|
|||
linenoiseHistorySave(history_file.c_str());
|
||||
}
|
||||
|
||||
|
||||
void repl() {
|
||||
std::string code;
|
||||
std::string input;
|
||||
|
|
@ -124,19 +125,19 @@ void repl() {
|
|||
close_linenoise();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
std::vector<std::string> sql_commands{
|
||||
void debug() {
|
||||
std::__1::vector<std::string> sql_commands{
|
||||
// "create table ticker ( tablee varchar(5) not null, permaticker integer, ticker varchar(10) not null, name varchar(256) not null, exchange varchar(32), isdelisted boolean, category varchar(32), cusips varchar(256), siccode integer, sicsector varchar(256), sicindustry varchar(256), famasector varchar(256), famaindustry varchar(256), sector varchar(128), industry varchar(128), scalemarketcap varchar(64), scalerevenue varchar(64), relatedtickers varchar(128), currency varchar(3), location varchar(64), lastupdated date, firstadded date, firstpricedate date, lastpricedate date, firstquarter date, lastquarter date, secfilings varchar(256), companysite varchar(256))",
|
||||
// "load ticker from '/Users/vaclavt/Library/Mobile Documents/com~apple~CloudDocs/Development/usql/tickers.csv')",
|
||||
// "select * from ticker where ticker = 'WFC' and tablee = 'SF1'",
|
||||
// "set 'DATE_FORMAT' = '%Y-%m-%d'",
|
||||
// "show 'DATE_FORMAT'",
|
||||
// "create table sf1 ( ticker varchar(8), dimension varchar(3), calendar_date date, date_key date, report_period date, last_updated date, accoci float, assets float, assetsavg float, assetsc float, assetsnc float, assetturnover float, bvps float, capex float, cashneq float, cashnequsd float, cor float, consolinc float, currentratio float, de float, debt float, debtc float, debtnc float, debtusd float, deferredrev float, depamor float, deposits float, divyield float, dps float, ebit float, ebitda float, ebitdamargin float, ebitdausd float, ebitusd float, ebt float, eps float, epsdil float, epsusd float, equity float, equityavg float, equityusd float, ev float, evebit float, evebitda float, fcf float, fcfps float, fxusd float, gp float, grossmargin float, intangibles float, intexp float, invcap float, invcapavg float, inventory float, investments float, investmentsc float, investmentsnc float, liabilities float, liabilitiesc float, liabilitiesnc float, marketcap float, ncf float, ncfbus float, ncfcommon float, ncfdebt float, ncfdiv float, ncff float, ncfi float, ncfinv float, ncfo float, ncfx float, netinc float, netinccmn float, netinccmnusd float, netincdis float, netincnci float, netmargin float, opex float, opinc float, payables float, payoutratio float, pb float, pe float, pe1 float, ppnenet float, prefdivis float, price float, ps float, ps1 float, receivables float, retearn float, revenue float, revenueusd float, rnd float, roa float, roe float, roic float, ros float, sbcomp float, sgna float, sharefactor float, sharesbas float, shareswa float, shareswadil float, sps float, tangibles float, taxassets float, taxexp float, taxliabilities float, tbvps float, workingcapital float)",
|
||||
// "load sf1 from '/tmp/sf1.csv')",
|
||||
"set 'DATE_FORMAT' = '%Y-%m-%d'",
|
||||
"show 'DATE_FORMAT'",
|
||||
"create table sf1 ( ticker varchar(8), dimension varchar(3), calendar_date date, date_key date, report_period date, last_updated date, accoci float, assets float, assetsavg float, assetsc float, assetsnc float, assetturnover float, bvps float, capex float, cashneq float, cashnequsd float, cor float, consolinc float, currentratio float, de float, debt float, debtc float, debtnc float, debtusd float, deferredrev float, depamor float, deposits float, divyield float, dps float, ebit float, ebitda float, ebitdamargin float, ebitdausd float, ebitusd float, ebt float, eps float, epsdil float, epsusd float, equity float, equityavg float, equityusd float, ev float, evebit float, evebitda float, fcf float, fcfps float, fxusd float, gp float, grossmargin float, intangibles float, intexp float, invcap float, invcapavg float, inventory float, investments float, investmentsc float, investmentsnc float, liabilities float, liabilitiesc float, liabilitiesnc float, marketcap float, ncf float, ncfbus float, ncfcommon float, ncfdebt float, ncfdiv float, ncff float, ncfi float, ncfinv float, ncfo float, ncfx float, netinc float, netinccmn float, netinccmnusd float, netincdis float, netincnci float, netmargin float, opex float, opinc float, payables float, payoutratio float, pb float, pe float, pe1 float, ppnenet float, prefdivis float, price float, ps float, ps1 float, receivables float, retearn float, revenue float, revenueusd float, rnd float, roa float, roe float, roic float, ros float, sbcomp float, sgna float, sharefactor float, sharesbas float, shareswa float, shareswadil float, sps float, tangibles float, taxassets float, taxexp float, taxliabilities float, tbvps float, workingcapital float)",
|
||||
"load sf1 from '/tmp/sf1.csv')",
|
||||
// "select * from sf1 where ticker = 'WFC'",
|
||||
// "select ticker, dimension, calendar_date, eps, dps from sf1 where (ticker = 'AIG' or ticker = 'AI') and dimension = 'MRY' order by 3 desc",
|
||||
// "select ticker, dimension, calendar_date, eps, dps from sf1 where (ticker = 'AIG' or ticker = 'AI') and (dimension = 'MRY' or dimension = 'MRQ') order by 3 desc",
|
||||
// "select ticker, dimension, calendar_date, eps, dps from sf1 where (ticker = 'AIG' or ticker = 'WFC') and dimension = 'MRY' order by 3 desc",
|
||||
"select ticker, dimension, calendar_date, eps, dps from sf1 where (ticker = 'AIG' or ticker = 'WFC') and dimension = 'MRY' order by 3 desc",
|
||||
"create table a (i integer not null, s varchar(64), f float null, d date null, b boolean)",
|
||||
"insert into a (i, s, b) values(1, upper('one'), 'Y')",
|
||||
"insert into a (i, s, b) values(1 + 10000, upper('one'), 'Y')",
|
||||
|
|
@ -195,6 +196,11 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
std::cout << std::endl << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
debug();
|
||||
|
||||
// repl();
|
||||
|
||||
|
|
|
|||
19
parser.cpp
19
parser.cpp
|
|
@ -444,7 +444,7 @@ namespace usql {
|
|||
std::vector<std::unique_ptr<Node>> pars;
|
||||
|
||||
m_lexer.skipToken(TokenType::open_paren);
|
||||
while (m_lexer.tokenType() != TokenType::close_paren) { // TODO handle errors
|
||||
while (m_lexer.tokenType() != TokenType::close_paren && m_lexer.tokenType() != TokenType::eof) {
|
||||
pars.push_back(parse_value());
|
||||
m_lexer.skipTokenOptional(TokenType::comma);
|
||||
}
|
||||
|
|
@ -521,22 +521,5 @@ namespace usql {
|
|||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<Node> Parser::parse_relational_expression() {
|
||||
auto left = parse_value();
|
||||
|
||||
if (!Lexer::isRelationalOperator(m_lexer.tokenType()))
|
||||
{
|
||||
if (left->node_type != NodeType::relational_operator)
|
||||
throw Exception("syntax error in relational operation");
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
auto operation = parse_relational_operator();
|
||||
auto right = parse_value();
|
||||
|
||||
return std::make_unique<RelationalOperatorNode>(operation, std::move(left), std::move(right));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
|
|
|||
4
parser.h
4
parser.h
|
|
@ -368,10 +368,8 @@ namespace usql {
|
|||
LogicalOperatorType parse_logical_operator();
|
||||
ArithmeticalOperatorType parse_arithmetical_operator();
|
||||
|
||||
std::unique_ptr<Node> parse_relational_expression();
|
||||
|
||||
private:
|
||||
Lexer m_lexer;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
|||
195
row.cpp
195
row.cpp
|
|
@ -1,120 +1,126 @@
|
|||
|
||||
#include <ml_string.h>
|
||||
#include "row.h"
|
||||
|
||||
namespace usql {
|
||||
|
||||
int ColNullValue::compare(ColValue * other) {
|
||||
return other->isNull() ? 0 : -1; // null goes to end
|
||||
}
|
||||
int ColNullValue::compare(ColValue *other) {
|
||||
return other->isNull() ? 0 : -1; // null goes to end
|
||||
}
|
||||
|
||||
int ColIntegerValue::compare(ColValue * other) {
|
||||
long r = m_integer - other->getIntValue();
|
||||
return other->isNull() ? 1 : r > 0 ? 1 : r == 0 ? 0 : -1;
|
||||
}
|
||||
int ColIntegerValue::compare(ColValue *other) {
|
||||
long r = m_integer - other->getIntValue();
|
||||
return other->isNull() ? 1 : r > 0 ? 1 : r == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
int ColDoubleValue::compare(ColValue * other) {
|
||||
if (other->isNull()) return 1; // null goes to end
|
||||
int ColDoubleValue::compare(ColValue *other) {
|
||||
if (other->isNull()) return 1; // null goes to end
|
||||
|
||||
double c = m_double - other->getDoubleValue();
|
||||
return c < 0 ? -1 : c == 0.0 ? 0 : 1;
|
||||
}
|
||||
double c = m_double - other->getDoubleValue();
|
||||
return c < 0 ? -1 : c == 0.0 ? 0 : 1;
|
||||
}
|
||||
|
||||
int ColStringValue::compare(ColValue * other) {
|
||||
return other->isNull() ? 1 : m_string.compare(other->getStringValue()); // null goes to end
|
||||
}
|
||||
int ColStringValue::compare(ColValue *other) {
|
||||
return other->isNull() ? 1 : m_string.compare(other->getStringValue()); // null goes to end
|
||||
}
|
||||
|
||||
int ColDateValue::compare(ColValue * other) {
|
||||
int ColDateValue::compare(ColValue *other) {
|
||||
long r = m_date - other->getIntValue();
|
||||
return other->isNull() ? 1 : r > 0 ? 1 : r == 0 ? 0 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
int ColBooleanValue::compare(ColValue * other) {
|
||||
if (other->isNull()) return 1; // null goes to end
|
||||
int ColBooleanValue::compare(ColValue *other) {
|
||||
if (other->isNull()) return 1; // null goes to end
|
||||
|
||||
return m_bool==other->getBoolValue() ? 0 : m_bool && !other->getBoolValue() ? -1 : 1; // true first
|
||||
}
|
||||
return m_bool == other->getBoolValue() ? 0 : m_bool && !other->getBoolValue() ? -1 : 1; // true first
|
||||
}
|
||||
|
||||
Row::Row(int cols_count) {
|
||||
m_columns.reserve(cols_count);
|
||||
for (int i = 0; i < cols_count; i++) {
|
||||
m_columns.push_back(std::make_unique<ColNullValue>());
|
||||
}
|
||||
}
|
||||
Row::Row(int cols_count) {
|
||||
m_columns.reserve(cols_count);
|
||||
for (int i = 0; i < cols_count; i++) {
|
||||
m_columns.emplace_back(std::make_unique<ColNullValue>());
|
||||
}
|
||||
}
|
||||
|
||||
Row::Row(const Row &other) {
|
||||
m_columns.reserve(other.m_columns.size());
|
||||
// PERF here we first set cols null and then immediately replace it
|
||||
for (int i = 0; i < other.m_columns.size(); i++) {
|
||||
m_columns.emplace_back(std::make_unique<ColNullValue>());
|
||||
}
|
||||
Row::Row(const Row &other) {
|
||||
m_columns.reserve(other.m_columns.size());
|
||||
// PERF here we first set cols null and then immediately replace it
|
||||
for (int i = 0; i < other.m_columns.size(); i++) {
|
||||
m_columns.emplace_back(std::make_unique<ColNullValue>());
|
||||
}
|
||||
|
||||
for (int i = 0; i < other.m_columns.size(); i++) {
|
||||
for (int i = 0; i < other.m_columns.size(); i++) {
|
||||
if (other.m_columns[i]->isNull())
|
||||
continue; // for null NOP
|
||||
continue; // for null NOP
|
||||
|
||||
ColumnType col_type = other.m_columns[i]->getColType();
|
||||
switch (col_type) {
|
||||
ColumnType col_type = other.m_columns[i]->getColType();
|
||||
switch (col_type) {
|
||||
case ColumnType::integer_type :
|
||||
setIntColumnValue(i, (static_cast<ColIntegerValue *>(other.m_columns[i].get())->getIntValue()));
|
||||
setIntColumnValue(i,
|
||||
(static_cast<ColIntegerValue *>(other.m_columns[i].get())->getIntValue()));
|
||||
break;
|
||||
case ColumnType::float_type :
|
||||
setFloatColumnValue(i, (static_cast<ColDoubleValue *>(other.m_columns[i].get())->getDoubleValue()));
|
||||
setFloatColumnValue(i,
|
||||
(static_cast<ColDoubleValue *>(other.m_columns[i].get())->getDoubleValue()));
|
||||
break;
|
||||
case ColumnType::varchar_type :
|
||||
setStringColumnValue(i, (static_cast<ColStringValue *>(other.m_columns[i].get())->getStringValue()));
|
||||
setStringColumnValue(i,
|
||||
(static_cast<ColStringValue *>(other.m_columns[i].get())->getStringValue()));
|
||||
break;
|
||||
case ColumnType::date_type :
|
||||
setDateColumnValue(i, (static_cast<ColDateValue *>(other.m_columns[i].get())->getDateValue()));
|
||||
setDateColumnValue(i,
|
||||
(static_cast<ColDateValue *>(other.m_columns[i].get())->getDateValue()));
|
||||
break;
|
||||
case ColumnType::bool_type :
|
||||
setBoolColumnValue(i, (static_cast<ColBooleanValue *>(other.m_columns[i].get())->getBoolValue()));
|
||||
break;
|
||||
setBoolColumnValue(i,
|
||||
(static_cast<ColBooleanValue *>(other.m_columns[i].get())->getBoolValue()));
|
||||
break;
|
||||
default:
|
||||
throw Exception("unsupported column type");
|
||||
throw Exception("unsupported column type");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Row &Row::operator=(Row other) {
|
||||
std::swap(m_columns, other.m_columns);
|
||||
return *this;
|
||||
}
|
||||
Row &Row::operator=(Row other) {
|
||||
std::swap(m_columns, other.m_columns);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Row::setColumnNull(int col_index) {
|
||||
void Row::setColumnNull(int col_index) {
|
||||
m_columns[col_index] = std::make_unique<ColNullValue>();
|
||||
}
|
||||
}
|
||||
|
||||
void Row::setIntColumnValue(int col_index, long value) {
|
||||
m_columns[col_index] = std::make_unique<ColIntegerValue>(value);
|
||||
}
|
||||
void Row::setIntColumnValue(int col_index, long value) {
|
||||
m_columns[col_index] = std::make_unique<ColIntegerValue>(value);
|
||||
}
|
||||
|
||||
void Row::setFloatColumnValue(int col_index, double value) {
|
||||
m_columns[col_index] = std::make_unique<ColDoubleValue>(value);
|
||||
}
|
||||
void Row::setFloatColumnValue(int col_index, double value) {
|
||||
m_columns[col_index] = std::make_unique<ColDoubleValue>(value);
|
||||
}
|
||||
|
||||
void Row::setStringColumnValue(int col_index, const std::string &value) {
|
||||
m_columns[col_index] = std::make_unique<ColStringValue>(value);
|
||||
}
|
||||
void Row::setStringColumnValue(int col_index, const std::string &value) {
|
||||
m_columns[col_index] = std::make_unique<ColStringValue>(value);
|
||||
}
|
||||
|
||||
void Row::setDateColumnValue(int col_index, long value) {
|
||||
m_columns[col_index] = std::make_unique<ColDateValue>(value);
|
||||
}
|
||||
void Row::setDateColumnValue(int col_index, long value) {
|
||||
m_columns[col_index] = std::make_unique<ColDateValue>(value);
|
||||
}
|
||||
|
||||
void Row::setDateColumnValue(int col_index, const std::string &value) {
|
||||
void Row::setDateColumnValue(int col_index, const std::string &value) {
|
||||
m_columns[col_index] = std::make_unique<ColDateValue>(Settings::string_to_date(value));
|
||||
}
|
||||
}
|
||||
|
||||
void Row::setBoolColumnValue(int col_index, bool value) {
|
||||
m_columns[col_index] = std::make_unique<ColBooleanValue>(value);
|
||||
}
|
||||
void Row::setBoolColumnValue(int col_index, bool value) {
|
||||
m_columns[col_index] = std::make_unique<ColBooleanValue>(value);
|
||||
}
|
||||
|
||||
void Row::setBoolColumnValue(int col_index, const std::string &value) {
|
||||
bool v = (value=="Y" || value=="1");
|
||||
m_columns[col_index] = std::make_unique<ColBooleanValue>(v);
|
||||
}
|
||||
void Row::setBoolColumnValue(int col_index, const std::string &value) {
|
||||
bool v = (value == "Y" || value == "1");
|
||||
m_columns[col_index] = std::make_unique<ColBooleanValue>(v);
|
||||
}
|
||||
|
||||
void Row::setColumnValue(ColDefNode *col_def, ColValue *col_value) {
|
||||
void Row::setColumnValue(ColDefNode *col_def, ColValue *col_value) {
|
||||
if (!col_value->isNull()) {
|
||||
if (col_def->type == ColumnType::integer_type)
|
||||
setIntColumnValue(col_def->order, col_value->getIntValue());
|
||||
|
|
@ -129,7 +135,7 @@ namespace usql {
|
|||
} else {
|
||||
setColumnNull(col_def->order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Row::setColumnValue(ColDefNode *col_def, ValueNode *col_value) {
|
||||
if (!col_value->isNull()) {
|
||||
|
|
@ -150,25 +156,22 @@ void Row::setColumnValue(ColDefNode *col_def, ValueNode *col_value) {
|
|||
}
|
||||
}
|
||||
|
||||
int Row::compare(const Row & other) const {
|
||||
for (int ci = 0; ci < m_columns.size(); ci++) {
|
||||
int cmp = m_columns[ci]->compare(other.ith_column(ci));
|
||||
if (cmp != 0) return cmp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Row::print(const std::vector<int> & col_char_sizes) {
|
||||
std::string out{"| "};
|
||||
|
||||
for (int ci = 0; ci < m_columns.size(); ci++) {
|
||||
auto value = m_columns[ci]->getStringValue();
|
||||
|
||||
// TODO use rpad string function handle len
|
||||
out.append(value + std::string(col_char_sizes[ci] - value.size(), ' ') + " | ");
|
||||
}
|
||||
|
||||
std::cout << out << std::endl;
|
||||
}
|
||||
|
||||
int Row::compare(const Row &other) const {
|
||||
for (int ci = 0; ci < m_columns.size(); ci++) {
|
||||
int cmp = m_columns[ci]->compare(other.ith_column(ci));
|
||||
if (cmp != 0) return cmp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Row::print(const std::vector<int> &col_char_sizes) {
|
||||
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) + " | ");
|
||||
}
|
||||
|
||||
std::cout << out << std::endl;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include "table.h"
|
||||
#include "csvreader.h"
|
||||
#include "ml_string.h"
|
||||
|
|
@ -93,7 +92,7 @@ int Table::load_csv_file(const std::string &filename) {
|
|||
if (infile.good()) {
|
||||
std::string sLine;
|
||||
std::getline(infile, sLine);
|
||||
line_size = sLine.size();
|
||||
line_size = (int)sLine.size();
|
||||
}
|
||||
infile.close();
|
||||
|
||||
|
|
@ -113,7 +112,7 @@ void Table::create_row_from_vector(const std::vector<ColDefNode> &colDefs, const
|
|||
Row& new_row = create_empty_row();
|
||||
|
||||
// copy values
|
||||
for (size_t i = 0; i < std::min<int>(columns_count(), csv_line.size()); i++) {
|
||||
for (int i = 0; i < std::min<int>(columns_count(), csv_line.size()); i++) {
|
||||
const ColDefNode & col_def = colDefs[i];
|
||||
|
||||
if (csv_line[i].empty()) {
|
||||
|
|
|
|||
4
table.h
4
table.h
|
|
@ -15,8 +15,8 @@ namespace usql {
|
|||
ColDefNode get_column_def(const std::string &col_name);
|
||||
ColDefNode get_column_def(int col_index);
|
||||
|
||||
int columns_count() const { return m_col_defs.size(); }; // TODO size_t type?
|
||||
int rows_count() const { return m_rows.size(); };
|
||||
int columns_count() const { return (int) m_col_defs.size(); };
|
||||
size_t rows_count() const { return m_rows.size(); };
|
||||
|
||||
Row& create_empty_row();
|
||||
void commit_row(const Row &row);
|
||||
|
|
|
|||
16
usql.cpp
16
usql.cpp
|
|
@ -138,11 +138,12 @@ std::unique_ptr<Table> USql::execute_show(ShowNode &node) {
|
|||
}
|
||||
|
||||
std::unique_ptr<Table> USql::execute_insert_into_table(InsertIntoTableNode &node) {
|
||||
// TODO check column names.size = values.size
|
||||
|
||||
// find table
|
||||
Table *table_def = find_table(node.table_name);
|
||||
|
||||
if (node.cols_names.size() != node.cols_values.size())
|
||||
throw Exception("Incorrect number of values");
|
||||
|
||||
// prepare empty new_row
|
||||
Row& new_row = table_def->create_empty_row();
|
||||
|
||||
|
|
@ -168,8 +169,9 @@ std::unique_ptr<Table> USql::execute_select(SelectFromTableNode &node) {
|
|||
// expand *
|
||||
if (node.cols_names->size()==1 && node.cols_names->operator[](0).name == "*") {
|
||||
node.cols_names->clear();
|
||||
node.cols_names->reserve(table->columns_count());
|
||||
for(auto col : table->m_col_defs) {
|
||||
node.cols_names->push_back(SelectColNode{std::move(std::make_unique<DatabaseValueNode>(col.name)), col.name});
|
||||
node.cols_names->emplace_back(SelectColNode{std::make_unique<DatabaseValueNode>(col.name), col.name});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -179,7 +181,7 @@ std::unique_ptr<Table> USql::execute_select(SelectFromTableNode &node) {
|
|||
std::vector<int> source_table_col_index{};
|
||||
|
||||
for (int i = 0; i < node.cols_names->size(); i++) {
|
||||
auto [ src_tbl_col_index, rst_tbl_col_def ] = get_column_definition(table, &node.cols_names->operator[](i), i);
|
||||
auto [src_tbl_col_index, rst_tbl_col_def] = get_column_definition(table, &node.cols_names->operator[](i), i);
|
||||
|
||||
source_table_col_index.push_back(src_tbl_col_index);
|
||||
result_tbl_col_defs.push_back(rst_tbl_col_def);
|
||||
|
|
@ -297,7 +299,7 @@ std::unique_ptr<Table> USql::execute_delete(DeleteFromTableNode &node) {
|
|||
Table *table = find_table(node.table_name);
|
||||
|
||||
// execute access plan
|
||||
int affected_rows = table->rows_count();
|
||||
auto affected_rows = table->rows_count();
|
||||
|
||||
table->m_rows.erase(
|
||||
std::remove_if(table->m_rows.begin(), table->m_rows.end(),
|
||||
|
|
@ -565,13 +567,13 @@ std::unique_ptr<ValueNode> USql::eval_arithmetic_operator(ColumnType outType, Ar
|
|||
throw Exception("implement me!!");
|
||||
}
|
||||
}
|
||||
// TODO date node should support addition and substraction
|
||||
// TODO date node should support addition and subtraction
|
||||
|
||||
throw Exception("implement me!!");
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Table> USql::create_stmt_result_table(long code, const std::string &text, long affected_rows) {
|
||||
std::unique_ptr<Table> USql::create_stmt_result_table(long code, const std::string &text, size_t affected_rows) {
|
||||
std::vector<ColDefNode> result_tbl_col_defs{};
|
||||
result_tbl_col_defs.emplace_back("code", ColumnType::integer_type, 0, 1, false);
|
||||
result_tbl_col_defs.emplace_back("desc", ColumnType::varchar_type, 1, 48, false);
|
||||
|
|
|
|||
2
usql.h
2
usql.h
|
|
@ -46,7 +46,7 @@ private:
|
|||
static std::unique_ptr<ValueNode> eval_arithmetic_operator(ColumnType outType, ArithmeticalOperatorNode &node, Table *table, Row &row) ;
|
||||
|
||||
|
||||
static std::unique_ptr<Table> create_stmt_result_table(long code, const std::string &text, long affected_rows);
|
||||
static std::unique_ptr<Table> create_stmt_result_table(long code, const std::string &text, size_t affected_rows);
|
||||
static std::tuple<int, ColDefNode> get_column_definition(Table *table, SelectColNode *select_col_node, int col_order) ;
|
||||
Table *find_table(const std::string &name);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue