Permalink
Browse files

Fix extra spaces in type definitions with parentheses

At the moment space is inserted between all tokens from which a type
consists. This adds extra spaces to types like VARCHAR(5) which become
"VARCHAR ( 5 )" which causes problems in some applications.

This patch modifies the way tokens are concatenated for a type. It makes
sure that the extra space isn't inserted before "(" and ")" and also
after "(".
  • Loading branch information...
techee authored and MKleusberg committed Sep 20, 2017
1 parent c5e9197 commit 18bcbf138f3f351e21eaf2db108f89e558943c45
Showing with 23 additions and 2 deletions.
  1. +22 −1 src/sqlitetypes.cpp
  2. +1 −1 src/tests/testsqlobjects.cpp
@@ -935,7 +935,28 @@ void CreateTableWalker::parsecolumn(Table* table, antlr::RefAST c)
c = c->getNextSibling(); //type?
if(c != antlr::nullAST && c->getType() == sqlite3TokenTypes::TYPE_NAME)
{
type = concatTextAST(c->getFirstChild(), true);
antlr::RefAST t = c->getFirstChild();

if(t != antlr::nullAST)
{
type.clear();
}

while(t != antlr::nullAST)
{
int thisType = t->getType();
type.append(textAST(t));
t = t->getNextSibling();
if(t != antlr::nullAST)
{
int nextType = t->getType();
if(nextType != sqlite3TokenTypes::LPAREN && nextType != sqlite3TokenTypes::RPAREN &&
thisType != sqlite3TokenTypes::LPAREN)
{
type.append(" ");
}
}
}
c = c->getNextSibling();
}

@@ -128,7 +128,7 @@ void TestTable::parseSQL()

QVERIFY(tab.fields().at(0)->type() == "integer");
QVERIFY(tab.fields().at(1)->type() == "text");
QCOMPARE(tab.fields().at(2)->type(), QString("VARCHAR ( 255 )"));
QCOMPARE(tab.fields().at(2)->type(), QString("VARCHAR(255)"));

FieldVector pk = tab.primaryKey();
QVERIFY(tab.fields().at(0)->autoIncrement());

0 comments on commit 18bcbf1

Please sign in to comment.