Fix segfault on printing cast/extract exprs
- Additionally, fix printing logic
This commit is contained in:
parent
159c786cdb
commit
b6dfe73051
|
@ -218,7 +218,7 @@ Expr* Expr::makeInOperator(Expr* expr, SelectStatement* select) {
|
|||
}
|
||||
|
||||
Expr* Expr::makeExtract(DatetimeField datetimeField, Expr* expr) {
|
||||
Expr* e = new Expr(kExprFunctionRef);
|
||||
Expr* e = new Expr(kExprExtract);
|
||||
e->name = strdup("EXTRACT");
|
||||
e->datetimeField = datetimeField;
|
||||
e->expr = expr;
|
||||
|
@ -226,7 +226,7 @@ Expr* Expr::makeExtract(DatetimeField datetimeField, Expr* expr) {
|
|||
}
|
||||
|
||||
Expr* Expr::makeCast(Expr* expr, ColumnType columnType) {
|
||||
Expr* e = new Expr(kExprFunctionRef);
|
||||
Expr* e = new Expr(kExprCast);
|
||||
e->name = strdup("CAST");
|
||||
e->columnType = columnType;
|
||||
e->expr = expr;
|
||||
|
|
|
@ -27,7 +27,8 @@ enum ExprType {
|
|||
kExprHint,
|
||||
kExprArray,
|
||||
kExprArrayIndex,
|
||||
kExprDatetimeField
|
||||
kExprExtract,
|
||||
kExprCast
|
||||
};
|
||||
|
||||
// Operator types. These are important for expressions of type kExprOperator.
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace hsql {
|
|||
void printAlias(Alias* alias, uintmax_t numIndent);
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const OperatorType& op);
|
||||
std::ostream& operator<<(std::ostream& os, const DatetimeField& op);
|
||||
|
||||
std::string indent(uintmax_t numIndent) {
|
||||
return std::string(numIndent, '\t');
|
||||
|
@ -32,6 +33,12 @@ namespace hsql {
|
|||
void inprint(const OperatorType& op, uintmax_t numIndent) {
|
||||
std::cout << indent(numIndent) << op << std::endl;
|
||||
}
|
||||
void inprint(const ColumnType& colType, uintmax_t numIndent) {
|
||||
std::cout << indent(numIndent) << colType << std::endl;
|
||||
}
|
||||
void inprint(const DatetimeField& colType, uintmax_t numIndent) {
|
||||
std::cout << indent(numIndent) << colType << std::endl;
|
||||
}
|
||||
|
||||
void printTableRefInfo(TableRef* table, uintmax_t numIndent) {
|
||||
switch (table->type) {
|
||||
|
@ -118,6 +125,16 @@ namespace hsql {
|
|||
inprint(expr->name, numIndent);
|
||||
for (Expr* e : *expr->exprList) printExpression(e, numIndent + 1);
|
||||
break;
|
||||
case kExprExtract:
|
||||
inprint(expr->name, numIndent);
|
||||
inprint(expr->datetimeField, numIndent + 1);
|
||||
printExpression(expr->expr, numIndent + 1);
|
||||
break;
|
||||
case kExprCast:
|
||||
inprint(expr->name, numIndent);
|
||||
inprint(expr->columnType, numIndent + 1);
|
||||
printExpression(expr->expr, numIndent + 1);
|
||||
break;
|
||||
case kExprOperator:
|
||||
printOperatorExpression(expr, numIndent);
|
||||
break;
|
||||
|
@ -372,4 +389,23 @@ namespace hsql {
|
|||
}
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const DatetimeField& datetime) {
|
||||
static const std::map<const DatetimeField, const std::string> operatorToToken = {
|
||||
{kDatetimeNone, "None"},
|
||||
{kDatetimeSecond, "SECOND"},
|
||||
{kDatetimeMinute, "MINUTE"},
|
||||
{kDatetimeHour, "HOUR"},
|
||||
{kDatetimeDay, "DAY"},
|
||||
{kDatetimeMonth, "MONTH"},
|
||||
{kDatetimeYear, "YEAR"}
|
||||
};
|
||||
|
||||
const auto found = operatorToToken.find(datetime);
|
||||
if (found == operatorToToken.cend()) {
|
||||
return os << static_cast<uint64_t>(datetime);
|
||||
} else {
|
||||
return os << (*found).second;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace hsql
|
||||
|
|
Loading…
Reference in New Issue