The global function for getting a typename from an oid now supports passing the typmod of a column.
This is used by the list of columns for a table. Works for char, varchar, text and numeric.
This commit is contained in:
parent
6599498556
commit
c324daa75b
3 changed files with 26 additions and 5 deletions
|
|
@ -133,7 +133,7 @@ QVariant ColumnTableModel::getData(const QModelIndex &index) const
|
||||||
s = t.name;
|
s = t.name;
|
||||||
break;
|
break;
|
||||||
case TypeCol:
|
case TypeCol:
|
||||||
s = getTypeDisplayString(*m_catalog, t.typid);
|
s = getTypeDisplayString(*m_catalog, t.typid, t.typmod);
|
||||||
break;
|
break;
|
||||||
case NullCol:
|
case NullCol:
|
||||||
s = QString::fromStdU16String(t.notnull ? u"\u2713" : u"");
|
s = QString::fromStdU16String(t.notnull ? u"\u2713" : u"");
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@
|
||||||
#include "PgNamespaceContainer.h"
|
#include "PgNamespaceContainer.h"
|
||||||
#include "PgTypeContainer.h"
|
#include "PgTypeContainer.h"
|
||||||
#include "Pgsql_Connection.h"
|
#include "Pgsql_Connection.h"
|
||||||
|
#include "Pgsql_oids.h"
|
||||||
|
|
||||||
|
using namespace Pgsql;
|
||||||
|
|
||||||
QString getRoleNameFromOid(const PgDatabaseCatalog &cat, Oid oid)
|
QString getRoleNameFromOid(const PgDatabaseCatalog &cat, Oid oid)
|
||||||
{
|
{
|
||||||
|
|
@ -53,18 +55,37 @@ QString getTablespaceDisplayString(const PgDatabaseCatalog &cat, Oid oid)
|
||||||
return QString("ts %1").arg(oid);
|
return QString("ts %1").arg(oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getTypeDisplayString(const PgDatabaseCatalog &cat, Oid oid)
|
QString getTypeDisplayString(const PgDatabaseCatalog &cat, Oid oid, int32_t typmod)
|
||||||
{
|
{
|
||||||
auto tc = cat.types();
|
auto tc = cat.types();
|
||||||
auto t = tc->getByKey(oid);
|
auto t = tc->getByKey(oid);
|
||||||
QString s;
|
QString s;
|
||||||
if (t.category == TypCategory::Array) {
|
if (t.category == TypCategory::Array) {
|
||||||
auto et = tc->getByKey(t.elem);
|
// auto et = tc->getByKey(t.elem);
|
||||||
s = et.name;
|
// s = et.name;
|
||||||
|
s = getTypeDisplayString(cat, t.elem, typmod);
|
||||||
s += "[]";
|
s += "[]";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
s = t.name;
|
s = t.name;
|
||||||
|
switch (oid) {
|
||||||
|
case varchar_oid:
|
||||||
|
case char_oid:
|
||||||
|
case text_oid:
|
||||||
|
if (typmod > 4)
|
||||||
|
s += QString::asprintf("(%d)", typmod-4);
|
||||||
|
break;
|
||||||
|
case numeric_oid:
|
||||||
|
if (typmod > 4) {
|
||||||
|
int prec = (typmod - 4) / 65536;
|
||||||
|
int scale = (typmod - 4) % 65536;
|
||||||
|
if (scale > 0)
|
||||||
|
s += QString::asprintf("(%d,%d)", prec, scale);
|
||||||
|
else
|
||||||
|
s += QString::asprintf("(%d)", prec);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ QString getRoleNameFromOid(const PgDatabaseCatalog &cat, Oid oid);
|
||||||
QString getRoleDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
QString getRoleDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
||||||
QString getNamespaceDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
QString getNamespaceDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
||||||
QString getTablespaceDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
QString getTablespaceDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
||||||
QString getTypeDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
QString getTypeDisplayString(const PgDatabaseCatalog &cat, Oid oid, int32_t typmod = -1);
|
||||||
|
|
||||||
|
|
||||||
#endif // PGSQLDATABASECATALOGUE_H
|
#endif // PGSQLDATABASECATALOGUE_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue