Added support for casting to DATE

This commit is contained in:
Ankush Rayabhari 2020-08-31 19:15:45 -07:00
parent 723b4175fd
commit 8d1c86f192
5 changed files with 982 additions and 969 deletions

File diff suppressed because it is too large Load Diff

View File

@ -562,6 +562,7 @@ column_type:
| CHAR '(' INTVAL ')' { $$ = ColumnType{DataType::CHAR, $3}; }
| TEXT { $$ = ColumnType{DataType::TEXT}; }
| DATETIME { $$ = ColumnType{DataType::DATETIME}; }
| DATE { $$ = ColumnType{DataType::DATE}; }
;
opt_column_nullable:

View File

@ -13,7 +13,8 @@ namespace hsql {
CHAR,
VARCHAR,
TEXT,
DATETIME
DATETIME,
DATE
};
// Represents the type of a column, e.g., FLOAT or VARCHAR(10)

View File

@ -57,6 +57,9 @@ namespace hsql {
case DataType::DATETIME:
stream << "DATETIME";
break;
case DataType::DATE:
stream << "DATE";
break;
}
return stream;
}

View File

@ -737,4 +737,18 @@ TEST(WithClauseDouble) {
ASSERT_EQ(stmt->selectList->size(), 1);
ASSERT_STREQ(stmt->selectList->at(0)->name, "nameA");
ASSERT_STREQ(stmt->fromTable->name, "a");
}
}
TEST(CastAsDate) {
TEST_PARSE_SINGLE_SQL(
"SELECT CAST(ID AS DATE) FROM TEST",
kStmtSelect,
SelectStatement,
result,
stmt);
ASSERT_TRUE(result.isValid());
ASSERT_EQ(1, stmt->selectList->size());
ASSERT_STREQ("CAST", stmt->selectList->front()->name);
ASSERT_EQ(DataType::DATE, stmt->selectList->front()->columnType.data_type);
}