2017-12-12 20:13:53 +01:00
|
|
|
|
#ifndef PGATTRIBUTE_H
|
|
|
|
|
|
#define PGATTRIBUTE_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "Pgsql_declare.h"
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
|
#include <libpq-fe.h>
|
|
|
|
|
|
#include <tuple>
|
|
|
|
|
|
|
2018-11-29 20:21:36 +01:00
|
|
|
|
class PgClass;
|
|
|
|
|
|
class PgDatabaseCatalog;
|
|
|
|
|
|
|
2017-12-12 20:13:53 +01:00
|
|
|
|
class PgAttribute {
|
|
|
|
|
|
public:
|
|
|
|
|
|
using Key = std::tuple<Oid, int16_t>;
|
|
|
|
|
|
|
|
|
|
|
|
Oid relid = InvalidOid;
|
|
|
|
|
|
QString name;
|
|
|
|
|
|
Oid typid = InvalidOid;
|
|
|
|
|
|
int32_t stattarget = 0;
|
|
|
|
|
|
int16_t num = 0;
|
|
|
|
|
|
int32_t ndims = 0; // array dimensions
|
|
|
|
|
|
int32_t typmod = -1;
|
|
|
|
|
|
bool notnull = false;
|
|
|
|
|
|
bool hasdef = false;
|
2019-08-19 19:44:07 +02:00
|
|
|
|
char identity = '\0';
|
2018-11-18 20:24:27 +01:00
|
|
|
|
bool isdropped = false;
|
2018-12-03 21:03:49 +01:00
|
|
|
|
bool islocal = true;
|
2017-12-12 20:13:53 +01:00
|
|
|
|
Oid collation = InvalidOid;
|
|
|
|
|
|
QString acl;
|
|
|
|
|
|
QString options;
|
|
|
|
|
|
|
2017-12-19 18:57:05 +01:00
|
|
|
|
QString defaultValue; ///< Comes from pg_attrdef table
|
|
|
|
|
|
|
2017-12-12 20:13:53 +01:00
|
|
|
|
|
|
|
|
|
|
bool operator==(Key _k) const { return relid == std::get<0>(_k) && num == std::get<1>(_k); }
|
|
|
|
|
|
bool operator==(const QString &n) const { return name == n; }
|
|
|
|
|
|
bool operator<(Key _k) const { return relid < std::get<0>(_k) || (relid == std::get<0>(_k) && num < std::get<1>(_k)); }
|
|
|
|
|
|
bool operator<(const PgAttribute &rhs) const { return relid < rhs.relid || (relid == rhs.relid && num < rhs.num); }
|
|
|
|
|
|
|
2018-11-29 20:21:36 +01:00
|
|
|
|
/// Return the part of the SQL create statement that can be reused for both the CREATE TABLE and ALTER TABLE ADD COLUMN
|
|
|
|
|
|
QString columnDefinition(const PgDatabaseCatalog &cat) const;
|
|
|
|
|
|
QString alterTableAddColumn(const PgDatabaseCatalog &cat, const PgClass &table) const;
|
|
|
|
|
|
QString alterTableDropColumn(const PgDatabaseCatalog &cat, const PgClass &table) const;
|
2017-12-12 20:13:53 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // PGATTRIBUTE_H
|