Skip to content
Permalink
Browse files

[OGR] Use a ORIG_OGC_FID constant instead of hard-coding orig_ogc_fid

  • Loading branch information
manisandro committed Sep 25, 2017
1 parent 15eaafd commit 6b7201f4edb8ba34962d6f88fb7114fe15620c25
Showing with 6 additions and 4 deletions.
  1. +6 −4 src/providers/ogr/qgsogrprovider.cpp
@@ -88,6 +88,8 @@ static const QString TEXT_PROVIDER_DESCRIPTION =
static OGRwkbGeometryType ogrWkbGeometryTypeFromName( const QString &typeName );
static const QByteArray ORIG_OGC_FID = "orig_ogc_fid";
bool QgsOgrProvider::convertField( QgsField &field, const QTextCodec &encoding )
{
@@ -1023,7 +1025,7 @@ void QgsOgrProviderUtils::setRelevantFields( OGRLayerH ogrLayer, int fieldCount,
{
// add to ignored fields
const char *fieldName = OGR_Fld_GetNameRef( OGR_FD_GetFieldDefn( featDefn, firstAttrIsFid ? i - 1 : i ) );
if ( qstrcmp( fieldName, "orig_ogc_fid" ) != 0 )
if ( qstrcmp( fieldName, ORIG_OGC_FID ) != 0 )
{
ignoredFields.append( fieldName );
}
@@ -3564,15 +3566,15 @@ OGRLayerH QgsOgrProviderUtils::setSubsetString( OGRLayerH layer, GDALDatasetH ds
fidColumn = "FID";
}

QByteArray sql = sqlPart1 + ", " + fidColumn + " as orig_ogc_fid" + sqlPart3;
QByteArray sql = sqlPart1 + ", " + fidColumn + " as " + ORIG_OGC_FID + sqlPart3;
QgsDebugMsg( QString( "SQL: %1" ).arg( encoding->toUnicode( sql ) ) );
subsetLayer = GDALDatasetExecuteSQL( ds, sql.constData(), nullptr, nullptr );

// See https://lists.osgeo.org/pipermail/qgis-developer/2017-September/049802.html
// If execute SQL fails because it did not find the fidColumn, retry with hardcoded FID
if ( !subsetLayer )
{
QByteArray sql = sqlPart1 + ", " + "FID as orig_ogc_fid" + sqlPart3;
QByteArray sql = sqlPart1 + ", " + "FID as " + ORIG_OGC_FID + sqlPart3;
QgsDebugMsg( QString( "SQL: %1" ).arg( encoding->toUnicode( sql ) ) );
subsetLayer = GDALDatasetExecuteSQL( ds, sql.constData(), nullptr, nullptr );
}
@@ -3594,7 +3596,7 @@ OGRLayerH QgsOgrProviderUtils::setSubsetString( OGRLayerH layer, GDALDatasetH ds
if ( fieldCount > 0 )
{
OGRFieldDefnH fldDef = OGR_FD_GetFieldDefn( fdef, fieldCount - 1 );
origFidAdded = qstrcmp( OGR_Fld_GetNameRef( fldDef ), "orig_ogc_fid" ) == 0;
origFidAdded = qstrcmp( OGR_Fld_GetNameRef( fldDef ), ORIG_OGC_FID ) == 0;
}
}

0 comments on commit 6b7201f

Please sign in to comment.
You can’t perform that action at this time.