Skip to content
Permalink
Browse files

Accept fields of type "name" in PG 12

Fixes #37313

(cherry picked from commit e4718d7)
  • Loading branch information
elpaso authored and nyalldawson committed Jul 21, 2020
1 parent a169a35 commit dbd5ae03ae94b772e59f2877105ecd4137dd917f
@@ -805,14 +805,8 @@ bool QgsPostgresProvider::loadFields()
}
}

// Populate the field vector for this layer. The field vector contains
// field name, type, length, and precision (if numeric)
QString sql = QStringLiteral( "SELECT * FROM %1 LIMIT 0" ).arg( mQuery );

QgsPostgresResult result( connectionRO()->PQexec( sql ) );

// Collect type info
sql = QStringLiteral( "SELECT oid,typname,typtype,typelem,typlen FROM pg_type" );
QString sql = QStringLiteral( "SELECT oid,typname,typtype,typelem,typlen FROM pg_type" );
QgsPostgresResult typeResult( connectionRO()->PQexec( sql ) );

QMap<Oid, PGTypeInfo> typeMap;
@@ -828,6 +822,11 @@ bool QgsPostgresProvider::loadFields()
typeMap.insert( typeResult.PQgetvalue( i, 0 ).toUInt(), typeInfo );
}

// Populate the field vector for this layer. The field vector contains
// field name, type, length, and precision (if numeric)
sql = QStringLiteral( "SELECT * FROM %1 LIMIT 0" ).arg( mQuery );

QgsPostgresResult result( connectionRO()->PQexec( sql ) );

QMap<Oid, QMap<int, QString> > fmtFieldTypeMap, descrMap, defValMap, identityMap;
QMap<Oid, QMap<int, Oid> > attTypeIdMap;
@@ -1086,6 +1085,13 @@ bool QgsPostgresProvider::loadFields()
fieldType = QVariant::Bool;
fieldSize = -1;
}
// PG 12 returns "name" type for some system table fields (e.g. information_schema.tables)
else if ( fieldTypeName == QLatin1String( "name" ) )
{
fieldSubType = QVariant::String;
// "name" type lenght is 64 according to: SELECT typlen FROM pg_type WHERE typname = 'name';
fieldSize = 64;
}
else
{
// be tolerant in case of views: this might be a field used as a key
@@ -255,6 +255,15 @@ QList<QVariantList> QgsPostgresProviderConnection::executeSqlPrivate( const QStr
{
vType = QVariant::Bool;
}
else if ( typName == QStringLiteral( "char" ) )
{
vType = QVariant::Char;
}
else
{
// Just a warning, usually ok
QgsDebugMsgLevel( QStringLiteral( "Unhandled PostgreSQL type %1, assuming string" ).arg( typName ), 2 );
}
}
typeMap[ rowIdx ] = vType;
}

0 comments on commit dbd5ae0

Please sign in to comment.
You can’t perform that action at this time.