mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
grammar: Parse named primary keys in column constraints
Parse named primary keys correctly when they are in a column constraint, not in a table constraint. E.g. CREATE TABLE `a` ( `x` INTEGER CONSTRAINT c PRIMARY KEY, -- Name 'c' here `y` INTEGER, ); See issue #741.
This commit is contained in:
@@ -691,11 +691,11 @@ void CreateTableWalker::parsecolumn(Table& table, antlr::RefAST c)
|
||||
QString colname;
|
||||
QString type = "TEXT";
|
||||
bool autoincrement = false;
|
||||
bool primarykey = false;
|
||||
bool notnull = false;
|
||||
bool unique = false;
|
||||
QString defaultvalue;
|
||||
QString check;
|
||||
sqlb::PrimaryKeyConstraint* primaryKey = 0;
|
||||
sqlb::ForeignKeyClause* foreignKey = 0;
|
||||
|
||||
colname = columnname(c);
|
||||
@@ -725,11 +725,9 @@ void CreateTableWalker::parsecolumn(Table& table, antlr::RefAST c)
|
||||
{
|
||||
case sqlite3TokenTypes::PRIMARY:
|
||||
{
|
||||
// TODO Support constraint names here
|
||||
if(!constraint_name.isEmpty())
|
||||
m_bModifySupported = false;
|
||||
primaryKey = new PrimaryKeyConstraint;
|
||||
primaryKey->setName(constraint_name);
|
||||
|
||||
primarykey = true;
|
||||
con = con->getNextSibling()->getNextSibling(); // skip KEY
|
||||
if(con != antlr::nullAST && (con->getType() == sqlite3TokenTypes::ASC
|
||||
|| con->getType() == sqlite3TokenTypes::DESC))
|
||||
@@ -831,13 +829,13 @@ void CreateTableWalker::parsecolumn(Table& table, antlr::RefAST c)
|
||||
|
||||
if(foreignKey)
|
||||
table.addConstraint({f}, ConstraintPtr(foreignKey));
|
||||
if(primarykey)
|
||||
if(primaryKey)
|
||||
{
|
||||
FieldVector v;
|
||||
if(table.constraint(v, Constraint::PrimaryKeyConstraintType))
|
||||
table.primaryKeyRef().push_back(f);
|
||||
else
|
||||
table.addConstraint({f}, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
table.addConstraint({f}, ConstraintPtr(primaryKey));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user