From 61f90668d86cf615116a72c6634e0ee11fd77120 Mon Sep 17 00:00:00 2001 From: eelke Date: Mon, 30 Jan 2023 20:08:24 +0100 Subject: [PATCH] Fix DROP sql for partitioned table. --- pglablib/catalog/PgClass.cpp | 13 ++++++++++++- pglablib/catalog/PgClass.h | 6 +++++- pglablib/catalog/PgObject.cpp | 2 +- pglablib/catalog/PgServerObject.cpp | 7 ++++++- pglablib/catalog/PgServerObject.h | 4 ++++ ...fix-drop-partitioned-table-04ba53874e8f4db1.yaml | 5 +++++ 6 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/fix-drop-partitioned-table-04ba53874e8f4db1.yaml diff --git a/pglablib/catalog/PgClass.cpp b/pglablib/catalog/PgClass.cpp index ccb007c..7f41cbb 100644 --- a/pglablib/catalog/PgClass.cpp +++ b/pglablib/catalog/PgClass.cpp @@ -111,7 +111,18 @@ QString PgClass::aclAllPattern() const default: break; } - return {}; + return {}; +} + +QString PgClass::ddlTypeName() const +{ + switch (kind) + { + case RelKind::PartitionedTable: return "PARTITIONED TABLE"; + return "TABLE"; + default: + return PgNamespaceObject::ddlTypeName(); + } } QString PgClass::createTableSql() const diff --git a/pglablib/catalog/PgClass.h b/pglablib/catalog/PgClass.h index 0591c37..d35e91c 100644 --- a/pglablib/catalog/PgClass.h +++ b/pglablib/catalog/PgClass.h @@ -14,7 +14,8 @@ enum class RelPersistence { void operator<<(RelPersistence &s, const Pgsql::Value &v); -enum class RelKind { +enum class RelKind +{ Table, // r Index, // i Sequence, // S @@ -58,6 +59,9 @@ public: QString typeName() const override; QString aclAllPattern() const override; +protected: + virtual QString ddlTypeName() const override; + private: mutable QString createSqlCache; diff --git a/pglablib/catalog/PgObject.cpp b/pglablib/catalog/PgObject.cpp index e59a050..885f9b7 100644 --- a/pglablib/catalog/PgObject.cpp +++ b/pglablib/catalog/PgObject.cpp @@ -37,7 +37,7 @@ QString PgObject::fullyQualifiedQuotedObjectName() const const PgDatabaseCatalog& PgObject::catalog() const { - return *m_catalog; + return *m_catalog; } diff --git a/pglablib/catalog/PgServerObject.cpp b/pglablib/catalog/PgServerObject.cpp index 2e4ea4a..f85bd1f 100644 --- a/pglablib/catalog/PgServerObject.cpp +++ b/pglablib/catalog/PgServerObject.cpp @@ -93,7 +93,7 @@ QString PgServerObject::aclAllPattern() const QString PgServerObject::dropSql() const { - return "DROP " % typeName() % " " % fullyQualifiedQuotedObjectName() % ";"; + return "DROP " % ddlTypeName() % " " % fullyQualifiedQuotedObjectName() % ";"; } QString PgServerObject::createSql() const @@ -110,3 +110,8 @@ QString PgServerObject::commentSql() const + " IS " + escapeLiteral(description) + ";"; } +QString PgServerObject::ddlTypeName() const +{ + return typeName(); +} + diff --git a/pglablib/catalog/PgServerObject.h b/pglablib/catalog/PgServerObject.h index 447c4f0..5c08fd3 100644 --- a/pglablib/catalog/PgServerObject.h +++ b/pglablib/catalog/PgServerObject.h @@ -46,6 +46,10 @@ public: virtual QString dropSql() const; virtual QString createSql() const; QString commentSql() const; + +protected: + virtual QString ddlTypeName() const; + private: Oid m_ownerOid = InvalidOid; const PgAuthId * m_owner = nullptr; diff --git a/releasenotes/notes/fix-drop-partitioned-table-04ba53874e8f4db1.yaml b/releasenotes/notes/fix-drop-partitioned-table-04ba53874e8f4db1.yaml new file mode 100644 index 0000000..96ed647 --- /dev/null +++ b/releasenotes/notes/fix-drop-partitioned-table-04ba53874e8f4db1.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fix the SQL to drop a partitioned table should be the same as for a normal table. + It should NOT include the word PARTITIONED.