Skip to content

Commit 2d0edcd

Browse files
committedDec 27, 2011
ogr provider:
- support for OLCStringsAsUTF8 (fixes #4558) - remove quotation on "ORDER BY" (produces a syntax error otherwise) - support for null values in uniqueValues/minimumValue/maximumValue
1 parent 79f8283 commit 2d0edcd

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed
 

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,19 @@ QStringList QgsOgrProvider::subLayers() const
460460

461461
void QgsOgrProvider::setEncoding( const QString& e )
462462
{
463+
#if defined(OLCStringsAsUTF8)
464+
if ( !OGR_L_TestCapability( ogrLayer, OLCStringsAsUTF8 ) )
465+
{
466+
QgsVectorDataProvider::setEncoding( e );
467+
}
468+
else
469+
{
470+
QgsVectorDataProvider::setEncoding( "UTF-8" );
471+
}
472+
#else
463473
QgsVectorDataProvider::setEncoding( e );
474+
#endif
475+
464476
loadFields();
465477
}
466478

@@ -523,17 +535,17 @@ void QgsOgrProvider::loadFields()
523535
mAttributeFields.insert(
524536
i, QgsField(
525537
//TODO: fix this hack
526-
#ifdef ANDROID
527-
OGR_Fld_GetNameRef( fldDef ),
528-
#else
529-
mEncoding->toUnicode( OGR_Fld_GetNameRef( fldDef ) ),
530-
#endif
538+
#ifdef ANDROID
539+
OGR_Fld_GetNameRef( fldDef ),
540+
#else
541+
mEncoding->toUnicode( OGR_Fld_GetNameRef( fldDef ) ),
542+
#endif
531543
varType,
532-
#ifdef ANDROID
533-
OGR_GetFieldTypeName( ogrType ),
534-
#else
535-
mEncoding->toUnicode( OGR_GetFieldTypeName( ogrType ) ),
536-
#endif
544+
#ifdef ANDROID
545+
OGR_GetFieldTypeName( ogrType ),
546+
#else
547+
mEncoding->toUnicode( OGR_GetFieldTypeName( ogrType ) ),
548+
#endif
537549
OGR_Fld_GetWidth( fldDef ),
538550
OGR_Fld_GetPrecision( fldDef ) ) );
539551
}
@@ -2117,7 +2129,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
21172129
sql += QString( " WHERE %1" ).arg( mSubsetString );
21182130
}
21192131

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

21222134
QgsDebugMsg( QString( "SQL: %1" ).arg( sql ) );
21232135
OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, TO8( sql ), NULL, "SQL" );
@@ -2127,7 +2139,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
21272139
OGRFeatureH f;
21282140
while ( 0 != ( f = OGR_L_GetNextFeature( l ) ) )
21292141
{
2130-
uniqueValues << convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) );
2142+
uniqueValues << ( OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) );
21312143
OGR_F_Destroy( f );
21322144

21332145
if ( limit >= 0 && uniqueValues.size() >= limit )
@@ -2169,7 +2181,7 @@ QVariant QgsOgrProvider::minimumValue( int index )
21692181
return QVariant();
21702182
}
21712183

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

21752187
OGR_DS_ReleaseResultSet( ogrDataSource, l );
@@ -2208,7 +2220,7 @@ QVariant QgsOgrProvider::maximumValue( int index )
22082220
return QVariant();
22092221
}
22102222

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

22142226
OGR_DS_ReleaseResultSet( ogrDataSource, l );

0 commit comments

Comments
 (0)