Skip to content
Permalink
Browse files
postgres provider: fix enumeration parsing
git-svn-id: http://svn.osgeo.org/qgis/trunk@15048 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jan 14, 2011
1 parent 075d068 commit 78cc7abf2a40599c48c23ed0f3cbb248f7540f18
Showing with 13 additions and 27 deletions.
  1. +13 −27 src/providers/postgres/qgspostgresprovider.cpp
@@ -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

0 comments on commit 78cc7ab

Please sign in to comment.