pgLab/pglablib/catalog/PgClassContainer.cpp

62 lines
1.8 KiB
C++
Raw Normal View History

#include "PgClassContainer.h"
#include "Pgsql_Connection.h"
#include "Pgsql_Col.h"
2018-01-08 20:45:52 +01:00
#include "PgDatabaseCatalog.h"
#include "PgNamespaceContainer.h"
2018-09-02 10:30:30 +00:00
#include <iterator>
std::string PgClassContainer::getLoadQuery() const
{
std::string q = "SELECT oid, relname, relnamespace, reltype, reloftype, "
" relowner, relam, relfilenode, reltablespace, relpages, "
" reltuples, reltoastrelid, relisshared, relpersistence, "
" relkind, relispopulated, relfrozenxid, relminmxid, "
" reloptions, d.description, "
" pg_total_relation_size(oid) AS total_bytes, "
" CASE WHEN relkind='r' THEN pg_indexes_size(oid) ELSE 0 END AS index_bytes, "
" CASE WHEN relkind='r' THEN pg_total_relation_size(reltoastrelid) ELSE 0 END AS toast_bytes, "
" relacl, pg_get_viewdef(oid)";
if (lessThenVersion(120000))
q += ", relhasoids ";
q +=
"\nFROM pg_catalog.pg_class \n"
" LEFT JOIN pg_catalog.pg_description AS d ON (objoid=pg_class.oid AND objsubid=0) \n"
"WHERE relkind IN ('r', 'i', 'p', 'I', 'v', 'm', 'f')";
return q;
}
PgClass PgClassContainer::loadElem(const Pgsql::Row &row)
{
Pgsql::Col col(row);
Oid class_oid = col.nextValue();
QString name = col.nextValue();
Oid schema_oid = col.nextValue();
PgClass v(m_catalog, class_oid, name, schema_oid);
Oid owner ;
col >> v.type >> v.oftype
>> owner >> v.am >> v.filenode >> v.tablespace >> v.pages_est
>> v.tuples_est >> v.toastrelid >> v.isshared >> v.persistence
>> v.kind >> v.ispopulated >> v.frozenxid >> v.minmxid
>> v.options >> v.description >> v.totalBytes >> v.indexBytes >> v.toastBytes;
v.setOwnerOid(owner);
AclList acl_list;
col >> acl_list;
v.setAcls(std::move(acl_list));
2019-10-26 13:13:58 +02:00
auto vd = col.nextValue();
if (!vd.null())
v.viewdef = vd.asQString();
if (lessThenVersion(120000))
col >> v.hasoids;
return v;
}