[QGIS Commit] r15048 - trunk/qgis/src/providers/postgres

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Jan 14 15:47:27 EST 2011


Author: jef
Date: 2011-01-14 12:47:27 -0800 (Fri, 14 Jan 2011)
New Revision: 15048

Modified:
   trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
Log:
postgres provider: fix enumeration parsing

Modified: trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
===================================================================
--- trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp	2011-01-14 20:47:19 UTC (rev 15047)
+++ trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp	2011-01-14 20:47:27 UTC (rev 15048)
@@ -1996,35 +1996,21 @@
 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 )
+
+  if ( PQresultStatus( enumRangeRes ) != PGRES_TUPLES_OK )
+    return false;
+
+  for ( int i = 0; i < PQntuples( enumRangeRes ); i++ )
   {
-    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;
+    enumValues << QString::fromUtf8( PQgetvalue( enumRangeRes, i, 0 ) );
   }
-  return false;
+
+  return true;
 }
 
 bool QgsPostgresProvider::parseDomainCheckConstraint( QStringList& enumValues, const QString& attributeName ) const



More information about the QGIS-commit mailing list