@@ -460,7 +460,19 @@ QStringList QgsOgrProvider::subLayers() const
460
460
461
461
void QgsOgrProvider::setEncoding ( const QString& e )
462
462
{
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
463
473
QgsVectorDataProvider::setEncoding ( e );
474
+ #endif
475
+
464
476
loadFields ();
465
477
}
466
478
@@ -523,17 +535,17 @@ void QgsOgrProvider::loadFields()
523
535
mAttributeFields .insert (
524
536
i, QgsField (
525
537
// 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
531
543
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
537
549
OGR_Fld_GetWidth ( fldDef ),
538
550
OGR_Fld_GetPrecision ( fldDef ) ) );
539
551
}
@@ -2117,7 +2129,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
2117
2129
sql += QString ( " WHERE %1" ).arg ( mSubsetString );
2118
2130
}
2119
2131
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
2121
2133
2122
2134
QgsDebugMsg ( QString ( " SQL: %1" ).arg ( sql ) );
2123
2135
OGRLayerH l = OGR_DS_ExecuteSQL ( ogrDataSource, TO8 ( sql ), NULL , " SQL" );
@@ -2127,7 +2139,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
2127
2139
OGRFeatureH f;
2128
2140
while ( 0 != ( f = OGR_L_GetNextFeature ( l ) ) )
2129
2141
{
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 ( ) ) );
2131
2143
OGR_F_Destroy ( f );
2132
2144
2133
2145
if ( limit >= 0 && uniqueValues.size () >= limit )
@@ -2169,7 +2181,7 @@ QVariant QgsOgrProvider::minimumValue( int index )
2169
2181
return QVariant ();
2170
2182
}
2171
2183
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 ( ) );
2173
2185
OGR_F_Destroy ( f );
2174
2186
2175
2187
OGR_DS_ReleaseResultSet ( ogrDataSource, l );
@@ -2208,7 +2220,7 @@ QVariant QgsOgrProvider::maximumValue( int index )
2208
2220
return QVariant ();
2209
2221
}
2210
2222
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 ( ) );
2212
2224
OGR_F_Destroy ( f );
2213
2225
2214
2226
OGR_DS_ReleaseResultSet ( ogrDataSource, l );
0 commit comments