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
|
|
@ -8,7 +8,9 @@
|
|||
#include "PgNamespaceContainer.h"
|
||||
#include "PgTypeContainer.h"
|
||||
#include "Pgsql_Connection.h"
|
||||
#include "Pgsql_oids.h"
|
||||
|
||||
using namespace Pgsql;
|
||||
|
||||
QString getRoleNameFromOid(const PgDatabaseCatalog &cat, Oid oid)
|
||||
{
|
||||
|
|
@ -53,18 +55,37 @@ QString getTablespaceDisplayString(const PgDatabaseCatalog &cat, Oid 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 t = tc->getByKey(oid);
|
||||
QString s;
|
||||
if (t.category == TypCategory::Array) {
|
||||
auto et = tc->getByKey(t.elem);
|
||||
s = et.name;
|
||||
// auto et = tc->getByKey(t.elem);
|
||||
// s = et.name;
|
||||
s = getTypeDisplayString(cat, t.elem, typmod);
|
||||
s += "[]";
|
||||
}
|
||||
else {
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue