mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Parse and save foreign key constraints
When parsing a CREATE TABLE statement read and try to parse any foreign key constraints and save that information.
This commit is contained in:
@@ -190,6 +190,14 @@ QString Table::sql() const
|
||||
if(pks_found)
|
||||
sql += pk + ")";
|
||||
}
|
||||
|
||||
// foreign keys
|
||||
foreach(FieldPtr f, m_fields)
|
||||
{
|
||||
if(!f->foreignKey().isEmpty())
|
||||
sql += QString(",\n\tFOREIGN KEY(`%1`) REFERENCES %2").arg(f->name()).arg(f->foreignKey());
|
||||
}
|
||||
|
||||
sql += "\n)";
|
||||
|
||||
// without rowid
|
||||
@@ -345,6 +353,25 @@ Table CreateTableWalker::table()
|
||||
}
|
||||
}
|
||||
break;
|
||||
case sqlite3TokenTypes::FOREIGN:
|
||||
{
|
||||
tc = tc->getNextSibling(); // FOREIGN
|
||||
tc = tc->getNextSibling(); // KEY
|
||||
tc = tc->getNextSibling(); // LPAREN
|
||||
QString column_name = identifier(tc);
|
||||
tc = tc->getNextSibling(); // identifier
|
||||
if(tc->getType() == sqlite3TokenTypes::COMMA)
|
||||
{
|
||||
// No support for composite foreign keys
|
||||
m_bModifySupported = false;
|
||||
break;
|
||||
}
|
||||
tc = tc->getNextSibling(); // RPAREN
|
||||
tc = tc->getNextSibling(); // REFERENCES
|
||||
|
||||
tab.fields().at(tab.findField(column_name))->setForeignKey(concatTextAST(tc, true));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
m_bModifySupported = false;
|
||||
|
||||
Reference in New Issue
Block a user