a bit of refactoring

This commit is contained in:
2021-12-18 14:52:33 +01:00
parent 906df74847
commit eebb270f47
11 changed files with 96 additions and 96 deletions

View File

@@ -1,6 +1,5 @@
#include "usql.h"
#include "exception.h"
#include "ml_date.h"
#include "ml_string.h"
#include <algorithm>
@@ -175,6 +174,7 @@ std::unique_ptr<ValueNode> USql::eval_function_value_node(Table *table, Row &row
}
// at this moment no functions without parameter(s) or first param can be null
// TODO exception here or better parsing
if (evaluatedPars.empty() || evaluatedPars[0]->isNull())
return std::make_unique<NullValueNode>();
@@ -194,13 +194,11 @@ std::unique_ptr<ValueNode> USql::eval_function_value_node(Table *table, Row &row
bool USql::eval_logical_operator(LogicalOperatorNode &node, Table *pTable, Row &row) {
//bool left = eval_relational_operator(static_cast<const RelationalOperatorNode &>(*node.left), pTable, row);
bool left = eval_where(&(*node.left), pTable, row);
if ((node.op == LogicalOperatorType::and_operator && !left) || (node.op == LogicalOperatorType::or_operator && left))
return left;
//bool right = eval_relational_operator(static_cast<const RelationalOperatorNode &>(*node.right), pTable, row);
bool right = eval_where(&(*node.right), pTable, row);
return right;
}
@@ -218,8 +216,8 @@ std::unique_ptr<ValueNode> USql::eval_arithmetic_operator(ColumnType outType, Ar
return std::make_unique<NullValueNode>();
if (outType == ColumnType::float_type) {
double l = ((ValueNode *) left.get())->getDoubleValue();
double r = ((ValueNode *) right.get())->getDoubleValue();
double l = left->getDoubleValue();
double r = right->getDoubleValue();
switch (node.op) {
case ArithmeticalOperatorType::plus_operator:
return std::make_unique<DoubleValueNode>(l + r);
@@ -230,12 +228,12 @@ std::unique_ptr<ValueNode> USql::eval_arithmetic_operator(ColumnType outType, Ar
case ArithmeticalOperatorType::divide_operator:
return std::make_unique<DoubleValueNode>(l / r);
default:
throw Exception("implement me!!");
throw Exception("eval_arithmetic_operator, float type implement me!!");
}
} else if (outType == ColumnType::integer_type) {
long l = ((ValueNode *) left.get())->getIntegerValue();
long r = ((ValueNode *) right.get())->getIntegerValue();
long l = left->getIntegerValue();
long r = right->getIntegerValue();
switch (node.op) {
case ArithmeticalOperatorType::plus_operator:
return std::make_unique<IntValueNode>(l + r);
@@ -246,22 +244,22 @@ std::unique_ptr<ValueNode> USql::eval_arithmetic_operator(ColumnType outType, Ar
case ArithmeticalOperatorType::divide_operator:
return std::make_unique<IntValueNode>(l / r);
default:
throw Exception("implement me!!");
throw Exception("eval_arithmetic_operator, integer type implement me!!");
}
} else if (outType == ColumnType::varchar_type) {
std::string l = ((ValueNode *) left.get())->getStringValue();
std::string r = ((ValueNode *) right.get())->getStringValue();
std::string l = left->getStringValue();
std::string r = right->getStringValue();
switch (node.op) {
case ArithmeticalOperatorType::plus_operator:
return std::make_unique<StringValueNode>(l + r);
default:
throw Exception("implement me!!");
throw Exception("eval_arithmetic_operator, varchar type implement me!!");
}
}
// TODO date node should support addition and subtraction
throw Exception("implement me!!");
throw Exception("eval_arithmetic_operator, implement me!!");
}
Table *USql::find_table(const std::string &name) const {