mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
Simplify code
This commit is contained in:
@@ -303,27 +303,27 @@ void DbStructureModel::buildTree(QTreeWidgetItem* parent, const QString& schema)
|
||||
|
||||
// Get all database objects and sort them by their name
|
||||
QMultiMap<QString, sqlb::ObjectPtr> dbobjs;
|
||||
for(auto it=objmap.constBegin(); it != objmap.constEnd(); ++it)
|
||||
dbobjs.insert((*it)->name(), (*it));
|
||||
for(auto it : objmap)
|
||||
dbobjs.insert(it->name(), it);
|
||||
|
||||
// Add the database objects to the tree nodes
|
||||
for(auto it=dbobjs.constBegin();it!=dbobjs.constEnd();++it)
|
||||
for(auto it : dbobjs)
|
||||
{
|
||||
// Object node
|
||||
QTreeWidgetItem* item = addNode(typeToParentItem.value(sqlb::Object::typeToString((*it)->type())), *it, schema);
|
||||
QTreeWidgetItem* item = addNode(typeToParentItem.value(sqlb::Object::typeToString(it->type())), it, schema);
|
||||
|
||||
// If it is a table or view add the field nodes, add an extra node for the browsable section
|
||||
if((*it)->type() == sqlb::Object::Types::Table || (*it)->type() == sqlb::Object::Types::View)
|
||||
addNode(browsablesRootItem, *it, schema);
|
||||
if(it->type() == sqlb::Object::Types::Table || it->type() == sqlb::Object::Types::View)
|
||||
addNode(browsablesRootItem, it, schema);
|
||||
|
||||
// Add field nodes if there are any
|
||||
sqlb::FieldInfoList fieldList = (*it)->fieldInformation();
|
||||
sqlb::FieldInfoList fieldList = it->fieldInformation();
|
||||
if(!fieldList.empty())
|
||||
{
|
||||
QStringList pk_columns;
|
||||
if((*it)->type() == sqlb::Object::Types::Table)
|
||||
if(it->type() == sqlb::Object::Types::Table)
|
||||
{
|
||||
sqlb::FieldVector pk = (*it).dynamicCast<sqlb::Table>()->primaryKey();
|
||||
sqlb::FieldVector pk = it.dynamicCast<sqlb::Table>()->primaryKey();
|
||||
for(const sqlb::FieldPtr& pk_col : pk)
|
||||
pk_columns.push_back(pk_col->name());
|
||||
|
||||
|
||||
@@ -33,10 +33,10 @@ EditIndexDialog::EditIndexDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
|
||||
}
|
||||
} else { // If this is an existing index, only offer tables of the current database schema
|
||||
QList<sqlb::ObjectPtr> tables = pdb.schemata[curIndex.schema()].values("table");
|
||||
for(auto it=tables.constBegin();it!=tables.constEnd();++it)
|
||||
for(auto it : tables)
|
||||
{
|
||||
// Only show the schema name for non-main schemata
|
||||
sqlb::ObjectIdentifier obj(curIndex.schema(), (*it)->name());
|
||||
sqlb::ObjectIdentifier obj(curIndex.schema(), it->name());
|
||||
dbobjs.insert(obj.toDisplayString(), obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,11 +427,11 @@ void MainWindow::populateStructure(const QString& old_table)
|
||||
for(auto it=db.schemata.constBegin();it!=db.schemata.constEnd();++it)
|
||||
{
|
||||
objectMap tab = db.getBrowsableObjects(it.key());
|
||||
for(auto it=tab.constBegin();it!=tab.constEnd();++it)
|
||||
for(auto it : tab)
|
||||
{
|
||||
QString objectname = (*it)->name();
|
||||
QString objectname = it->name();
|
||||
|
||||
sqlb::FieldInfoList fi = (*it)->fieldInformation();
|
||||
sqlb::FieldInfoList fi = it->fieldInformation();
|
||||
for(const sqlb::FieldInfo& f : fi)
|
||||
tablesToColumnsMap[objectname].append(f.name);
|
||||
}
|
||||
|
||||
@@ -1205,16 +1205,16 @@ bool DBBrowserDB::alterTable(const sqlb::ObjectIdentifier& tablename, const sqlb
|
||||
|
||||
// Save all indices, triggers and views associated with this table because SQLite deletes them when we drop the table in the next step
|
||||
QStringList otherObjectsSql;
|
||||
for(auto it=schemata[tablename.schema()].constBegin();it!=schemata[tablename.schema()].constEnd();++it)
|
||||
for(auto it : schemata[tablename.schema()])
|
||||
{
|
||||
// If this object references the table and it's not the table itself save it's SQL string
|
||||
if((*it)->baseTable() == tablename.name() && (*it)->type() != sqlb::Object::Types::Table)
|
||||
if(it->baseTable() == tablename.name() && it->type() != sqlb::Object::Types::Table)
|
||||
{
|
||||
// If this is an index, update the fields first. This highly increases the chance that the SQL statement won't throw an
|
||||
// error later on when we try to recreate it.
|
||||
if((*it)->type() == sqlb::Object::Types::Index)
|
||||
if(it->type() == sqlb::Object::Types::Index)
|
||||
{
|
||||
sqlb::IndexPtr idx = (*it).dynamicCast<sqlb::Index>();
|
||||
sqlb::IndexPtr idx = it.dynamicCast<sqlb::Index>();
|
||||
|
||||
// Are we updating a field name or are we removing a field entirely?
|
||||
if(to)
|
||||
@@ -1238,7 +1238,7 @@ bool DBBrowserDB::alterTable(const sqlb::ObjectIdentifier& tablename, const sqlb
|
||||
} else {
|
||||
// If it's a view or a trigger we don't have any chance to corrections yet. Just store the statement as is and
|
||||
// hope for the best.
|
||||
otherObjectsSql << (*it)->originalSql().trimmed() + ";";
|
||||
otherObjectsSql << it->originalSql().trimmed() + ";";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1352,10 +1352,10 @@ objectMap DBBrowserDB::getBrowsableObjects(const QString& schema) const
|
||||
|
||||
const sqlb::ObjectPtr DBBrowserDB::getObjectByName(const sqlb::ObjectIdentifier& name) const
|
||||
{
|
||||
for(auto it=schemata[name.schema()].constBegin();it!=schemata[name.schema()].constEnd();++it)
|
||||
for(auto it : schemata[name.schema()])
|
||||
{
|
||||
if((*it)->name() == name.name())
|
||||
return *it;
|
||||
if(it->name() == name.name())
|
||||
return it;
|
||||
}
|
||||
return sqlb::ObjectPtr(nullptr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user