From f1020ac56ed27e92e21b66e11a222b1164f29c95 Mon Sep 17 00:00:00 2001 From: eelke Date: Sun, 5 Aug 2018 11:27:05 +0200 Subject: [PATCH] Index DROP and CREATE statements are now shown. For now the create is still single line. Either complex query is required to get details for custom generator or we need to format after the fact. Close #12 --- pglab/TablesPage.cpp | 2 +- pglablib/SqlFormattingUtils.cpp | 37 +++++++++++++++++++++++---------- pglablib/SqlFormattingUtils.h | 1 + 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/pglab/TablesPage.cpp b/pglab/TablesPage.cpp index c8f83c1..cc2f4a6 100644 --- a/pglab/TablesPage.cpp +++ b/pglab/TablesPage.cpp @@ -146,7 +146,7 @@ void TablesPage::indexesTable_selectionChanged(const QItemSelection &/*selected* QString creates; for (auto rij : rijen) { const PgIndex index = m_indexModel->getIndex(rij); - //drops += getDropIndexDefinition(*m_catalog, index) % "\n"; + drops += getDropIndexDefinition(*m_catalog, index) % "\n"; creates += getIndexDefinition(*m_catalog, index) % "\n"; } ui->indexSqlEdit->setPlainText(drops % "\n" % creates); diff --git a/pglablib/SqlFormattingUtils.cpp b/pglablib/SqlFormattingUtils.cpp index fb3addc..6e26c88 100644 --- a/pglablib/SqlFormattingUtils.cpp +++ b/pglablib/SqlFormattingUtils.cpp @@ -177,18 +177,18 @@ QString getIndexDefinition(const PgDatabaseCatalog &catalog, const PgIndex &inde PgClass index_class = catalog.classes()->getByKey(index.indexrelid); + return index.definition + ";"; - - QString result; - result = "CREATE "; - if (index.isunique) - result += "UNIQUE "; - result += "INDEX " -// % quoteIdent(getIndexDisplayString(catalog, index.indexrelid)) - % quoteIdent(index_class.name) - % "\n ON " % genFQTableName(catalog, table_class); -// % "\n USING " % index_class.am lookup in pg_am table - return result; +// QString result; +// result = "CREATE "; +// if (index.isunique) +// result += "UNIQUE "; +// result += "INDEX " +//// % quoteIdent(getIndexDisplayString(catalog, index.indexrelid)) +// % quoteIdent(index_class.name) +// % "\n ON " % genFQTableName(catalog, table_class); +//// % "\n USING " % index_class.am lookup in pg_am table +// return result; #if 0 + wxT("\n USING ") + GetIndexType() @@ -222,6 +222,21 @@ QString getIndexDefinition(const PgDatabaseCatalog &catalog, const PgIndex &inde #endif } +QString getDropIndexDefinition(const PgDatabaseCatalog &catalog, const PgIndex &index) +{ + PgClass table_class = catalog.classes()->getByKey(index.relid); + PgClass index_class = catalog.classes()->getByKey(index.indexrelid); + + QString result; + result = "DROP INDEX " + % quoteIdent(getIndexDisplayString(catalog, index.indexrelid)) + % ";"; +// % quoteIdent(index_class.name) +// % "\n ON " % genFQTableName(catalog, table_class); +//// % "\n USING " % index_class.am lookup in pg_am table + return result; +} + /* wxString sql; diff --git a/pglablib/SqlFormattingUtils.h b/pglablib/SqlFormattingUtils.h index cec320d..d485dba 100644 --- a/pglablib/SqlFormattingUtils.h +++ b/pglablib/SqlFormattingUtils.h @@ -15,6 +15,7 @@ QString genFQTableName(const PgDatabaseCatalog &catalog, const PgClass &cls); QString getDropConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint); QString getConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint); QString getIndexDefinition(const PgDatabaseCatalog &catalog, const PgIndex &index); +QString getDropIndexDefinition(const PgDatabaseCatalog &catalog, const PgIndex &index); QString getForeignKeyConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint); #endif // SQLFORMATTINGUTILS_H