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}; } | CHAR '(' INTVAL ')' { $$ = ColumnType{DataType::CHAR, $3}; }
| TEXT { $$ = ColumnType{DataType::TEXT}; } | TEXT { $$ = ColumnType{DataType::TEXT}; }
| DATETIME { $$ = ColumnType{DataType::DATETIME}; } | DATETIME { $$ = ColumnType{DataType::DATETIME}; }
| DATE { $$ = ColumnType{DataType::DATE}; }
; ;
opt_column_nullable: opt_column_nullable:

View File

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

View File

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

View File

@ -738,3 +738,17 @@ TEST(WithClauseDouble) {
ASSERT_STREQ(stmt->selectList->at(0)->name, "nameA"); ASSERT_STREQ(stmt->selectList->at(0)->name, "nameA");
ASSERT_STREQ(stmt->fromTable->name, "a"); 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);
}