Issue #1534: add schema name for qualified fields dropped from DB Schema

For the "Drag & Drop Qualified Names" option, the schema name for
attached databases is also added for field names dropped from the DB
Schema dock.
This commit is contained in:
mgr
2018-09-15 20:27:08 +02:00
parent 71f26cbc83
commit 9daf2657fc
2 changed files with 20 additions and 18 deletions

View File

@@ -211,19 +211,11 @@ QMimeData* DbStructureModel::mimeData(const QModelIndexList& indices) const
if(index.isValid()) {
QString objectType = data(index.sibling(index.row(), ColumnObjectType), Qt::DisplayRole).toString();
// For names, export an escaped identifier of the item for statement composition in SQL editor.
// Commas are included for a list of fields. A dot is added after other items, in order to allow composing
// a fully qualified name by selecting together and dropping a parent item and a child (e.g. select with
// control an attached database and a table, and drag and drop them to get "schema1"."table1".)
// Note that this only makes sense when the "Drop Qualified Names" option is not set.
if(index.column() == ColumnName)
if(objectType == "field")
namesData.append(getNameForDropping(item->parent()->text(ColumnName), item->text(ColumnName)) + ", ");
else if(objectType != "")
if(item->text(ColumnSchema) == "main")
namesData.append(getNameForDropping("", item->text(ColumnName)) + ".");
else
namesData.append(getNameForDropping(item->text(ColumnSchema), item->text(ColumnName)) + ".");
// For names, export a (qualified) (escaped) identifier of the item for statement composition in SQL editor.
if(objectType == "field")
namesData.append(getNameForDropping(item->text(ColumnSchema), item->parent()->text(ColumnName), item->text(ColumnName)));
else if(objectType != "")
namesData.append(getNameForDropping(item->text(ColumnSchema), item->text(ColumnName), ""));
if(objectType != "field" && index.column() == ColumnSQL)
{
@@ -380,13 +372,23 @@ QTreeWidgetItem* DbStructureModel::addNode(QTreeWidgetItem* parent, const sqlb::
return item;
}
QString DbStructureModel::getNameForDropping(const QString& parentName, const QString& itemName) const
QString DbStructureModel::getNameForDropping(const QString& domain, const QString& object, const QString& field) const
{
// Take into account the drag&drop options for composing a name. Commas are included for composing a
// list of fields. A dot is added after other items, in order to allow composing a fully qualified name
// by selecting together and dropping a parent item and a child (e.g. select with control an attached
// database and a table, and drag and drop them to get "schema1"."table1".) Note that this only makes
// sense when the "Drop Qualified Names" option is not set.
QString name;
if (m_dropQualifiedNames && parentName != "")
name = m_dropEnquotedNames ? sqlb::escapeIdentifier(parentName) + "." : parentName + ".";
if (m_dropQualifiedNames) {
if (domain != "main")
name = m_dropEnquotedNames ? sqlb::escapeIdentifier(domain) + "." : domain + ".";
name += m_dropEnquotedNames ? sqlb::escapeIdentifier(itemName) : itemName;
name += m_dropEnquotedNames ? sqlb::escapeIdentifier(object) + "." : object + ".";
}
if (!field.isEmpty())
name += m_dropEnquotedNames ? sqlb::escapeIdentifier(field) + ", " : field + ", ";
return name;
}

View File

@@ -54,7 +54,7 @@ private:
void buildTree(QTreeWidgetItem* parent, const QString& schema);
QTreeWidgetItem* addNode(QTreeWidgetItem* parent, const sqlb::ObjectPtr& object, const QString& schema);
QString getNameForDropping(const QString& parentName, const QString& itemName) const;
QString getNameForDropping(const QString& domain, const QString& object, const QString& field) const;
};
#endif