Skip to content

Commit bbe80b3

Browse files
author
jef
committedJan 14, 2011
postgres provider: fix enumeration parsing
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15048 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed
 

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,35 +1996,21 @@ void QgsPostgresProvider::enumValues( int index, QStringList& enumList )
19961996
bool QgsPostgresProvider::parseEnumRange( QStringList& enumValues, const QString& attributeName ) const
19971997
{
19981998
enumValues.clear();
1999-
QString enumRangeSql = QString( "SELECT enum_range(%1) from %2 limit 1" )
2000-
.arg( quotedIdentifier( attributeName ) )
2001-
.arg( mQuery );
1999+
2000+
QString enumRangeSql = QString( "SELECT enumlabel FROM pg_catalog.pg_enum WHERE enumtypid=(SELECT atttypid::regclass FROM pg_attribute WHERE attrelid=%1::regclass AND attname=%2)" )
2001+
.arg( quotedValue( mQuery ) )
2002+
.arg( quotedValue( attributeName ) );
20022003
Result enumRangeRes = connectionRO->PQexec( enumRangeSql );
2003-
if ( PQresultStatus( enumRangeRes ) == PGRES_TUPLES_OK && PQntuples( enumRangeRes ) > 0 )
2004-
{
2005-
QString enumRangeString = PQgetvalue( enumRangeRes, 0, 0 );
2006-
//strip away the brackets at begin and end
2007-
enumRangeString.chop( 1 );
2008-
enumRangeString.remove( 0, 1 );
2009-
QStringList rangeSplit = enumRangeString.split( "," );
2010-
QStringList::const_iterator range_it = rangeSplit.constBegin();
2011-
for ( ; range_it != rangeSplit.constEnd(); ++range_it )
2012-
{
2013-
QString currentEnumValue = *range_it;
2014-
//remove quotes from begin and end of the value
2015-
if ( currentEnumValue.startsWith( "'" ) || currentEnumValue.startsWith( "\"" ) )
2016-
{
2017-
currentEnumValue.remove( 0, 1 );
2018-
}
2019-
if ( currentEnumValue.endsWith( "'" ) || currentEnumValue.endsWith( "\"" ) )
2020-
{
2021-
currentEnumValue.chop( 1 );
2022-
}
2023-
enumValues << currentEnumValue;
2024-
}
2025-
return true;
2004+
2005+
if ( PQresultStatus( enumRangeRes ) != PGRES_TUPLES_OK )
2006+
return false;
2007+
2008+
for ( int i = 0; i < PQntuples( enumRangeRes ); i++ )
2009+
{
2010+
enumValues << QString::fromUtf8( PQgetvalue( enumRangeRes, i, 0 ) );
20262011
}
2027-
return false;
2012+
2013+
return true;
20282014
}
20292015

20302016
bool QgsPostgresProvider::parseDomainCheckConstraint( QStringList& enumValues, const QString& attributeName ) const

0 commit comments

Comments
 (0)
Please sign in to comment.