pgLab/pglablib/catalog/PgProc.h
eelke 43f8117bbd pg11: pg_proc, type of function is stored differently from pg11 forward
Followed the more structured approach of pg11 in combining the different types into a kind field
when reading from older versions we migrate the old fields to the new field. Change in 11
is because of PROCEDURE support. However full PROCEDURE support will be its own change and is
registered as issue #37
2018-12-23 08:48:45 +01:00

105 lines
2.9 KiB
C++

#ifndef PGPROC_H
#define PGPROC_H
#include "PgNamespaceObject.h"
#include "PgOwnedObject.h"
#include <QString>
#include <libpq-fe.h>
#include "Pgsql_Value.h"
#include <vector>
class Arg {
public:
enum Mode {
In, Out, InOut, Variadic, Table
};
Oid type;
Mode mode;
QString name;
QString def;
Arg(Oid t, Mode m, QString n, QString d)
: type(t), mode(m), name(n), def(d)
{}
};
enum class ProcKind {
Function, // f Normal function
Procedure, // p stored procedure, new in 11 can use transactions executed with CALL
Aggregate, // a
Window // w
};
void operator<<(ProcKind &s, const Pgsql::Value &v);
class PgProc: public PgNamespaceObject, public PgOwnedObject {
public:
using PgNamespaceObject::PgNamespaceObject;
// Oid oid = InvalidOid; // oid
// QString name; // name
// Oid pronamespace = InvalidOid; // oid, namespace
// Oid owner = InvalidOid; // oid
Oid lang = InvalidOid; // oid
float cost = 0.f; // float4
float rows = 0.f; // float4
Oid variadic = InvalidOid; // oid
QString transform; // regproc
// bool isagg = false; // bool < 11
// bool iswindow = false; // bool << 11
ProcKind kind = ProcKind::Function; // >= 11
bool secdef = false; // bool
bool leakproof = false; // bool
bool isstrict = false; // bool
bool retset = false; // bool
char provolatile = '\0'; // char
char parallel = '\0'; // char, version >= 9.6
int16_t nargs = 0; // int2
int16_t nargdefaults; // = 0; // int2
Oid rettype = InvalidOid; // oid
std::vector<Oid> trftypes; // oid[], version >= 9.5
QString src; // text
QString bin; // text
std::vector<QString> config; // text[]
QString acl; // aclitem[]
/// Converts the collection of arrays about the arguments to a single list of arguments
/// making it much easier to work with them correctly
void setArgs(
std::vector<Oid> argtypes,
std::vector<Oid> allargtypes,
std::vector<char> argmodes,
std::vector<QString> argnames,
std::optional<QString> argdefaults
);
const std::vector<Arg>& args() const;
// bool operator==(Oid _oid) const { return oid == _oid; }
// bool operator==(const QString &n) const { return name == n; }
// bool operator<(Oid _oid) const { return oid < _oid; }
// bool operator<(const PgProc &rhs) const { return oid < rhs.oid; }
QString createSql() const;
QString argListWithNames(bool multiline = false) const;
QString argSigList(const bool forScript = false) const;
QString volatility() const;
bool isFunction() const { return kind == ProcKind::Function; }
bool isProcedure() const { return kind == ProcKind::Procedure; }
bool isAggregate() const { return kind == ProcKind::Aggregate; }
bool isWindow() const { return kind == ProcKind::Window; }
// bool isTrigger() const
// {
// return typname == wxT("\"trigger\"") || typname == wxT("trigger") || typname == wxT("event_trigger") || typname == wxT("\"event_trigger\""))
// }
private:
mutable QString createSqlCache;
std::vector<Arg> m_args;
};
#endif // PGPROC_H