Skip to content

Commit

Permalink
postgres provider: fix enumeration parsing
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15048 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jan 14, 2011
1 parent 91387e1 commit bbe80b3
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1996,35 +1996,21 @@ void QgsPostgresProvider::enumValues( int index, QStringList& enumList )
bool QgsPostgresProvider::parseEnumRange( QStringList& enumValues, const QString& attributeName ) const
{
enumValues.clear();
QString enumRangeSql = QString( "SELECT enum_range(%1) from %2 limit 1" )
.arg( quotedIdentifier( attributeName ) )
.arg( mQuery );

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)" )
.arg( quotedValue( mQuery ) )
.arg( quotedValue( attributeName ) );
Result enumRangeRes = connectionRO->PQexec( enumRangeSql );
if ( PQresultStatus( enumRangeRes ) == PGRES_TUPLES_OK && PQntuples( enumRangeRes ) > 0 )
{
QString enumRangeString = PQgetvalue( enumRangeRes, 0, 0 );
//strip away the brackets at begin and end
enumRangeString.chop( 1 );
enumRangeString.remove( 0, 1 );
QStringList rangeSplit = enumRangeString.split( "," );
QStringList::const_iterator range_it = rangeSplit.constBegin();
for ( ; range_it != rangeSplit.constEnd(); ++range_it )
{
QString currentEnumValue = *range_it;
//remove quotes from begin and end of the value
if ( currentEnumValue.startsWith( "'" ) || currentEnumValue.startsWith( "\"" ) )
{
currentEnumValue.remove( 0, 1 );
}
if ( currentEnumValue.endsWith( "'" ) || currentEnumValue.endsWith( "\"" ) )
{
currentEnumValue.chop( 1 );
}
enumValues << currentEnumValue;
}
return true;

if ( PQresultStatus( enumRangeRes ) != PGRES_TUPLES_OK )
return false;

for ( int i = 0; i < PQntuples( enumRangeRes ); i++ )
{
enumValues << QString::fromUtf8( PQgetvalue( enumRangeRes, i, 0 ) );
}
return false;

return true;
}

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

0 comments on commit bbe80b3

Please sign in to comment.