grammar: Correctly parse subexpressions in parentheses

This fixes parsing for table definitions like this:

CREATE TABLE a(
    x INT DEFAULT(5 + (1))
);

See issue #1950.
This commit is contained in:
Martin Kleusberg
2019-08-01 10:53:51 +02:00
parent 05e2defe33
commit 55b3f6378f
4 changed files with 620 additions and 522 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -440,7 +440,7 @@ functionname
expr
:
( LPAREN (((subexpr (COMMA subexpr)+ RPAREN binaryoperator LPAREN subexpr (COMMA subexpr)+) | (expr)) RPAREN) ((AND | OR) expr)* )
| ( subexpr ((binaryoperator | AND | OR) subexpr )* )
| ( subexpr ((binaryoperator | AND | OR) (subexpr | LPAREN subexpr RPAREN) )* )
;
subexpr

View File

@@ -490,3 +490,17 @@ void TestTable::datetimeExpression()
QCOMPARE(tab.fields.at(0).type(), "INTEGER");
QCOMPARE(tab.fields.at(0).defaultValue(), "(DATETIME(CURRENT_TIMESTAMP,'LOCALTIME'))");
}
void TestTable::extraParentheses()
{
std::string sql = "CREATE TABLE test(\n"
"xy INTEGER DEFAULT (1 + (5) - 4)\n"
");";
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sql)));
QCOMPARE(tab.name(), "test");
QCOMPARE(tab.fields.at(0).name(), "xy");
QCOMPARE(tab.fields.at(0).type(), "INTEGER");
QCOMPARE(tab.fields.at(0).defaultValue(), "(1+(5)-4)");
}

View File

@@ -36,6 +36,7 @@ private slots:
void rowValues();
void complexExpressions();
void datetimeExpression();
void extraParentheses();
};
#endif