Show SQL for database

Also improvements to the SQL for tables and views.
This commit is contained in:
eelke 2022-01-20 20:13:56 +01:00
parent b5a706a2a2
commit 3158a4364b
12 changed files with 172 additions and 58 deletions

View file

@ -20,7 +20,7 @@
#include <QApplication>
#include <QHeaderView>
#include <QStringBuilder>
#include <QSortFilterProxyModel>
//#include <QSortFilterProxyModel>
#include <QTableWidget>
CatalogTablesPage::CatalogTablesPage(std::shared_ptr<OpenDatabase> opendatabase, QWidget *parent)
@ -69,12 +69,6 @@ CatalogTablesPage::CatalogTablesPage(std::shared_ptr<OpenDatabase> opendatabase,
// Signals
connect(tv->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
&CatalogTablesPage::tableListTable_currentRowChanged);
// connect(m_tablesTableView.dataModel(), &TablesTableModel::modelReset,
// [this] ()
// {
// selectedTableChanged({});
// m_propertiesPage->setActiveRow({});
// });
connect(m_tablesTableView.dataModel(), &QAbstractItemModel::layoutChanged,
this, &CatalogTablesPage::tableListTable_layoutChanged);
@ -117,10 +111,11 @@ void CatalogTablesPage::setNamespaceFilter(NamespaceFilter filter)
void CatalogTablesPage::tableListTable_currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
{
if (current.row() != previous.row()) {
auto table = m_tablesTableView.rowItemForProxyIndex(current);
selectedTableChanged(table);
}
if (current.row() == previous.row())
return;
auto table = m_tablesTableView.rowItemForProxyIndex(current);
selectedTableChanged(table);
}
@ -160,8 +155,9 @@ void CatalogTablesPage::updateSqlTab(const std::optional<PgClass> &table)
QString drop_sql;
QString create_sql;
// create table
create_sql += table->createSql();
// table
drop_sql += table->dropSql() % "\n";
create_sql += table->createSql() % "\n";
// - columns
// - constraints
// table details (inherits etc)
@ -194,10 +190,7 @@ void CatalogTablesPage::updateSqlTab(const std::optional<PgClass> &table)
// Comments
create_sql += "-- set Comments table + columns\n";
if (!table->description.isEmpty()) {
create_sql += "COMMENT ON TABLE " + table->fullyQualifiedQuotedObjectName()
+ " IS " + dollarQuoteString(table->description) + ";\n";
}
create_sql += table->commentSql() % "\n";
auto && cols = m_catalog->attributes()->getColumnsForRelation(table->oid());
for (auto && col : cols) {