mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
Add support for conflict clauses to the grammar parser
Add support for parsing and generating CREATE statements with an ON CONFLICT clause for their primary key.
This commit is contained in:
@@ -92,6 +92,7 @@ public:
|
||||
|
||||
private:
|
||||
void parsecolumn(Table* table, antlr::RefAST c);
|
||||
QString parseConflictClause(antlr::RefAST c);
|
||||
|
||||
private:
|
||||
antlr::RefAST m_root;
|
||||
@@ -219,6 +220,9 @@ QString PrimaryKeyConstraint::toSql(const FieldVector& applyOn) const
|
||||
result += QString("CONSTRAINT %1 ").arg(escapeIdentifier(m_name));
|
||||
result += QString("PRIMARY KEY(%1)").arg(fieldVectorToFieldNames(applyOn).join(","));
|
||||
|
||||
if(!m_conflictAction.isEmpty())
|
||||
result += " ON CONFLICT " + m_conflictAction;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -794,6 +798,10 @@ TablePtr CreateTableWalker::table()
|
||||
}
|
||||
} while(tc != antlr::nullAST && tc->getType() != sqlite3TokenTypes::RPAREN);
|
||||
|
||||
// We're either done now or there is a conflict clause
|
||||
tc = tc->getNextSibling(); // skip RPAREN
|
||||
pk->setConflictAction(parseConflictClause(tc));
|
||||
|
||||
tab->addConstraint(fields, ConstraintPtr(pk));
|
||||
}
|
||||
break;
|
||||
@@ -1026,6 +1034,9 @@ void CreateTableWalker::parsecolumn(Table* table, antlr::RefAST c)
|
||||
table->setFullyParsed(false);
|
||||
con = con->getNextSibling(); //skip
|
||||
}
|
||||
|
||||
primaryKey->setConflictAction(parseConflictClause(con));
|
||||
|
||||
if(con != antlr::nullAST && con->getType() == sqlite3TokenTypes::AUTOINCREMENT)
|
||||
autoincrement = true;
|
||||
}
|
||||
@@ -1145,6 +1156,21 @@ void CreateTableWalker::parsecolumn(Table* table, antlr::RefAST c)
|
||||
}
|
||||
}
|
||||
|
||||
QString CreateTableWalker::parseConflictClause(antlr::RefAST c)
|
||||
{
|
||||
QString conflictAction;
|
||||
|
||||
if(c != antlr::nullAST && c->getType() == sqlite3TokenTypes::ON && c->getNextSibling()->getType() == sqlite3TokenTypes::CONFLICT)
|
||||
{
|
||||
c = c->getNextSibling(); // skip ON
|
||||
c = c->getNextSibling(); // skip CONFLICT
|
||||
conflictAction = identifier(c);
|
||||
c = c->getNextSibling(); // skip action
|
||||
}
|
||||
|
||||
return conflictAction;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString IndexedColumn::toString(const QString& indent, const QString& sep) const
|
||||
|
||||
Reference in New Issue
Block a user