Skip to content

Commit

Permalink
Fix extra spaces in type definitions with parentheses
Browse files Browse the repository at this point in the history
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 22, 2017
1 parent c5e9197 commit 18bcbf1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/sqlitetypes.cpp
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/testsqlobjects.cpp
Expand Up @@ -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());
Expand Down

0 comments on commit 18bcbf1

Please sign in to comment.