Skip to content
Permalink
Browse files

Accept fields of type "name" in PG 12

  • Loading branch information
github-actions authored and nyalldawson committed Jun 28, 2020
1 parent 0a84475 commit 0219ef3faa518978db92bde30bb62139150c9956
@@ -828,14 +828,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;
@@ -851,6 +845,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, generatedMap;
QMap<Oid, QMap<int, Oid> > attTypeIdMap;
@@ -1120,6 +1119,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
@@ -271,7 +271,8 @@ QList<QVariantList> QgsPostgresProviderConnection::executeSqlPrivate( const QStr
}
else
{
QgsDebugMsg( QStringLiteral( "Unhandled PostgreSQL type %1" ).arg( typName ) );
// Just a warning, usually ok
QgsDebugMsgLevel( QStringLiteral( "Unhandled PostgreSQL type %1, assuming string" ).arg( typName ), 2 );
}
}
typeMap[ rowIdx ] = vType;

0 comments on commit 0219ef3

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