mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-21 19:41:19 -06:00
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:
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
|
||||
@@ -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)");
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ private slots:
|
||||
void rowValues();
|
||||
void complexExpressions();
|
||||
void datetimeExpression();
|
||||
void extraParentheses();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user