Th default values of columns are now joined with the other column data and displayed in the default column of the column tableview.

This commit is contained in:
eelke 2017-12-19 18:57:05 +01:00
parent 8402470baa
commit a69aa401b2
3 changed files with 17 additions and 9 deletions

View file

@ -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;

View file

@ -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; }

View file

@ -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;
}