Show view definition
This commit is contained in:
parent
dc949f3c34
commit
ead3ce8a8a
3 changed files with 26 additions and 1 deletions
|
|
@ -68,6 +68,8 @@ QString PgClass::createSql() const
|
||||||
if (createSqlCache.isEmpty()) {
|
if (createSqlCache.isEmpty()) {
|
||||||
if (kind == RelKind::Table)
|
if (kind == RelKind::Table)
|
||||||
createSqlCache = createTableSql();
|
createSqlCache = createTableSql();
|
||||||
|
else if (kind == RelKind::View)
|
||||||
|
createSqlCache = createViewSql();
|
||||||
|
|
||||||
}
|
}
|
||||||
return createSqlCache;
|
return createSqlCache;
|
||||||
|
|
@ -159,3 +161,20 @@ QString PgClass::createTableSql() const
|
||||||
sql += ";\n";
|
sql += ";\n";
|
||||||
return sql;
|
return sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString PgClass::createViewSql() const
|
||||||
|
{
|
||||||
|
QString sql;
|
||||||
|
sql += "CREATE OR REPLACE VIEW " + fullyQualifiedQuotedObjectName();
|
||||||
|
|
||||||
|
// todo security_barrier
|
||||||
|
// todo check_option
|
||||||
|
|
||||||
|
sql += " AS \n";
|
||||||
|
sql += viewdef;
|
||||||
|
|
||||||
|
// todo owner
|
||||||
|
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ public:
|
||||||
int frozenxid;
|
int frozenxid;
|
||||||
int minmxid;
|
int minmxid;
|
||||||
std::vector<QString> options;
|
std::vector<QString> options;
|
||||||
|
QString viewdef;
|
||||||
|
|
||||||
using PgNamespaceObject::PgNamespaceObject;
|
using PgNamespaceObject::PgNamespaceObject;
|
||||||
|
|
||||||
|
|
@ -59,6 +60,7 @@ private:
|
||||||
mutable QString createSqlCache;
|
mutable QString createSqlCache;
|
||||||
|
|
||||||
QString createTableSql() const;
|
QString createTableSql() const;
|
||||||
|
QString createViewSql() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PGCLASS_H
|
#endif // PGCLASS_H
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ std::string PgClassContainer::getLoadQuery() const
|
||||||
" relowner, relam, relfilenode, reltablespace, relpages, "
|
" relowner, relam, relfilenode, reltablespace, relpages, "
|
||||||
" reltuples, reltoastrelid, relisshared, relpersistence, "
|
" reltuples, reltoastrelid, relisshared, relpersistence, "
|
||||||
" relkind, relispopulated, relfrozenxid, relminmxid, "
|
" relkind, relispopulated, relfrozenxid, relminmxid, "
|
||||||
" reloptions, relacl";
|
" reloptions, relacl, pg_get_viewdef(oid)";
|
||||||
|
|
||||||
if (lessThenVersion(120000))
|
if (lessThenVersion(120000))
|
||||||
q += ", relhasoids ";
|
q += ", relhasoids ";
|
||||||
|
|
@ -45,6 +45,10 @@ PgClass PgClassContainer::loadElem(const Pgsql::Row &row)
|
||||||
col >> acl_list;
|
col >> acl_list;
|
||||||
v.setAcls(std::move(acl_list));
|
v.setAcls(std::move(acl_list));
|
||||||
|
|
||||||
|
auto vd = col.nextValue();
|
||||||
|
if (!vd.null())
|
||||||
|
v.viewdef = vd.asQString();
|
||||||
|
|
||||||
if (lessThenVersion(120000))
|
if (lessThenVersion(120000))
|
||||||
col >> v.hasoids;
|
col >> v.hasoids;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue