2018-11-17 19:38:07 +01:00
|
|
|
|
#include "PgProcContainer.h"
|
|
|
|
|
|
#include "Pgsql_Connection.h"
|
|
|
|
|
|
#include "Pgsql_Col.h"
|
|
|
|
|
|
#include "PgDatabaseCatalog.h"
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
#include <iterator>
|
|
|
|
|
|
|
|
|
|
|
|
std::string PgProcContainer::getLoadQuery() const
|
|
|
|
|
|
{
|
|
|
|
|
|
std::string column_list =
|
|
|
|
|
|
"oid,proname,pronamespace,proowner,prolang,procost,prorows,"
|
2019-08-10 18:10:19 +02:00
|
|
|
|
"provariadic,prosecdef,proleakproof,"
|
2018-11-17 19:38:07 +01:00
|
|
|
|
"proisstrict,proretset,provolatile,pronargs,pronargdefaults,prorettype,"
|
|
|
|
|
|
"proargtypes,proallargtypes,proargmodes,proargnames,proargdefaults,"
|
|
|
|
|
|
"prosrc,probin,proconfig,proacl";
|
2018-12-23 08:48:45 +01:00
|
|
|
|
if (minimumVersion(90500))
|
2018-11-17 19:38:07 +01:00
|
|
|
|
column_list += ",protrftypes";
|
2018-12-23 08:48:45 +01:00
|
|
|
|
if (minimumVersion(90600))
|
2018-11-17 19:38:07 +01:00
|
|
|
|
column_list += ",proparallel";
|
2018-12-23 08:48:45 +01:00
|
|
|
|
if (minimumVersion(110000))
|
|
|
|
|
|
column_list += ",prokind";
|
|
|
|
|
|
else
|
|
|
|
|
|
column_list += ",proisagg,proiswindow";
|
2018-11-17 19:38:07 +01:00
|
|
|
|
|
|
|
|
|
|
return "SELECT " + column_list + " FROM pg_proc";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PgProc PgProcContainer::loadElem(const Pgsql::Row &row)
|
|
|
|
|
|
{
|
|
|
|
|
|
Pgsql::Col col(row);
|
2018-11-25 19:45:06 +01:00
|
|
|
|
Oid oid = col.nextValue();
|
|
|
|
|
|
QString name = col.nextValue();
|
|
|
|
|
|
Oid namespace_oid = col.nextValue();
|
2018-12-17 21:51:14 +01:00
|
|
|
|
Oid owner_oid = col.nextValue();
|
2018-11-25 19:45:06 +01:00
|
|
|
|
|
2018-12-23 08:48:45 +01:00
|
|
|
|
//ProcKind
|
|
|
|
|
|
|
2018-11-25 19:45:06 +01:00
|
|
|
|
PgProc v(m_catalog, oid, name, namespace_oid);
|
2018-12-25 13:17:04 +01:00
|
|
|
|
v.setOwnerOid(owner_oid);
|
2018-12-17 21:51:14 +01:00
|
|
|
|
col >> v.lang >> v.cost >> v.rows
|
2019-08-10 18:10:19 +02:00
|
|
|
|
>> v.variadic >> v.secdef >> v.leakproof
|
2018-11-25 19:45:06 +01:00
|
|
|
|
>> v.isstrict >> v.retset >> v.provolatile >> v.nargs >> v.nargdefaults
|
|
|
|
|
|
>> v.rettype;
|
|
|
|
|
|
|
2018-11-25 09:06:01 +01:00
|
|
|
|
std::vector<Oid> argtypes; // oid[]
|
|
|
|
|
|
std::vector<Oid> allargtypes; // oid[]
|
|
|
|
|
|
std::vector<char> argmodes; // char[]
|
|
|
|
|
|
std::vector<QString> argnames; // text[]
|
|
|
|
|
|
std::optional<QString> argdefaults; // pg_node_tree
|
|
|
|
|
|
col.getAsVector<Oid>(std::back_inserter(argtypes));
|
|
|
|
|
|
col >> allargtypes >> argmodes >> argnames >> argdefaults
|
2018-12-24 07:51:27 +01:00
|
|
|
|
>> v.src >> v.bin >> v.config; // >> v.acl;
|
|
|
|
|
|
AclList acl_list;
|
|
|
|
|
|
col >> acl_list;
|
|
|
|
|
|
v.setAcls(std::move(acl_list));
|
2018-11-25 09:06:01 +01:00
|
|
|
|
v.setArgs(argtypes, allargtypes, argmodes, argnames, argdefaults);
|
2018-11-18 19:30:45 +01:00
|
|
|
|
|
|
|
|
|
|
if (minimumVersion(90500)) {
|
|
|
|
|
|
col >> v.trftypes;
|
2018-11-17 19:38:07 +01:00
|
|
|
|
}
|
2018-11-18 19:30:45 +01:00
|
|
|
|
if (minimumVersion(90600)) {
|
|
|
|
|
|
col >> v.parallel;
|
2018-11-17 19:38:07 +01:00
|
|
|
|
}
|
2018-12-23 08:48:45 +01:00
|
|
|
|
if (minimumVersion(110000))
|
|
|
|
|
|
col >> v.kind;
|
|
|
|
|
|
else {
|
|
|
|
|
|
bool agg, window;
|
|
|
|
|
|
col >> agg >> window;
|
|
|
|
|
|
if (agg)
|
|
|
|
|
|
v.kind = ProcKind::Aggregate;
|
|
|
|
|
|
else if (window)
|
|
|
|
|
|
v.kind = ProcKind::Window;
|
|
|
|
|
|
else {
|
|
|
|
|
|
v.kind = ProcKind::Function;
|
|
|
|
|
|
}
|
|
|
|
|
|
// Only 11 and higher has ProcKind::Procedure!
|
|
|
|
|
|
}
|
2018-11-17 19:38:07 +01:00
|
|
|
|
|
|
|
|
|
|
return v;
|
|
|
|
|
|
}
|