Skip to content

Commit

Permalink
[postgres] fix domain not in public schema
Browse files Browse the repository at this point in the history
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
  • Loading branch information
3nids committed Feb 10, 2018
1 parent 779fe1a commit 498e551
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -1675,6 +1675,9 @@ void QgsPostgresProvider::enumValues( int index, QStringList &enumList ) const
QString fieldName = mAttributeFields.at( index ).name();
QString typeName = mAttributeFields.at( index ).typeName();

// Remove schema extension from typeName
typeName.remove( QRegularExpression( "^([^.]+\\.)+" ) );

//is type an enum?
QString typeSql = QStringLiteral( "SELECT typtype FROM pg_type WHERE typname=%1" ).arg( quotedValue( typeName ) );
QgsPostgresResult typeRes( connectionRO()->PQexec( typeSql ) );
Expand Down Expand Up @@ -1727,12 +1730,14 @@ bool QgsPostgresProvider::parseDomainCheckConstraint( QStringList &enumValues, c
enumValues.clear();

//is it a domain type with a check constraint?
QString domainSql = QStringLiteral( "SELECT domain_name FROM information_schema.columns WHERE table_name=%1 AND column_name=%2" ).arg( quotedValue( mTableName ), quotedValue( attributeName ) );
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 ) );
QgsPostgresResult domainResult( connectionRO()->PQexec( domainSql ) );
if ( domainResult.PQresultStatus() == PGRES_TUPLES_OK && domainResult.PQntuples() > 0 )
if ( domainResult.PQresultStatus() == PGRES_TUPLES_OK && domainResult.PQntuples() > 0 && !domainResult.PQgetvalue( 0, 0 ).isNull() )
{
//a domain type
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 ) ) );
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)" )
.arg( quotedValue( domainResult.PQgetvalue( 0, 0 ) ) )
.arg( quotedValue( domainResult.PQgetvalue( 0, 1 ) ) );
QgsPostgresResult domainCheckRes( connectionRO()->PQexec( domainCheckDefinitionSql ) );
if ( domainCheckRes.PQresultStatus() == PGRES_TUPLES_OK && domainCheckRes.PQntuples() > 0 )
{
Expand Down

0 comments on commit 498e551

Please sign in to comment.