grammar: Fix parsing of more complex expressions

See issue #1950.
This commit is contained in:
Martin Kleusberg
2019-08-01 11:14:30 +02:00
parent 263c28e6f4
commit 05181df8b8
4 changed files with 17 additions and 2 deletions
+1 -1
View File
@@ -2575,7 +2575,7 @@ void Sqlite3Parser::expr() {
astFactory->addASTChild(currentAST, tmp119_AST);
}
match(LPAREN);
subexpr();
expr();
if (inputState->guessing==0) {
astFactory->addASTChild( currentAST, returnAST );
}
+1 -1
View File
@@ -441,7 +441,7 @@ functionname
expr
:
( LPAREN (((subexpr (COMMA subexpr)+ RPAREN binaryoperator LPAREN subexpr (COMMA subexpr)+) | (expr)) RPAREN) ((AND | OR) expr)* )
| ( subexpr ((binaryoperator | AND | OR) (subexpr | LPAREN subexpr RPAREN) )* )
| ( subexpr ((binaryoperator | AND | OR) (subexpr | LPAREN expr RPAREN) )* )
;
subexpr
+14
View File
@@ -518,3 +518,17 @@ void TestTable::moduloOperator()
QCOMPARE(tab.fields.at(0).type(), "INTEGER");
QCOMPARE(tab.fields.at(0).defaultValue(), "(7%2)");
}
void TestTable::complexExpression()
{
std::string sql = "CREATE TABLE test(\n"
"uuid INTEGER DEFAULT (hex(randomblob(4))||'-'||hex(randomblob(2))||'-'||'4'||substr(hex(randomblob(2)),2)||'-'||substr('AB89',1+(abs(random())%4),1)||substr(hex(randomblob(2)),2)||'-'||hex(randomblob(6)))\n"
");";
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sql)));
QCOMPARE(tab.name(), "test");
QCOMPARE(tab.fields.at(0).name(), "uuid");
QCOMPARE(tab.fields.at(0).type(), "INTEGER");
QCOMPARE(tab.fields.at(0).defaultValue(), "(hex(randomblob(4))||'-'||hex(randomblob(2))||'-'||'4'||substr(hex(randomblob(2)),2)||'-'||substr('AB89',1+(abs(random())%4),1)||substr(hex(randomblob(2)),2)||'-'||hex(randomblob(6)))");
}
+1
View File
@@ -38,6 +38,7 @@ private slots:
void datetimeExpression();
void extraParentheses();
void moduloOperator();
void complexExpression();
};
#endif