Skip to content
Permalink
Browse files
[postgres] use pg_type rather than information_schema.domain_constrai…
…nts to retrieve domain

otherwise there is no warranty to retrieve the correct constraint as its name is not unique
  • Loading branch information
3nids committed Feb 11, 2018
1 parent 781b587 commit bfe35c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
@@ -1735,7 +1735,15 @@ bool QgsPostgresProvider::parseDomainCheckConstraint( QStringList &enumValues, c
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 AND domain_schema=%2)" )
QString domainCheckDefinitionSql = QStringLiteral( ""
"SELECT consrc FROM pg_constraint "
" WHERE contypid =("
" SELECT oid FROM pg_type "
" WHERE typname = %1 "
" AND typnamespace =("
" SELECT oid FROM pg_namespace WHERE nspname = %2"
" )"
" )" )
.arg( quotedValue( domainResult.PQgetvalue( 0, 0 ) ) )
.arg( quotedValue( domainResult.PQgetvalue( 0, 1 ) ) );
QgsPostgresResult domainCheckRes( connectionRO()->PQexec( domainCheckDefinitionSql ) );
@@ -42,6 +42,7 @@ def setUpClass(cls):
def test_postgres_domain(self):
self.assertEqual(self.vl.dataProvider().enumValues(1), ['red', 'green', 'blue'])
self.assertEqual(self.vl.dataProvider().enumValues(2), ['yellow', 'cyan', 'magenta'])
self.assertEqual(self.vl.dataProvider().enumValues(3), ['Alchemilla', 'Alstroemeria', 'Alyssum'])


if __name__ == '__main__':
@@ -11,9 +11,15 @@ CREATE DOMAIN qgis_test.colordomain
COLLATE pg_catalog."default"
CONSTRAINT domainconstraint CHECK (VALUE = ANY (ARRAY['yellow'::text, 'cyan'::text, 'magenta'::text]));

CREATE DOMAIN qgis_test.flowerdomain
AS text
COLLATE pg_catalog."default"
CONSTRAINT domainconstraint CHECK (VALUE = ANY (ARRAY['Alchemilla'::text, 'Alstroemeria'::text, 'Alyssum'::text]));

CREATE TABLE qgis_test.colors
(
id SERIAL NOT NULL,
color_public colordomain,
color_qgis qgis_test.colordomain
color_qgis qgis_test.colordomain,
flower qgis_test.flowerdomain
)

0 comments on commit bfe35c2

Please sign in to comment.