Skip to content

Commit 498e551

Browse files
committed
[postgres] fix domain not in public schema
fix #18053 correctly set enumeration widget in case the domain is not in public schema also fixes an issue if two domain with the same are present in two schemas
1 parent 779fe1a commit 498e551

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,9 @@ void QgsPostgresProvider::enumValues( int index, QStringList &enumList ) const
16751675
QString fieldName = mAttributeFields.at( index ).name();
16761676
QString typeName = mAttributeFields.at( index ).typeName();
16771677

1678+
// Remove schema extension from typeName
1679+
typeName.remove( QRegularExpression( "^([^.]+\\.)+" ) );
1680+
16781681
//is type an enum?
16791682
QString typeSql = QStringLiteral( "SELECT typtype FROM pg_type WHERE typname=%1" ).arg( quotedValue( typeName ) );
16801683
QgsPostgresResult typeRes( connectionRO()->PQexec( typeSql ) );
@@ -1727,12 +1730,14 @@ bool QgsPostgresProvider::parseDomainCheckConstraint( QStringList &enumValues, c
17271730
enumValues.clear();
17281731

17291732
//is it a domain type with a check constraint?
1730-
QString domainSql = QStringLiteral( "SELECT domain_name FROM information_schema.columns WHERE table_name=%1 AND column_name=%2" ).arg( quotedValue( mTableName ), quotedValue( attributeName ) );
1733+
QString domainSql = QStringLiteral( "SELECT domain_name, domain_schema FROM information_schema.columns WHERE table_name=%1 AND column_name=%2" ).arg( quotedValue( mTableName ), quotedValue( attributeName ) );
17311734
QgsPostgresResult domainResult( connectionRO()->PQexec( domainSql ) );
1732-
if ( domainResult.PQresultStatus() == PGRES_TUPLES_OK && domainResult.PQntuples() > 0 )
1735+
if ( domainResult.PQresultStatus() == PGRES_TUPLES_OK && domainResult.PQntuples() > 0 && !domainResult.PQgetvalue( 0, 0 ).isNull() )
17331736
{
17341737
//a domain type
1735-
QString domainCheckDefinitionSql = QStringLiteral( "SELECT consrc FROM pg_constraint WHERE conname=(SELECT constraint_name FROM information_schema.domain_constraints WHERE domain_name=%1)" ).arg( quotedValue( domainResult.PQgetvalue( 0, 0 ) ) );
1738+
QString domainCheckDefinitionSql = QStringLiteral( "SELECT consrc FROM pg_constraint WHERE conname=(SELECT constraint_name FROM information_schema.domain_constraints WHERE domain_name=%1 AND domain_schema=%2)" )
1739+
.arg( quotedValue( domainResult.PQgetvalue( 0, 0 ) ) )
1740+
.arg( quotedValue( domainResult.PQgetvalue( 0, 1 ) ) );
17361741
QgsPostgresResult domainCheckRes( connectionRO()->PQexec( domainCheckDefinitionSql ) );
17371742
if ( domainCheckRes.PQresultStatus() == PGRES_TUPLES_OK && domainCheckRes.PQntuples() > 0 )
17381743
{

0 commit comments

Comments
 (0)