Skip to content

Commit df291aa

Browse files
committed
grammar: Fix whitespace problems
When using a "x IS NOT NULL" expression in a statement our parser was generating something like "xIS NOTNULL". This was especially a problem because the table looked like it parsed correctly but actually contained a faulty expression. So when modifying the table you would get unexpected error messages, or worse silent errors introduced into your table. Also add a test case for this and for commit e7ba79f. See issue #1969.
1 parent e7ba79f commit df291aa

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/sql/sqlitetypes.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,9 @@ std::string concatExprAST(antlr::RefAST t)
701701
case sqlite3TokenTypes::BETWEEN:
702702
expr += " " + textAST(t) + " ";
703703
break;
704+
case sqlite3TokenTypes::IS:
704705
case sqlite3TokenTypes::NOT:
706+
case sqlite3TokenTypes::NULL_T:
705707
expr += " " + textAST(t);
706708
break;
707709
default:

src/tests/testsqlobjects.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,10 @@ void TestTable::moduloOperator()
522522
void TestTable::complexExpression()
523523
{
524524
std::string sql = "CREATE TABLE test(\n"
525-
"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"
525+
"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"
526+
"a INTEGER,\n"
527+
"b INTEGER,\n"
528+
"CHECK((a = 'S' AND b IS NOT NULL) OR (a IN ('A', 'P')))"
526529
");";
527530

528531
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sql)));
@@ -531,4 +534,8 @@ void TestTable::complexExpression()
531534
QCOMPARE(tab.fields.at(0).name(), "uuid");
532535
QCOMPARE(tab.fields.at(0).type(), "INTEGER");
533536
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)))");
537+
538+
auto c = tab.constraints({}, sqlb::Constraint::CheckConstraintType);
539+
QCOMPARE(c.size(), 1);
540+
QCOMPARE(std::dynamic_pointer_cast<sqlb::CheckConstraint>(c.at(0))->expression(), "(a='S' AND b IS NOT NULL) OR (a IN ('A','P'))");
534541
}

0 commit comments

Comments
 (0)