Skip to content

Commit 18bcbf1

Browse files
techeeMKleusberg
authored andcommitted
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 "(".
1 parent c5e9197 commit 18bcbf1

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/sqlitetypes.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,28 @@ void CreateTableWalker::parsecolumn(Table* table, antlr::RefAST c)
935935
c = c->getNextSibling(); //type?
936936
if(c != antlr::nullAST && c->getType() == sqlite3TokenTypes::TYPE_NAME)
937937
{
938-
type = concatTextAST(c->getFirstChild(), true);
938+
antlr::RefAST t = c->getFirstChild();
939+
940+
if(t != antlr::nullAST)
941+
{
942+
type.clear();
943+
}
944+
945+
while(t != antlr::nullAST)
946+
{
947+
int thisType = t->getType();
948+
type.append(textAST(t));
949+
t = t->getNextSibling();
950+
if(t != antlr::nullAST)
951+
{
952+
int nextType = t->getType();
953+
if(nextType != sqlite3TokenTypes::LPAREN && nextType != sqlite3TokenTypes::RPAREN &&
954+
thisType != sqlite3TokenTypes::LPAREN)
955+
{
956+
type.append(" ");
957+
}
958+
}
959+
}
939960
c = c->getNextSibling();
940961
}
941962

src/tests/testsqlobjects.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void TestTable::parseSQL()
128128

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

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

0 commit comments

Comments
 (0)