@@ -711,6 +711,10 @@ struct PGTypeInfo
711
711
712
712
bool QgsPostgresProvider::loadFields ()
713
713
{
714
+
715
+ // Clear cached information about enum values support
716
+ mShared ->clearSupportsEnumValuesCache ();
717
+
714
718
if ( !mIsQuery )
715
719
{
716
720
QgsDebugMsg ( QStringLiteral ( " Loading fields for table %1" ).arg ( mTableName ) );
@@ -1683,42 +1687,50 @@ QStringList QgsPostgresProvider::uniqueStringsMatching( int index, const QString
1683
1687
1684
1688
void QgsPostgresProvider::enumValues ( int index, QStringList &enumList ) const
1685
1689
{
1686
- enumList.clear ();
1687
1690
1688
1691
if ( index < 0 || index >= mAttributeFields .count () )
1689
1692
return ;
1690
1693
1694
+ if ( ! mShared ->fieldSupportsEnumValuesIsSet ( index ) )
1695
+ {
1696
+ mShared ->setFieldSupportsEnumValues ( index, true );
1697
+ }
1698
+ else if ( ! mShared ->fieldSupportsEnumValues ( index ) )
1699
+ {
1700
+ return ;
1701
+ }
1702
+
1691
1703
// find out type of index
1692
- QString fieldName = mAttributeFields .at ( index ).name ();
1704
+ const QString fieldName = mAttributeFields .at ( index ).name ();
1693
1705
QString typeName = mAttributeFields .at ( index ).typeName ();
1694
1706
1695
1707
// Remove schema extension from typeName
1696
1708
typeName.remove ( QRegularExpression ( " ^([^.]+\\ .)+" ) );
1697
1709
1698
1710
// is type an enum?
1699
- QString typeSql = QStringLiteral ( " SELECT typtype FROM pg_type WHERE typname=%1" ).arg ( quotedValue ( typeName ) );
1711
+ const QString typeSql = QStringLiteral ( " SELECT typtype FROM pg_type WHERE typname=%1" ).arg ( quotedValue ( typeName ) );
1700
1712
QgsPostgresResult typeRes ( connectionRO ()->PQexec ( typeSql ) );
1701
1713
if ( typeRes.PQresultStatus () != PGRES_TUPLES_OK || typeRes.PQntuples () < 1 )
1702
1714
{
1715
+ mShared ->setFieldSupportsEnumValues ( index, false );
1703
1716
return ;
1704
1717
}
1705
1718
1706
-
1707
- QString typtype = typeRes.PQgetvalue ( 0 , 0 );
1719
+ const QString typtype = typeRes.PQgetvalue ( 0 , 0 );
1708
1720
if ( typtype.compare ( QLatin1String ( " e" ), Qt::CaseInsensitive ) == 0 )
1709
1721
{
1710
1722
// try to read enum_range of attribute
1711
1723
if ( !parseEnumRange ( enumList, fieldName ) )
1712
1724
{
1713
- enumList. clear ( );
1725
+ mShared -> setFieldSupportsEnumValues ( index, false );
1714
1726
}
1715
1727
}
1716
1728
else
1717
1729
{
1718
1730
// is there a domain check constraint for the attribute?
1719
1731
if ( !parseDomainCheckConstraint ( enumList, fieldName ) )
1720
1732
{
1721
- enumList. clear ( );
1733
+ mShared -> setFieldSupportsEnumValues ( index, false );
1722
1734
}
1723
1735
}
1724
1736
}
@@ -5169,3 +5181,28 @@ void QgsPostgresSharedData::clear()
5169
5181
mFeaturesCounted = -1 ;
5170
5182
mFidCounter = 0 ;
5171
5183
}
5184
+
5185
+ void QgsPostgresSharedData::clearSupportsEnumValuesCache ()
5186
+ {
5187
+ QMutexLocker locker ( &mMutex );
5188
+ mFieldSupportsEnumValues .clear ();
5189
+ }
5190
+
5191
+ bool QgsPostgresSharedData::fieldSupportsEnumValuesIsSet ( int index )
5192
+ {
5193
+ QMutexLocker locker ( &mMutex );
5194
+ return mFieldSupportsEnumValues .contains ( index );
5195
+ }
5196
+
5197
+ bool QgsPostgresSharedData::fieldSupportsEnumValues ( int index )
5198
+ {
5199
+ QMutexLocker locker ( &mMutex );
5200
+ return mFieldSupportsEnumValues .contains ( index ) && mFieldSupportsEnumValues [ index ];
5201
+ }
5202
+
5203
+ void QgsPostgresSharedData::setFieldSupportsEnumValues ( int index, bool isSupported )
5204
+ {
5205
+ QMutexLocker locker ( &mMutex );
5206
+ mFieldSupportsEnumValues [ index ] = isSupported;
5207
+ }
5208
+
0 commit comments