Skip to content

Commit

Permalink
ogr provider:
Browse files Browse the repository at this point in the history
- support for OLCStringsAsUTF8 (fixes #4558)
- remove quotation on "ORDER BY" (produces a syntax error otherwise)
- support for null values in uniqueValues/minimumValue/maximumValue
  • Loading branch information
jef-n authored and alexbruy committed Dec 28, 2011
1 parent 9611ec3 commit 397e3b4
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -357,7 +357,19 @@ QStringList QgsOgrProvider::subLayers() const

void QgsOgrProvider::setEncoding( const QString& e )
{
#if defined(OLCStringsAsUTF8)
if ( !OGR_L_TestCapability( ogrLayer, OLCStringsAsUTF8 ) )
{
QgsVectorDataProvider::setEncoding( e );
}
else
{
QgsVectorDataProvider::setEncoding( "UTF-8" );
}
#else
QgsVectorDataProvider::setEncoding( e );
#endif

loadFields();
}

Expand Down Expand Up @@ -1884,7 +1896,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
sql += QString( " WHERE %1" ).arg( mSubsetString );
}

sql += QString( " ORDER BY %1" ).arg( quotedIdentifier( fld.name() ) );
sql += QString( " ORDER BY %1 ASC" ).arg( fld.name() ); // quoting of fieldname produces a syntax error

QgsDebugMsg( QString( "SQL: %1" ).arg( sql ) );
OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, TO8( sql ), NULL, "SQL" );
Expand All @@ -1894,7 +1906,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
OGRFeatureH f;
while ( 0 != ( f = OGR_L_GetNextFeature( l ) ) )
{
uniqueValues << convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) );
uniqueValues << ( OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) );
OGR_F_Destroy( f );

if ( limit >= 0 && uniqueValues.size() >= limit )
Expand Down Expand Up @@ -1936,7 +1948,7 @@ QVariant QgsOgrProvider::minimumValue( int index )
return QVariant();
}

QVariant value = convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) );
QVariant value = OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
OGR_F_Destroy( f );

OGR_DS_ReleaseResultSet( ogrDataSource, l );
Expand Down Expand Up @@ -1975,7 +1987,7 @@ QVariant QgsOgrProvider::maximumValue( int index )
return QVariant();
}

QVariant value = convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) );
QVariant value = OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
OGR_F_Destroy( f );

OGR_DS_ReleaseResultSet( ogrDataSource, l );
Expand Down

0 comments on commit 397e3b4

Please sign in to comment.