Merge pull request #157 from ankushrayabhari/date_cast

Added support for casting to DATE
This commit is contained in:
mrks 2020-09-01 12:14:20 +02:00 committed by GitHub
commit 159c786cdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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

@ -737,4 +737,18 @@ TEST(WithClauseDouble) {
ASSERT_EQ(stmt->selectList->size(), 1); ASSERT_EQ(stmt->selectList->size(), 1);
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);
}