2018-11-17 19:38:07 +01:00
|
|
|
|
#ifndef PGPROC_H
|
|
|
|
|
|
#define PGPROC_H
|
|
|
|
|
|
|
2018-11-25 19:45:06 +01:00
|
|
|
|
#include "PgNamespaceObject.h"
|
2018-11-17 19:38:07 +01:00
|
|
|
|
#include <QString>
|
|
|
|
|
|
#include <libpq-fe.h>
|
|
|
|
|
|
#include "Pgsql_Value.h"
|
2018-11-25 09:06:01 +01:00
|
|
|
|
#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)
|
|
|
|
|
|
{}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-11-17 19:38:07 +01:00
|
|
|
|
|
2018-12-23 08:48:45 +01:00
|
|
|
|
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);
|
|
|
|
|
|
|
2018-12-23 19:45:04 +01:00
|
|
|
|
enum class ParallelMode {
|
|
|
|
|
|
Unsafe, // u, default
|
|
|
|
|
|
Restricted, // r,
|
|
|
|
|
|
Safe // s
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void operator<<(ParallelMode &s, const Pgsql::Value &v);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief parallelModeToSql
|
|
|
|
|
|
* @param pm The parallel mode
|
|
|
|
|
|
* @param explicit_unsafe When false an empty string is return for unsage when true
|
|
|
|
|
|
* a "PARALLEL UNSAFE" is returned.
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
QString parallelModeToSql(ParallelMode pm, bool explicit_unsafe = false);
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-25 13:17:04 +01:00
|
|
|
|
class PgProc: public PgNamespaceObject {
|
2018-11-17 19:38:07 +01:00
|
|
|
|
public:
|
2018-11-25 19:45:06 +01:00
|
|
|
|
using PgNamespaceObject::PgNamespaceObject;
|
2018-11-18 19:30:45 +01:00
|
|
|
|
|
|
|
|
|
|
Oid lang = InvalidOid; // oid
|
|
|
|
|
|
float cost = 0.f; // float4
|
|
|
|
|
|
float rows = 0.f; // float4
|
|
|
|
|
|
Oid variadic = InvalidOid; // oid
|
|
|
|
|
|
QString transform; // regproc
|
2018-12-23 08:48:45 +01:00
|
|
|
|
ProcKind kind = ProcKind::Function; // >= 11
|
2018-11-18 19:30:45 +01:00
|
|
|
|
bool secdef = false; // bool
|
|
|
|
|
|
bool leakproof = false; // bool
|
|
|
|
|
|
bool isstrict = false; // bool
|
|
|
|
|
|
bool retset = false; // bool
|
2018-11-17 19:38:07 +01:00
|
|
|
|
char provolatile = '\0'; // char
|
2018-12-23 19:45:04 +01:00
|
|
|
|
ParallelMode parallel = ParallelMode::Unsafe; // char, version >= 9.6
|
2018-11-18 19:30:45 +01:00
|
|
|
|
int16_t nargs = 0; // int2
|
2018-11-25 09:06:01 +01:00
|
|
|
|
int16_t nargdefaults; // = 0; // int2
|
2018-11-18 19:30:45 +01:00
|
|
|
|
Oid rettype = InvalidOid; // oid
|
|
|
|
|
|
std::vector<Oid> trftypes; // oid[], version >= 9.5
|
|
|
|
|
|
QString src; // text
|
|
|
|
|
|
QString bin; // text
|
|
|
|
|
|
std::vector<QString> config; // text[]
|
2018-11-25 09:06:01 +01:00
|
|
|
|
|
|
|
|
|
|
/// 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;
|
2018-11-17 19:38:07 +01:00
|
|
|
|
|
2018-12-23 19:45:04 +01:00
|
|
|
|
const QString& createSql() const;
|
2018-11-25 09:06:01 +01:00
|
|
|
|
QString argListWithNames(bool multiline = false) const;
|
|
|
|
|
|
QString argSigList(const bool forScript = false) const;
|
2018-12-22 13:52:19 +01:00
|
|
|
|
QString volatility() const;
|
|
|
|
|
|
|
2018-12-23 08:48:45 +01:00
|
|
|
|
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; }
|
|
|
|
|
|
|
2018-12-24 11:31:56 +01:00
|
|
|
|
QString typeName() const override;
|
2018-12-25 13:17:04 +01:00
|
|
|
|
QString aclAllPattern() const override;
|
2018-11-25 09:06:01 +01:00
|
|
|
|
// 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;
|
2018-11-17 19:38:07 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // PGPROC_H
|