date and boolean data types added

This commit is contained in:
2021-08-06 22:46:48 +02:00
parent 4b95be1e31
commit 15a065c2aa
17 changed files with 1123 additions and 907 deletions

View File

@@ -56,8 +56,8 @@ namespace usql {
do {
std::string column_name;
ColumnType column_type;
int column_len{1};
bool column_nullable{true};
int column_len = 1;
bool column_nullable = true;
// column name
if (m_lexer.tokenType() != TokenType::identifier) {
@@ -82,8 +82,14 @@ namespace usql {
throw Exception("syntax error, expected int number");
}
m_lexer.skipToken(TokenType::close_paren);
} else if (m_lexer.tokenType() == TokenType::keyword_date) {
column_type = ColumnType::date_type;
m_lexer.nextToken();
} else if (m_lexer.tokenType() == TokenType::keyword_bool) {
column_type = ColumnType::bool_type;
m_lexer.nextToken();
} else {
throw Exception("syntax error, column type expected");
throw Exception("syntax error, column type expected, found " + m_lexer.currentToken().token_string);
}
if (m_lexer.tokenType() == TokenType::keyword_not) {
@@ -94,7 +100,7 @@ namespace usql {
m_lexer.nextToken();
}
cols_def.push_back( ColDefNode(column_name, column_type, column_order++, column_len, column_nullable));
cols_def.emplace_back(column_name, column_type, column_order++, column_len, column_nullable);
m_lexer.skipTokenOptional(TokenType::comma);
@@ -155,7 +161,7 @@ namespace usql {
m_lexer.skipToken(TokenType::open_paren);
do {
if (m_lexer.tokenType() != TokenType::identifier) { /* TODO handle error */ }
column_names.push_back(m_lexer.consumeCurrentToken().token_string);
column_names.emplace_back(m_lexer.consumeCurrentToken().token_string);
m_lexer.skipTokenOptional(TokenType::comma);
} while (m_lexer.tokenType() != TokenType::close_paren);
@@ -272,7 +278,7 @@ namespace usql {
std::vector<std::unique_ptr<Node>> values;
do {
cols_names.push_back(m_lexer.consumeCurrentToken().token_string);
cols_names.emplace_back(m_lexer.consumeCurrentToken().token_string);
m_lexer.skipToken(TokenType::equal);
std::unique_ptr<Node> left = Parser::parse_operand_node();
@@ -332,9 +338,9 @@ namespace usql {
auto token_type = m_lexer.tokenType();
std::string tokenString = m_lexer.consumeCurrentToken().token_string;
switch (token_type) {
case TokenType::int_number:
col_index = std::stoi(tokenString);
break;
case TokenType::int_number:
col_index = std::stoi(tokenString);
break;
default:
throw Exception("column index allowed in order by clause at this moment");
}
@@ -346,7 +352,7 @@ namespace usql {
asc = false;
}
order_cols.push_back(ColOrderNode{col_index, asc});
order_cols.emplace_back(col_index, asc);
m_lexer.skipTokenOptional(TokenType::comma);