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:
|
2022-09-06 11:17:18 +00:00
|
|
|
|
enum class Identity {
|
|
|
|
|
|
None,
|
|
|
|
|
|
Always,
|
|
|
|
|
|
ByDefault
|
|
|
|
|
|
};
|
|
|
|
|
|
enum class Generated {
|
|
|
|
|
|
None,
|
|
|
|
|
|
Stored
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-04-13 09:06:51 +02:00
|
|
|
|
class Key {
|
|
|
|
|
|
public:
|
|
|
|
|
|
Key() = default;
|
|
|
|
|
|
Key(Oid relationId, int16_t num)
|
|
|
|
|
|
: RelationId(relationId)
|
|
|
|
|
|
, Num(num)
|
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
std::strong_ordering operator <=> (const Key &rhs) const = default;
|
|
|
|
|
|
private:
|
|
|
|
|
|
Oid RelationId = InvalidOid;
|
|
|
|
|
|
int16_t Num = 0;
|
|
|
|
|
|
};
|
2017-12-12 20:13:53 +01:00
|
|
|
|
|
|
|
|
|
|
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';
|
2022-09-06 11:17:18 +00:00
|
|
|
|
char generated = '\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;
|
|
|
|
|
|
|
2022-09-06 11:17:18 +00:00
|
|
|
|
Identity getIdentity() const;
|
|
|
|
|
|
Generated getGenerated() const;
|
|
|
|
|
|
|
2017-12-19 18:57:05 +01:00
|
|
|
|
QString defaultValue; ///< Comes from pg_attrdef table
|
2019-12-01 06:40:11 +01:00
|
|
|
|
QString sername, serschema; // serial sequence name and schema
|
2021-03-08 17:23:34 +01:00
|
|
|
|
QString description; ///< from pg_description
|
2017-12-12 20:13:53 +01:00
|
|
|
|
|
2024-04-13 09:06:51 +02:00
|
|
|
|
Key key() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return Key(relid, num);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::strong_ordering operator <=> (const Key& rhs) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return key() <=> rhs;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(const Key &k) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return key() == k;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-12 20:13:53 +01:00
|
|
|
|
bool operator==(const QString &n) const { return name == n; }
|
|
|
|
|
|
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;
|
2021-07-02 20:42:32 +02:00
|
|
|
|
QString commentStatement(const PgDatabaseCatalog &cat, const PgClass &table) const;
|
2019-12-01 06:40:11 +01:00
|
|
|
|
|
|
|
|
|
|
bool isSerial() const { return !sername.isEmpty(); }
|
2017-12-12 20:13:53 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // PGATTRIBUTE_H
|