The create table statement now lists the inherited tables and inherited columns are commented out.
This commit is contained in:
parent
498233d58c
commit
6c76c70a97
11 changed files with 118 additions and 6 deletions
|
|
@ -24,6 +24,7 @@ public:
|
|||
bool hasdef = false;
|
||||
char identity = ' ';
|
||||
bool isdropped = false;
|
||||
bool islocal = true;
|
||||
Oid collation = InvalidOid;
|
||||
QString acl;
|
||||
QString options;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ std::string PgAttributeContainer::getLoadQuery() const
|
|||
std::string q = R"__(
|
||||
SELECT attrelid, attname, atttypid, attstattarget,
|
||||
attnum, attndims, atttypmod, attnotnull, atthasdef, attisdropped,
|
||||
attcollation, attacl, attoptions, pg_get_expr(adbin, adrelid) AS def_value)__";
|
||||
attislocal, attcollation, attacl, attoptions, pg_get_expr(adbin, adrelid) AS def_value)__";
|
||||
if (m_catalog.serverVersion() >= 100000)
|
||||
q += ", attidentity";
|
||||
q +=
|
||||
|
|
@ -27,7 +27,7 @@ PgAttribute PgAttributeContainer::loadElem(const Pgsql::Row &row)
|
|||
PgAttribute v;
|
||||
col >> v.relid >> v.name >> v.typid >> v.stattarget
|
||||
>> v.num >> v.ndims >> v.typmod >> v.notnull >> v.hasdef >> v.isdropped
|
||||
>> v.collation >> v.acl >> v.options >> v.defaultValue;
|
||||
>> v.islocal >> v.collation >> v.acl >> v.options >> v.defaultValue;
|
||||
if (m_catalog.serverVersion() >= 100000)
|
||||
col >> v.identity;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
#include "PgClass.h"
|
||||
#include "PgAttributeContainer.h"
|
||||
#include "PgClassContainer.h"
|
||||
#include "PgDatabaseCatalog.h"
|
||||
#include "PgConstraintContainer.h"
|
||||
#include "PgInheritsContainer.h"
|
||||
#include <QStringBuilder>
|
||||
#include "SqlFormattingUtils.h"
|
||||
|
||||
|
|
@ -93,6 +95,7 @@ QString PgClass::createTableSql() const
|
|||
first = false;
|
||||
}
|
||||
else sql += ",\n ";
|
||||
if (!col.islocal) sql += "-- ";
|
||||
sql += col.columnDefinition(catalog());
|
||||
}
|
||||
// { column_name data_type [ COLLATE collation ] [ column_constraint [ ... ] ]
|
||||
|
|
@ -110,7 +113,20 @@ QString PgClass::createTableSql() const
|
|||
}
|
||||
|
||||
sql += ")";
|
||||
// [ INHERITS ( parent_table [, ... ] ) ]
|
||||
{
|
||||
// [ INHERITS ( parent_table [, ... ] ) ]
|
||||
auto parents = catalog().inherits()->getParentsOf(oid());
|
||||
if (!parents.empty()) {
|
||||
sql += "\nINHERITS (";
|
||||
bool first = true;
|
||||
for (auto parent_oid : parents) {
|
||||
if (first) first = false;
|
||||
else sql += ", ";
|
||||
sql += catalog().classes()->getByKey(parent_oid)->fullyQualifiedQuotedObjectName();
|
||||
}
|
||||
sql += ")";
|
||||
}
|
||||
}
|
||||
// [ PARTITION BY { RANGE | LIST } ( { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [, ... ] ) ]
|
||||
// [ WITH ( storage_parameter [= value] [, ... ] ) | WITH OIDS | WITHOUT OIDS ]
|
||||
// [ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include "PgTypeContainer.h"
|
||||
#include "PgProcContainer.h"
|
||||
#include "PgCollationContainer.h"
|
||||
#include "PgInheritsContainer.h"
|
||||
#include "Pgsql_Connection.h"
|
||||
#include "Pgsql_oids.h"
|
||||
|
||||
|
|
@ -178,6 +179,9 @@ void PgDatabaseCatalog::loadAll(Pgsql::Connection &conn,
|
|||
if (progress_callback && !progress_callback(++n, count))
|
||||
return;
|
||||
load2(m_procs, conn);
|
||||
if (progress_callback && !progress_callback(++n, count))
|
||||
return;
|
||||
load2(m_inherits, conn);
|
||||
progress_callback && progress_callback(++n, count);
|
||||
|
||||
refreshed(this, All);
|
||||
|
|
@ -293,3 +297,8 @@ std::shared_ptr<const PgCollationContainer> PgDatabaseCatalog::collations() cons
|
|||
{
|
||||
return m_collations;
|
||||
}
|
||||
|
||||
std::shared_ptr<const PgInheritsContainer> PgDatabaseCatalog::inherits() const
|
||||
{
|
||||
return m_inherits;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ class PgTriggerContainer;
|
|||
class PgTypeContainer;
|
||||
class PgProcContainer;
|
||||
class PgCollationContainer;
|
||||
class PgInheritsContainer;
|
||||
|
||||
|
||||
class PgDatabaseCatalog: public QObject, public std::enable_shared_from_this<PgDatabaseCatalog> {
|
||||
|
|
@ -60,6 +61,7 @@ public:
|
|||
std::shared_ptr<const PgTypeContainer> types() const;
|
||||
std::shared_ptr<const PgProcContainer> procs() const;
|
||||
std::shared_ptr<const PgCollationContainer> collations() const;
|
||||
std::shared_ptr<const PgInheritsContainer> inherits() const;
|
||||
|
||||
enum RefreshFlag {
|
||||
Attributes = 1,
|
||||
|
|
@ -98,6 +100,7 @@ private:
|
|||
std::shared_ptr<PgTypeContainer> m_types;
|
||||
std::shared_ptr<PgProcContainer> m_procs;
|
||||
std::shared_ptr<PgCollationContainer> m_collations;
|
||||
std::shared_ptr<PgInheritsContainer> m_inherits;
|
||||
|
||||
template <typename T>
|
||||
void load2(std::shared_ptr<T> &ptr, Pgsql::Connection &conn)
|
||||
|
|
|
|||
3
pglablib/PgInherits.cpp
Normal file
3
pglablib/PgInherits.cpp
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#include "PgInherits.h"
|
||||
|
||||
PgInherits::PgInherits() = default;
|
||||
25
pglablib/PgInherits.h
Normal file
25
pglablib/PgInherits.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef PGINHERITS_H
|
||||
#define PGINHERITS_H
|
||||
|
||||
#include "Pgsql_declare.h"
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
class PgInherits {
|
||||
public:
|
||||
using Key = std::tuple<Oid, int32_t>;
|
||||
|
||||
|
||||
Oid relid = InvalidOid; // oid
|
||||
Oid parent = InvalidOid; // oid
|
||||
int32_t seqno = 0; // integer
|
||||
|
||||
PgInherits();
|
||||
|
||||
bool operator==(Key _k) const { return relid == std::get<0>(_k) && seqno == std::get<1>(_k); }
|
||||
bool operator<(Key _k) const { return relid < std::get<0>(_k) || (relid == std::get<0>(_k) && seqno < std::get<1>(_k)); }
|
||||
bool operator<(const PgInherits &rhs) const { return relid < rhs.relid || (relid == rhs.relid && seqno < rhs.seqno); }
|
||||
};
|
||||
|
||||
#endif // PGINHERITS_H
|
||||
29
pglablib/PgInheritsContainer.cpp
Normal file
29
pglablib/PgInheritsContainer.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include "PgInheritsContainer.h"
|
||||
#include "Pgsql_Col.h"
|
||||
#include "PgDatabaseCatalog.h"
|
||||
#include <algorithm>
|
||||
|
||||
std::vector<Oid> PgInheritsContainer::getParentsOf(Oid oid) const
|
||||
{
|
||||
std::vector<Oid> result;
|
||||
auto&& iter = std::lower_bound(m_container.begin(), m_container.end(), PgInherits::Key{ oid, 1 });
|
||||
for (;iter != m_container.end() && iter->relid == oid; ++iter)
|
||||
result.push_back(iter->parent);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string PgInheritsContainer::getLoadQuery() const
|
||||
{
|
||||
return
|
||||
"SELECT inhrelid, inhparent, inhseqno \n"
|
||||
" FROM pg_inherits";
|
||||
}
|
||||
|
||||
|
||||
PgInherits PgInheritsContainer::loadElem(const Pgsql::Row &row)
|
||||
{
|
||||
Pgsql::Col col(row);
|
||||
PgInherits v;
|
||||
col >> v.relid >> v.parent >> v.seqno;
|
||||
return v;
|
||||
}
|
||||
22
pglablib/PgInheritsContainer.h
Normal file
22
pglablib/PgInheritsContainer.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef PGINHERITSCONTAINER_H
|
||||
#define PGINHERITSCONTAINER_H
|
||||
|
||||
|
||||
#include "PgContainer.h"
|
||||
#include "PgInherits.h"
|
||||
#include "Pgsql_declare.h"
|
||||
|
||||
|
||||
class PgInheritsContainer : public PgContainer<PgInherits, PgInherits::Key> {
|
||||
public:
|
||||
using PgContainer<PgInherits, PgInherits::Key>::PgContainer;
|
||||
|
||||
virtual std::string getLoadQuery() const override;
|
||||
|
||||
/// Returns the parents in the correct order
|
||||
std::vector<Oid> getParentsOf(Oid oid) const;
|
||||
protected:
|
||||
PgInherits loadElem(const Pgsql::Row &row) override;
|
||||
};
|
||||
|
||||
#endif // PGINHERITSCONTAINER_H
|
||||
|
|
@ -317,7 +317,7 @@ QString getForeignKeyConstraintDefinition(const PgDatabaseCatalog &catalog, cons
|
|||
% ForeignKeyMatchToString(constraint.fmatchtype)
|
||||
% " ON UPDATE " % ForeignKeyActionToString(constraint.fupdtype)
|
||||
% " ON DELETE " % ForeignKeyActionToString(constraint.fdeltype)
|
||||
% deferrable % validated % ";";
|
||||
% deferrable % validated;
|
||||
}
|
||||
|
||||
QString getForeignKeyConstraintReferences(const PgDatabaseCatalog &catalog, const PgConstraint &constraint)
|
||||
|
|
|
|||
|
|
@ -73,7 +73,9 @@ codebuilder/StructureTemplate.cpp \
|
|||
PgOwnedObject.cpp \
|
||||
PgNamespaceObject.cpp \
|
||||
PgCollation.cpp \
|
||||
PgCollationContainer.cpp
|
||||
PgCollationContainer.cpp \
|
||||
PgInherits.cpp \
|
||||
PgInheritsContainer.cpp
|
||||
|
||||
HEADERS += \
|
||||
Pglablib.h \
|
||||
|
|
@ -129,7 +131,9 @@ codebuilder/StructureTemplate.h \
|
|||
PgOwnedObject.h \
|
||||
PgNamespaceObject.h \
|
||||
PgCollation.h \
|
||||
PgCollationContainer.h
|
||||
PgCollationContainer.h \
|
||||
PgInherits.h \
|
||||
PgInheritsContainer.h
|
||||
|
||||
unix {
|
||||
target.path = /usr/lib
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue