mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-17 09:19:38 -06:00
Project files: fix crash when tables does not match DB file
There are project files with settings saved for a table with empty schema and name. We let the user load a new DB file when the one referenced by the project is not found, opening the door to load a DB with a different structure. A final case for this inconsistencies can be that we let the user cancel the opening dialog, and the project can be opened without a DB file. See issue #3007
This commit is contained in:
@@ -2693,7 +2693,9 @@ bool MainWindow::loadProject(QString filename, bool readOnly)
|
||||
// New DB filename is pending to be saved
|
||||
isProjectModified = true;
|
||||
}
|
||||
fileOpen(dbfilename, true, readOnly);
|
||||
if(!fileOpen(dbfilename, true, readOnly)) {
|
||||
qWarning() << tr("DB file '%1' could not be opened").arg(dbfilename);
|
||||
}
|
||||
ui->dbTreeWidget->collapseAll();
|
||||
|
||||
// PRAGMAs
|
||||
@@ -2846,9 +2848,15 @@ bool MainWindow::loadProject(QString filename, bool readOnly)
|
||||
sqlb::ObjectIdentifier tableIdentifier =
|
||||
sqlb::ObjectIdentifier (xml.attributes().value("schema").toString().toStdString(),
|
||||
xml.attributes().value("name").toString().toStdString());
|
||||
BrowseDataTableSettings settings;
|
||||
loadBrowseDataTableSettings(settings, db.getTableByName(tableIdentifier), xml);
|
||||
TableBrowser::setSettings(tableIdentifier, settings);
|
||||
sqlb::TablePtr table = db.getTableByName(tableIdentifier);
|
||||
if(table == nullptr) {
|
||||
qWarning() << tr("Table '%1' not found; settings ignored")
|
||||
.arg(QString::fromStdString(tableIdentifier.toString()));
|
||||
} else {
|
||||
BrowseDataTableSettings settings;
|
||||
loadBrowseDataTableSettings(settings, table, xml);
|
||||
TableBrowser::setSettings(tableIdentifier, settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -225,6 +225,8 @@ public:
|
||||
|
||||
const sqlb::TablePtr getTableByName(const sqlb::ObjectIdentifier& name) const
|
||||
{
|
||||
if(schemata.empty() || name.schema().empty())
|
||||
return sqlb::TablePtr{};
|
||||
const auto& schema = schemata.at(name.schema());
|
||||
if(schema.tables.count(name.name()))
|
||||
return schema.tables.at(name.name());
|
||||
@@ -233,6 +235,8 @@ public:
|
||||
|
||||
const sqlb::IndexPtr getIndexByName(const sqlb::ObjectIdentifier& name) const
|
||||
{
|
||||
if(schemata.empty() || name.schema().empty())
|
||||
return sqlb::IndexPtr{};
|
||||
const auto& schema = schemata.at(name.schema());
|
||||
if(schema.indices.count(name.name()))
|
||||
return schema.indices.at(name.name());
|
||||
@@ -241,6 +245,8 @@ public:
|
||||
|
||||
const sqlb::TriggerPtr getTriggerByName(const sqlb::ObjectIdentifier& name) const
|
||||
{
|
||||
if(schemata.empty() || name.schema().empty())
|
||||
return sqlb::TriggerPtr{};
|
||||
const auto& schema = schemata.at(name.schema());
|
||||
if(schema.triggers.count(name.name()))
|
||||
return schema.triggers.at(name.name());
|
||||
|
||||
Reference in New Issue
Block a user