mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
grammar: Detect parse errors in primary key and unique constraints
When having a table definition like this, detect the parse errors in the table constraints correctly: CREATE TABLE test( a INTEGER, b TEXT, PRIMARY KEY(a ASC), -- ASC here UNIQUE(b COLLATE NOCASE) -- COLLATE here ); The next step is to actually parse and store this information.
This commit is contained in:
@@ -673,25 +673,38 @@ TablePtr CreateTableWalker::table()
|
||||
FieldVector fields;
|
||||
do
|
||||
{
|
||||
QString col = columnname(tc);
|
||||
antlr::RefAST indexed_column = tc->getFirstChild();
|
||||
|
||||
QString col = columnname(indexed_column);
|
||||
FieldPtr field = tab->field(tab->findField(col));
|
||||
fields.push_back(field);
|
||||
|
||||
tc = tc->getNextSibling();
|
||||
if(tc != antlr::nullAST
|
||||
&& (tc->getType() == sqlite3TokenTypes::ASC
|
||||
|| tc->getType() == sqlite3TokenTypes::DESC))
|
||||
indexed_column = indexed_column->getNextSibling();
|
||||
if(indexed_column != antlr::nullAST
|
||||
&& (indexed_column->getType() == sqlite3TokenTypes::ASC
|
||||
|| indexed_column->getType() == sqlite3TokenTypes::DESC))
|
||||
{
|
||||
// TODO save ASC / DESC information?
|
||||
tab->setFullyParsed(false);
|
||||
tc = tc->getNextSibling();
|
||||
indexed_column = indexed_column->getNextSibling();
|
||||
}
|
||||
|
||||
if(tc != antlr::nullAST && tc->getType() == sqlite3TokenTypes::AUTOINCREMENT)
|
||||
if(indexed_column != antlr::nullAST && indexed_column->getType() == sqlite3TokenTypes::COLLATE)
|
||||
{
|
||||
indexed_column = indexed_column->getNextSibling(); // COLLATE
|
||||
// TODO save collation name
|
||||
tab->setFullyParsed(false);
|
||||
indexed_column = indexed_column->getNextSibling(); // collation name
|
||||
}
|
||||
|
||||
if(indexed_column != antlr::nullAST && indexed_column->getType() == sqlite3TokenTypes::AUTOINCREMENT)
|
||||
{
|
||||
field->setAutoIncrement(true);
|
||||
tc = tc->getNextSibling();
|
||||
indexed_column = indexed_column->getNextSibling();
|
||||
}
|
||||
|
||||
tc = tc->getNextSibling(); // indexed column
|
||||
|
||||
while(tc != antlr::nullAST && tc->getType() == sqlite3TokenTypes::COMMA)
|
||||
{
|
||||
tc = tc->getNextSibling(); // skip ident and comma
|
||||
@@ -711,20 +724,32 @@ TablePtr CreateTableWalker::table()
|
||||
FieldVector fields;
|
||||
do
|
||||
{
|
||||
QString col = columnname(tc);
|
||||
antlr::RefAST indexed_column = tc->getFirstChild();
|
||||
|
||||
QString col = columnname(indexed_column);
|
||||
FieldPtr field = tab->field(tab->findField(col));
|
||||
fields.push_back(field);
|
||||
|
||||
tc = tc->getNextSibling();
|
||||
if(tc != antlr::nullAST
|
||||
&& (tc->getType() == sqlite3TokenTypes::ASC
|
||||
|| tc->getType() == sqlite3TokenTypes::DESC))
|
||||
indexed_column = indexed_column->getNextSibling();
|
||||
if(indexed_column != antlr::nullAST
|
||||
&& (indexed_column->getType() == sqlite3TokenTypes::ASC
|
||||
|| indexed_column->getType() == sqlite3TokenTypes::DESC))
|
||||
{
|
||||
// TODO save ASC / DESC information?
|
||||
tab->setFullyParsed(false);
|
||||
tc = tc->getNextSibling();
|
||||
indexed_column = indexed_column->getNextSibling();
|
||||
}
|
||||
|
||||
if(indexed_column != antlr::nullAST && indexed_column->getType() == sqlite3TokenTypes::COLLATE)
|
||||
{
|
||||
indexed_column = indexed_column->getNextSibling(); // COLLATE
|
||||
// TODO save collation name
|
||||
tab->setFullyParsed(false);
|
||||
indexed_column = indexed_column->getNextSibling(); // collation name
|
||||
}
|
||||
|
||||
tc = tc->getNextSibling(); // indexed column
|
||||
|
||||
while(tc != antlr::nullAST && tc->getType() == sqlite3TokenTypes::COMMA)
|
||||
{
|
||||
tc = tc->getNextSibling(); // skip ident and comma
|
||||
|
||||
Reference in New Issue
Block a user