diff --git a/pglab/ColumnTableModel.cpp b/pglab/ColumnTableModel.cpp index bd175e5..d198542 100644 --- a/pglab/ColumnTableModel.cpp +++ b/pglab/ColumnTableModel.cpp @@ -63,7 +63,7 @@ QVariant ColumnTableModel::headerData(int section, Qt::Orientation orientation, c = tr("Type"); break; case NullCol: - c = tr("Nullable"); + c = tr("Not null"); break; case DefaultCol: c = tr("Default"); @@ -136,10 +136,10 @@ QVariant ColumnTableModel::getData(const QModelIndex &index) const s = getTypeDisplayString(*m_catalog, t.typid); break; case NullCol: - s = t.notnull ? "NOT NULL" : ""; + s = QString::fromStdU16String(t.notnull ? u"\u2713" : u""); break; case DefaultCol: - s = ""; + s = t.defaultValue; break; case CollationCol: s = ""; //t.collation; diff --git a/pglab/PgAttribute.h b/pglab/PgAttribute.h index 31334c7..818e8e7 100644 --- a/pglab/PgAttribute.h +++ b/pglab/PgAttribute.h @@ -24,6 +24,8 @@ public: QString acl; QString options; + QString defaultValue; ///< Comes from pg_attrdef table + 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; } diff --git a/pglab/PgAttributeContainer.cpp b/pglab/PgAttributeContainer.cpp index 531dfd1..89eda0f 100644 --- a/pglab/PgAttributeContainer.cpp +++ b/pglab/PgAttributeContainer.cpp @@ -1,13 +1,19 @@ #include "PgAttributeContainer.h" #include "Pgsql_Col.h" +//SELECT attname, pg_get_expr(adbin, adrelid) AS def_value +//FROM pg_attribute +// JOIN pg_attrdef ON attrelid=adrelid AND attnum=adnum +//WHERE atthasdef=true + std::string PgAttributeContainer::getLoadQuery() const { - return - "SELECT attrelid, attname, atttypid, attstattarget, \n" - " attnum, attndims, atttypmod, attnotnull, atthasdef, \n" - " attcollation, attacl, attoptions \n" - " FROM pg_catalog.pg_attribute"; + return R"__( +SELECT attrelid, attname, atttypid, attstattarget, + attnum, attndims, atttypmod, attnotnull, atthasdef, + attcollation, attacl, attoptions, pg_get_expr(adbin, adrelid) AS def_value +FROM pg_catalog.pg_attribute + LEFT JOIN pg_attrdef ON attrelid=adrelid AND attnum=adnum)__"; } PgAttribute PgAttributeContainer::loadElem(const Pgsql::Row &row) @@ -16,7 +22,7 @@ PgAttribute PgAttributeContainer::loadElem(const Pgsql::Row &row) PgAttribute v; col >> v.relid >> v.name >> v.typid >> v.stattarget >> v.num >> v.ndims >> v.typmod >> v.notnull >> v.hasdef - >> v.collation >> v.acl >> v.options; + >> v.collation >> v.acl >> v.options >> v.defaultValue; return v; }