Added typeName function to PgObject as it might be useful for building generic functions.

This commit is contained in:
eelke 2018-12-24 11:31:56 +01:00
parent b210c570fc
commit 3f337b2cca
21 changed files with 83 additions and 15 deletions

View file

@ -73,6 +73,21 @@ QString PgClass::createSql() const
return createSqlCache;
}
QString PgClass::typeName() const
{
switch (kind) {
case RelKind::Table: return "TABLE";
case RelKind::Index: return "INDEX";
case RelKind::Sequence: return "SEQUENCE";
case RelKind::View: return "VIEW";
case RelKind::MaterializedView: return "MATERIALIZED VIEW";
case RelKind::Composite: return "COMPOSITE";
case RelKind::Toast: return "TOAST";
case RelKind::ForeignTable: return "FOREIGN TABLE";
}
throw std::runtime_error("Unexpected value in PgClass::typeName()");
}
QString PgClass::createTableSql() const
{
QString sql;

View file

@ -66,6 +66,7 @@ public:
// bool operator<(const PgClass &rhs) const { return oid < rhs.oid; }
QString createSql() const;
QString typeName() const override;
private:
mutable QString createSqlCache;

View file

@ -1,2 +1,7 @@
#include "PgCollation.h"
QString PgCollation::typeName() const
{
return "COLLATION";
}

View file

@ -20,6 +20,7 @@ public:
QString collcollate; // name
QString collctype; // name
QString typeName() const override;
};
#endif // PGCOLLATION_H

View file

@ -167,3 +167,8 @@ QString ForeignKeyMatchToString(ForeignKeyMatch fkm)
//{
//}
QString PgConstraint::typeName() const
{
return "CONSTRAINT";
}

View file

@ -75,6 +75,8 @@ public:
QString definition;
using PgNamespaceObject::PgNamespaceObject;
QString typeName() const override;
};

View file

@ -1,2 +1,6 @@
#include "PgDatabase.h"
QString PgDatabase::typeName() const
{
return "DATABASE";
}

View file

@ -8,8 +8,6 @@
class PgDatabase: public PgServerObject {
public:
// Oid oid = InvalidOid;
// QString name;
Oid dba; // owner?
int encoding;
QString collate;
@ -24,10 +22,7 @@ public:
bool isValid() const { return oid() != InvalidOid; }
// bool operator==(Oid _oid) const { return oid() == _oid; }
// bool operator==(const QString &n) const { return objectName() == n; }
// bool operator<(Oid _oid) const { return oid() < _oid; }
// bool operator<(const PgDatabase &rhs) const { return oid() < rhs.oid(); }
QString typeName() const override;
};
#endif // PGDATABASE_H

View file

@ -75,3 +75,8 @@ QString PgIndex::dropSql() const
% ";";
return result;
}
QString PgIndex::typeName() const
{
return "INDEX";
}

View file

@ -40,6 +40,8 @@ public:
QString createSql() const;
QString dropSql() const;
QString typeName() const override;
};
#endif // PGINDEX_H

View file

@ -9,3 +9,8 @@ QString PgLanguage::dropSql() const
{
throw std::exception("PgLanguage::dropSql() not implemented");
}
QString PgLanguage::typeName() const
{
return "LANGUAGE";
}

View file

@ -30,6 +30,7 @@ public:
bool isPlpgsql() const { return objectName() == "plpgsql"; }
bool isSql() const { return objectName() == "sql"; }
QString typeName() const override;
};
#endif // PGLANGUAGE_H

View file

@ -6,3 +6,8 @@ bool PgNamespace::isSystemCatalog() const
return n.startsWith("pg_")
|| n == "information_schema";
}
QString PgNamespace::typeName() const
{
return "SCHEMA";
}

View file

@ -9,20 +9,13 @@
/// Object representing a namespace within a database
class PgNamespace: public PgDatabaseObject {
public:
// Oid oid = InvalidOid;
// QString name;
Oid owner = InvalidOid;
QString acl;
using PgDatabaseObject::PgDatabaseObject;
// bool operator==(Oid _oid) const { return oid == _oid; }
// bool operator==(const QString &n) const { return objectName() == n; }
// bool operator<(Oid _oid) const { return oid < _oid; }
// bool operator<(const PgNamespace &rhs) const { return oid < rhs.oid; }
bool isSystemCatalog() const;
QString typeName() const override;
};
#endif // PGNAMESPACE_H

View file

@ -15,6 +15,7 @@ public:
const QString& objectName() const;
/// Default implementation uses objectName and add quotes when needed.
virtual QString quotedObjectName() const;
virtual QString typeName() const = 0;
bool operator==(Oid _oid) const { return m_oid == _oid; }
bool operator==(const QString &n) const { return m_name == n; }

View file

@ -370,3 +370,17 @@ QString PgProc::volatility() const
}
return "<unknown>";
}
QString PgProc::typeName() const
{
switch (kind) {
case ProcKind::Function:
case ProcKind::Window:
return "FUNCTION";
case ProcKind::Procedure:
return "PROCEDURE";
case ProcKind::Aggregate:
return "AGGREGATE";
}
throw std::runtime_error("Unexpected kind in PgProc::typeName()");
}

View file

@ -90,7 +90,6 @@ public:
const 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; }
@ -98,6 +97,7 @@ public:
bool isAggregate() const { return kind == ProcKind::Aggregate; }
bool isWindow() const { return kind == ProcKind::Window; }
QString typeName() const override;
// bool isTrigger() const
// {
// return typname == wxT("\"trigger\"") || typname == wxT("trigger") || typname == wxT("event_trigger") || typname == wxT("\"event_trigger\""))

View file

@ -154,3 +154,8 @@ QString PgTrigger::arguments() const
}
return output;
}
QString PgTrigger::typeName() const
{
return "TRIGGER";
}

View file

@ -63,6 +63,8 @@ public:
//}
QString arguments() const;
QString typeName() const override;
private:
mutable QString m_dropSql; // cache
mutable QString m_createSql; // cache

View file

@ -50,3 +50,8 @@ void operator<<(TypCategory &s, const Pgsql::Value &v)
break;
}
}
QString PgType::typeName() const
{
return "TYPE";
}

View file

@ -65,6 +65,8 @@ public:
using PgNamespaceObject::PgNamespaceObject;
QString typeName() const override;
// 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; }